X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=blobdiff_plain;f=Usermode%2FLibraries%2Flibnet.so_src%2FTEST_dns_proto.c;fp=Usermode%2FLibraries%2Flibnet.so_src%2FTEST_dns_proto.c;h=49ba023215f5852be14df74037ee3b1d49a17265;hp=0000000000000000000000000000000000000000;hb=db55040ba8814edf681d4ccc12ad8955d8aa404a;hpb=bdab8e5cebaf249d291d19523d0358f8c1c98008 diff --git a/Usermode/Libraries/libnet.so_src/TEST_dns_proto.c b/Usermode/Libraries/libnet.so_src/TEST_dns_proto.c new file mode 100644 index 00000000..49ba0232 --- /dev/null +++ b/Usermode/Libraries/libnet.so_src/TEST_dns_proto.c @@ -0,0 +1,80 @@ +/* + */ +#include +#include "include/dns_int.h" +#include +#include +#include + +// Complex response from "Q ssh.ucc.asn.au A IN" +const uint8_t test_packet_1[] = { + 0xac, 0x00, 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x03, 0x73, 0x73, 0x68, 0x03, 0x75, 0x63, 0x63, 0x03, 0x61, 0x73, 0x6e, 0x02, 0x61, 0x75, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x77, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x78, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x79, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x61, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x7a, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x62, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x75, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x76, 0xc0, 0x18, 0xc0, 0x2c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc0, 0x05, 0xc0, 0x3c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc2, 0x05, 0xc0, 0x4c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc4, 0x05, 0xc0, 0x5c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x3a, 0x41, 0xfe, 0x49, 0xc0, 0x6c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc6, 0x05, 0xc0, 0x7c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x3a, 0x41, 0xfd, 0x49, 0xc0, 0x8c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0xd3, 0x1d, 0x85, 0x20, 0xc0, 0x9c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0xca, 0x0c, 0x1f, 0x8d, + }; +const uint8_t test_packet_2[] ={ + 0xac,0x00,0x81,0x80,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x03,0x73,0x73,0x68,0x03,0x75,0x63,0x63,0x03,0x61,0x73,0x6e,0x02,0x61,0x75,0x00,0x00,0x01,0x00,0x01,0xc0,0x0c,0x00,0x01,0x00,0x01,0x00,0x00,0x0e,0x10,0x00,0x04,0x82,0x5f,0x0d,0x0b +}; + +int test_response_parse_1_cb(void *info, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata) +{ + int* stagep = info; + int curstage = *stagep; + *stagep = -1; + switch( curstage ) + { + case 0: + TEST_REL_INT(0, ==, strcmp(name, "w.au.")); + break; + case 1: + TEST_REL_INT(0, ==, strcmp(name, "x.au.")); + break; + } + *stagep = curstage + 1; + return 0; +} +int test_response_parse_1(void) +{ + int stage = 0; + TEST_REL_INT(0, ==, DNS_int_ParseResponse(test_packet_1, sizeof(test_packet_1), &stage, test_response_parse_1_cb) ); + TEST_REL_INT(stage, ==, 8); + return 0; +} + +int test_response_parse_2_cb(void *info, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata) +{ + int* stagep = info; + int curstage = *stagep; + *stagep = -1; + switch( curstage ) + { + case 0: + TEST_REL_INT(0, ==, strcmp(name, "ssh.ucc.asn.au.")); + TEST_REL_INT(TYPE_A, ==, type); + TEST_REL_INT(CLASS_IN, ==, class); + TEST_REL_INT(4, ==, rdlength); + TEST_REL_INT(130, ==, ((uint8_t*)rdata)[0]); + TEST_REL_INT( 95, ==, ((uint8_t*)rdata)[1]); + TEST_REL_INT( 13, ==, ((uint8_t*)rdata)[2]); + TEST_REL_INT( 11, ==, ((uint8_t*)rdata)[3]); + break; + } + *stagep = curstage + 1; + return 0; +} +int test_response_parse_2(void) +{ + int stage = 0; + TEST_REL_INT(0, ==, DNS_int_ParseResponse(test_packet_2, sizeof(test_packet_2), &stage, test_response_parse_2_cb) ); + TEST_REL_INT(stage, ==, 1); + return 0; +} + +int main(void) +{ + int rv = 0; + // - Name Encode + // - Name Decode + // - Response parsing + rv |= test_response_parse_1(); + rv |= test_response_parse_2(); + return rv; +}