dumb endianess bug

This commit is contained in:
Murphy 2023-04-12 19:22:46 -04:00
parent 1aeff9e8a4
commit 9d77fe0022
3 changed files with 3 additions and 7 deletions

View file

@ -17,7 +17,6 @@ void read_packet(PacketBuffer* buffer, Packet* packet) {
for(uint16_t i = 0; i < packet->header.questions; i++) { for(uint16_t i = 0; i < packet->header.questions; i++) {
if (!read_question(buffer, &packet->questions[i])) { if (!read_question(buffer, &packet->questions[i])) {
i--; i--;
WARN("J");
packet->header.questions--; packet->header.questions--;
} }
} }
@ -26,7 +25,6 @@ void read_packet(PacketBuffer* buffer, Packet* packet) {
for(uint16_t i = 0; i < packet->header.answers; i++) { for(uint16_t i = 0; i < packet->header.answers; i++) {
if (!read_record(buffer, &packet->answers[i])) { if (!read_record(buffer, &packet->answers[i])) {
i--; i--;
WARN("A");
packet->header.answers--; packet->header.answers--;
} }
} }
@ -35,7 +33,6 @@ void read_packet(PacketBuffer* buffer, Packet* packet) {
for(uint16_t i = 0; i < packet->header.authoritative_entries; i++) { for(uint16_t i = 0; i < packet->header.authoritative_entries; i++) {
if (!read_record(buffer, &packet->authorities[i])) { if (!read_record(buffer, &packet->authorities[i])) {
i--; i--;
WARN("B");
packet->header.authoritative_entries--; packet->header.authoritative_entries--;
} }
} }
@ -44,7 +41,6 @@ void read_packet(PacketBuffer* buffer, Packet* packet) {
for(uint16_t i = 0; i < packet->header.resource_entries; i++) { for(uint16_t i = 0; i < packet->header.resource_entries; i++) {
if (!read_record(buffer, &packet->resources[i])) { if (!read_record(buffer, &packet->resources[i])) {
i--; i--;
WARN("C");
packet->header.resource_entries--; packet->header.resource_entries--;
} }
} }

View file

@ -158,10 +158,10 @@ static bool write_udp(Connection* connection, uint8_t* buf, uint16_t len) {
} }
static bool write_tcp(Connection* connection, uint8_t* buf, uint16_t len) { static bool write_tcp(Connection* connection, uint8_t* buf, uint16_t len) {
len = htons(len); uint16_t net_len = htons(len);
if (write_tcp_stream( if (write_tcp_stream(
&connection->sock.tcp, &connection->sock.tcp,
&len, &net_len,
sizeof(uint16_t) sizeof(uint16_t)
) < 0) { ) < 0) {
return false; return false;

View file

@ -47,7 +47,7 @@ static void* server_respond(void* arg) {
handle_query(&req.request, &response, req.connection.type, &map); handle_query(&req.request, &response, req.connection.type, &map);
if (!write_connection(&req.connection, &response)) { if (!write_connection(&req.connection, &response)) {
ERROR("Faled to respond to connection ID %hu: %s", ERROR("Failed to respond to connection ID %hu: %s",
req.request.header.id, req.request.header.id,
strerror(errno) strerror(errno)
); );