make packets big endian
This commit is contained in:
parent
238eff5bb3
commit
6055103cdc
1 changed files with 6 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sqlite3.h>
|
||||
#include <arpa/inet.h>
|
||||
#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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue