This commit is contained in:
Murphy 2023-04-12 14:24:39 -04:00
parent 9c19aa4d33
commit 1aeff9e8a4

View file

@ -8,6 +8,7 @@
#include "header.h"
#include "question.h"
#include "record.h"
#include "../io/log.h"
void read_packet(PacketBuffer* buffer, Packet* packet) {
read_header(buffer, &packet->header);
@ -16,6 +17,7 @@ void read_packet(PacketBuffer* buffer, Packet* packet) {
for(uint16_t i = 0; i < packet->header.questions; i++) {
if (!read_question(buffer, &packet->questions[i])) {
i--;
WARN("J");
packet->header.questions--;
}
}
@ -24,24 +26,25 @@ void read_packet(PacketBuffer* buffer, Packet* packet) {
for(uint16_t i = 0; i < packet->header.answers; i++) {
if (!read_record(buffer, &packet->answers[i])) {
i--;
WARN("A");
packet->header.answers--;
}
}
packet->authorities = malloc(sizeof(Record) * packet->header.authoritative_entries);
for(uint16_t i = 0; i < packet->header.authoritative_entries; i++) {
read_record(buffer, &packet->authorities[i]);
if (!read_record(buffer, &packet->authorities[i])) {
i--;
WARN("B");
packet->header.authoritative_entries--;
}
}
packet->resources = malloc(sizeof(Record) * packet->header.resource_entries);
for(uint16_t i = 0; i < packet->header.resource_entries; i++) {
read_record(buffer, &packet->resources[i]);
if (!read_record(buffer, &packet->resources[i])) {
i--;
WARN("C");
packet->header.resource_entries--;
}
}