diff --git a/network.c b/network.c index 153023b..48f383c 100644 --- a/network.c +++ b/network.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "network.h" #include "client.h" #include "password.h" @@ -95,7 +96,7 @@ static void send_packet(struct client *client, uint8_t type, const void *data, s if (!buf) return; struct packet_header *hdr = (struct packet_header *)buf; - hdr->size = (uint16_t)total_len; + hdr->size = htons((uint16_t)total_len); hdr->type = type; if (data && data_len > 0) { @@ -633,7 +634,9 @@ void network_handle_data(struct client *client, const char *data, size_t len) return; } - const struct packet_header *hdr = (const struct packet_header *)data; + + struct packet_header *hdr = (struct packet_header *)data; + hdr->size = ntohs(hdr->size); if (hdr->size > len || hdr->size < sizeof(struct packet_header)) { send_error(client, ERR_INVALID_PACKET); @@ -643,6 +646,7 @@ void network_handle_data(struct client *client, const char *data, size_t len) const char *payload = data + sizeof(struct packet_header); size_t payload_len = hdr->size - sizeof(struct packet_header); + switch (hdr->type) { case PACKET_REGISTER: handle_register(client, payload, payload_len);