mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 10:05:08 +00:00
Added test on dns_encode
This commit is contained in:
parent
e56074b42a
commit
d1ffedae43
@ -38,9 +38,6 @@
|
||||
#include "encoding.h"
|
||||
#include "read.h"
|
||||
|
||||
#define QR_QUERY 0
|
||||
#define QR_ANSWER 1
|
||||
|
||||
// For FreeBSD
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
|
@ -28,6 +28,7 @@ void dns_send_version(int, int);
|
||||
void dns_login(int, char *, int);
|
||||
int dns_read(int, char *, int);
|
||||
int dns_encode_hostname(const char *, char *, int);
|
||||
int dns_encode(char *, size_t, struct query *, int, char *, size_t);
|
||||
|
||||
extern struct sockaddr_in peer;
|
||||
|
||||
@ -41,5 +42,7 @@ void dnsd_queuepacket(const char *, const int);
|
||||
|
||||
int dns_parse_reply(char *, int, char *, int);
|
||||
|
||||
#define QR_QUERY 0
|
||||
#define QR_ANSWER 1
|
||||
|
||||
#endif /* _DNS_H_ */
|
||||
|
28
tests/dns.c
28
tests/dns.c
@ -83,6 +83,33 @@ START_TEST(test_encode_hostname_toolong)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
char queryPacket[] =
|
||||
"\x05\x39\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x05\x73\x69\x6C\x6C"
|
||||
"\x79\x04\x68\x6F\x73\x74\x02\x6F\x66\x06\x69\x6F\x64\x69\x6E\x65\x04"
|
||||
"\x63\x6F\x64\x65\x04\x6B\x72\x79\x6F\x02\x73\x65\x00\x00\x0A\x00\x01"
|
||||
"\x00\x00\x29\x10\x00\x00\x00\x80\x00\x00\x00";
|
||||
|
||||
START_TEST(test_encode_query)
|
||||
{
|
||||
char buf[512];
|
||||
char *host = "silly.host.of.iodine.code.kryo.se";
|
||||
struct query q;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = sizeof(buf);
|
||||
memset(&q, 0, sizeof(struct query));
|
||||
q.type = T_NULL;
|
||||
q.id = 1337;
|
||||
|
||||
ret = dns_encode(buf, len, &q, QR_QUERY, host, strlen(host));
|
||||
len = sizeof(queryPacket) - 1; // Skip extra null character
|
||||
|
||||
fail_unless(strncmp(queryPacket, buf, sizeof(queryPacket)) == 0, "Did not compile expected packet");
|
||||
fail_unless(ret == len, va_str("Bad packet length: %d, expected %d", ret, len));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TCase *
|
||||
test_dns_create_tests()
|
||||
{
|
||||
@ -92,6 +119,7 @@ test_dns_create_tests()
|
||||
tcase_add_test(tc, test_encode_hostname);
|
||||
tcase_add_test(tc, test_encode_hostname_nodot);
|
||||
tcase_add_test(tc, test_encode_hostname_toolong);
|
||||
tcase_add_test(tc, test_encode_query);
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user