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!).
This commit is contained in:
Marc André Tanner 2017-06-21 22:37:43 +02:00
parent 6375556846
commit 8964601fe1
4 changed files with 15 additions and 8 deletions

View File

@ -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;

View File

@ -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))

View File

@ -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");

View File

@ -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;