forked from github/abduco
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:
parent
6375556846
commit
8964601fe1
12
abduco.c
12
abduco.c
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -71,12 +72,15 @@ enum PacketType {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int type;
|
uint32_t type;
|
||||||
size_t len;
|
uint32_t len;
|
||||||
union {
|
union {
|
||||||
char msg[BUFSIZ];
|
char msg[BUFSIZ];
|
||||||
struct winsize ws;
|
struct {
|
||||||
int i;
|
uint16_t rows;
|
||||||
|
uint16_t cols;
|
||||||
|
} ws;
|
||||||
|
uint32_t i;
|
||||||
} u;
|
} u;
|
||||||
} Packet;
|
} Packet;
|
||||||
|
|
||||||
|
|
|
||||||
2
client.c
2
client.c
|
|
@ -78,7 +78,7 @@ static int client_mainloop(void) {
|
||||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) {
|
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) {
|
||||||
Packet pkt = {
|
Packet pkt = {
|
||||||
.type = MSG_RESIZE,
|
.type = MSG_RESIZE,
|
||||||
.u = { .ws = ws },
|
.u = { .ws = { .rows = ws.ws_row, .cols = ws.ws_col } },
|
||||||
.len = sizeof(ws),
|
.len = sizeof(ws),
|
||||||
};
|
};
|
||||||
if (client_send_packet(&pkt))
|
if (client_send_packet(&pkt))
|
||||||
|
|
|
||||||
4
debug.c
4
debug.c
|
|
@ -29,7 +29,7 @@ static void print_packet(const char *prefix, Packet *pkt) {
|
||||||
fwrite(pkt->u.msg, pkt->len, 1, stderr);
|
fwrite(pkt->u.msg, pkt->len, 1, stderr);
|
||||||
break;
|
break;
|
||||||
case MSG_RESIZE:
|
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;
|
break;
|
||||||
case MSG_ATTACH:
|
case MSG_ATTACH:
|
||||||
fprintf(stderr, "readonly: %d low-priority: %d",
|
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);
|
pkt->u.i & CLIENT_LOWPRIORITY);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "len: %zu", pkt->len);
|
fprintf(stderr, "len: %"PRIu32, pkt->len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
|
||||||
5
server.c
5
server.c
|
|
@ -224,7 +224,10 @@ static void server_mainloop(void) {
|
||||||
case MSG_REDRAW:
|
case MSG_REDRAW:
|
||||||
if (!(c->flags & CLIENT_READONLY) && (client_packet.type == MSG_REDRAW || c == server.clients)) {
|
if (!(c->flags & CLIENT_READONLY) && (client_packet.type == MSG_REDRAW || c == server.clients)) {
|
||||||
debug("server-ioct: TIOCSWINSZ\n");
|
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);
|
kill(-server.pid, SIGWINCH);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue