abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 8964601fe13db90eecc0e4e9a866ae9f20c4edec
parent 637555684620efeb8579c367b7379346f0a46d23
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 21 Jun 2017 22:37:43 +0200

Use fixed size integer types in protocol messages

This should make it possible to connect with a 32bit client to a 64bit
server. This might also make it possible to forward the abduco socket
over SSH as described in #25. Different endianness are not supported at
this time.

This is a breaking protocol change. Make sure to use the same version
as client and server (anything else is unsupported anyway!).

Diffstat:
abduco.c | 12++++++++----
client.c | 2+-
debug.c | 4++--
server.c | 5++++-
4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/abduco.c b/abduco.c @@ -15,6 +15,7 @@ */ #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -71,12 +72,15 @@ enum PacketType { }; typedef struct { - unsigned int type; - size_t len; + uint32_t type; + uint32_t len; union { char msg[BUFSIZ]; - struct winsize ws; - int i; + struct { + uint16_t rows; + uint16_t cols; + } ws; + uint32_t i; } u; } Packet; diff --git a/client.c b/client.c @@ -78,7 +78,7 @@ static int client_mainloop(void) { if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) { Packet pkt = { .type = MSG_RESIZE, - .u = { .ws = ws }, + .u = { .ws = { .rows = ws.ws_row, .cols = ws.ws_col } }, .len = sizeof(ws), }; if (client_send_packet(&pkt)) diff --git a/debug.c b/debug.c @@ -29,7 +29,7 @@ static void print_packet(const char *prefix, Packet *pkt) { fwrite(pkt->u.msg, pkt->len, 1, stderr); break; case MSG_RESIZE: - fprintf(stderr, "%dx%d", pkt->u.ws.ws_col, pkt->u.ws.ws_row); + fprintf(stderr, "%"PRIu16"x%"PRIu16, pkt->u.ws.cols, pkt->u.ws.rows); break; case MSG_ATTACH: fprintf(stderr, "readonly: %d low-priority: %d", @@ -37,7 +37,7 @@ static void print_packet(const char *prefix, Packet *pkt) { pkt->u.i & CLIENT_LOWPRIORITY); break; default: - fprintf(stderr, "len: %zu", pkt->len); + fprintf(stderr, "len: %"PRIu32, pkt->len); break; } fprintf(stderr, "\n"); diff --git a/server.c b/server.c @@ -224,7 +224,10 @@ static void server_mainloop(void) { case MSG_REDRAW: if (!(c->flags & CLIENT_READONLY) && (client_packet.type == MSG_REDRAW || c == server.clients)) { debug("server-ioct: TIOCSWINSZ\n"); - ioctl(server.pty, TIOCSWINSZ, &client_packet.u.ws); + struct winsize ws = { 0 }; + ws.ws_row = client_packet.u.ws.rows; + ws.ws_col = client_packet.u.ws.cols; + ioctl(server.pty, TIOCSWINSZ, &ws); } kill(-server.pid, SIGWINCH); break;