diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2019-11-30 16:05:41 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2019-11-30 16:05:41 +0100 |
commit | d2c641eb5b516783adfe2a236bc18412cd89af71 (patch) | |
tree | 17b9ebf08a749991bab83abd4771d05188b33049 /src/dns.c | |
parent | 3efdb35480dd6fa656d0728cab5c8dc76eaba24c (diff) | |
download | dns-d2c641eb5b516783adfe2a236bc18412cd89af71.tar.gz |
asdf
Diffstat (limited to 'src/dns.c')
-rw-r--r-- | src/dns.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -1,5 +1,36 @@ #include "dns.h" +int dns_parse_packet ( char* _buffer, int _bufflen, struct dns_message* _msg ) +{ + if ( !_buffer || !_bufflen || !_msg ) + return 1; //Invalid input + + if ( _bufflen < 12 ) + return 1; //Too short to contain a DNS header + + //TODO test + _msg->header.id = *( (uint16_t*) _buffer ); + _msg->header.QR = ( 0x80 & *( (uint8_t*) (_buffer + 2)) ) >> 7; + _msg->header.OPCODE = (0x78 & *( (uint8_t*) (_buffer + 2))) >> 3; + _msg->header.AA = (0x04 & *( (uint8_t*) (_buffer + 2))) >> 2; + _msg->header.TC = (0x02 & *( (uint8_t*) (_buffer + 2))) >> 1; + _msg->header.RD = (0x01 & *( (uint8_t*) (_buffer + 2))); + _msg->header.RA = (0x80 & *( (uint8_t*) (_buffer + 3))) >> 7; + _msg->header.Z = (0x70 & *( (uint8_t*) (_buffer + 3))) >> 4; + _msg->header.RCODE = (0x0F & *( (uint8_t*) (_buffer + 3))); + _msg->header.question_count = (*((uint8_t*) (_buffer + 4)) << 8) | *((uint8_t*) (_buffer + 5)); + _msg->header.answer_count = (*((uint8_t*) (_buffer + 6)) << 8) | *((uint8_t*) (_buffer + 7)); + _msg->header.authorative_count = (*((uint8_t*) (_buffer + 8)) << 8) | *((uint8_t*) (_buffer + 9)); + _msg->header.additional_count = (*((uint8_t*) (_buffer + 10)) << 8) | *((uint8_t*) (_buffer + 11)); + + printf("ANSWER %i\n", _msg->header.answer_count); + printf("QUESTI %i\n", _msg->header.question_count); + printf("AUTHOR %i\n", _msg->header.authorative_count); + printf("ADDITI %i\n", _msg->header.additional_count); + + return 1; +} + int fqdn_to_qname( char* _source, int _sourcelen, char* _sink ,int _sinklen ) { int i; |