From: fatbob313 Date: Mon, 4 Jan 2010 17:56:28 +0000 (+0000) Subject: Use defines for version info. uint32_t should be byte-shifted with htonl() X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=401bf05f273f514ae3bbf0f16d19dd8eb471255e Use defines for version info. uint32_t should be byte-shifted with htonl() --- diff --git a/src/client.c b/src/client.c index ceaacf6..2b89345 100644 --- a/src/client.c +++ b/src/client.c @@ -39,9 +39,7 @@ #include "messagehandler.h" #include "conf.h" #include "channel.h" - -/* Version 0.2.0 XXX fixme */ -const uint32_t versionBlob = 1<<16 | 2<<8 | 0; +#include "version.h" static int Client_read(client_t *client); static int Client_write(client_t *client); @@ -192,9 +190,10 @@ int Client_add(int fd, struct sockaddr_in *remote) /* Send version message to client */ sendmsg = Msg_create(Version); sendmsg->payload.version->has_version = true; - sendmsg->payload.version->version = (1 << 16) | (2 << 8) | 0; /* XXX fix */ - sendmsg->payload.version->release = strdup("1.2.0"); - sendmsg->payload.version->os = strdup("Linux/OpenWRT"); + sendmsg->payload.version->version = PROTOCOL_VERSION; + sendmsg->payload.version->release = strdup(UMURMUR_VERSION); + /* XXX - set OS to something relevant? */ + /* sendmsg->payload.version->os = strdup("Linux/OpenWRT"); */ Client_send_message(newclient, sendmsg); @@ -538,11 +537,11 @@ int Client_read_udp() /* Ping packet */ if (len == 12 && *encrypted == 0) { uint32_t *ping = (uint32_t *)encrypted; - ping[0] = htons(versionBlob); + ping[0] = htonl((uint32_t)PROTOCOL_VERSION); // 1 and 2 will be the timestamp, which we return unmodified. - ping[3] = htons((uint32_t)clientcount); - ping[4] = htons((uint32_t)getIntConf(MAX_CLIENTS)); - ping[5] = htons((uint32_t)getIntConf(MAX_BANDWIDTH)); + ping[3] = htonl((uint32_t)clientcount); + ping[4] = htonl((uint32_t)getIntConf(MAX_CLIENTS)); + ping[5] = htonl((uint32_t)getIntConf(MAX_BANDWIDTH)); sendto(udpsock, encrypted, 6 * sizeof(uint32_t), 0, (struct sockaddr *)&from, fromlen); return 0; diff --git a/src/messages.h b/src/messages.h index 55a7433..eedf7fd 100644 --- a/src/messages.h +++ b/src/messages.h @@ -39,7 +39,7 @@ #define PROTVER_MAJOR 1 #define PROTVER_MINOR 2 #define PROTVER_PATCH 0 -#define PROTOCOL_VERSION (((PROTVER_MAJOR << 16) | (PROTVER_MINOR << 8) | PROTVER_PATCH)) +#define PROTOCOL_VERSION ((PROTVER_MAJOR << 16) | (PROTVER_MINOR << 8) | (PROTVER_PATCH)) #define MAX_TEXT 512