From: Wouter Wijngaards Date: Tue, 24 Jun 2008 14:18:06 +0000 (+0000) Subject: ipv6 test working for windows. X-Git-Tag: release-1.0.1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a64adc395f29c636fecff6eb67a39b6e41e7ab37;p=thirdparty%2Funbound.git ipv6 test working for windows. git-svn-id: file:///svn/unbound/trunk@1130 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index b030e1e92..f9f938807 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,8 @@ 24 June 2008: Wouter - removed testcode/checklocks from production code compilation path. + - streamtcp can use UDP mode (connected UDP socket), for testing IPv6 + on windows. + - fwd_ancil test fails if platform support is lacking. 23 June 2008: Wouter - fixup minitpkg to cleanup on windows with its file locking troubles. diff --git a/testcode/do-tests.sh b/testcode/do-tests.sh index 4c13c9fb8..a52e0c7ce 100755 --- a/testcode/do-tests.sh +++ b/testcode/do-tests.sh @@ -23,6 +23,7 @@ if dig @::1 -v >/dev/null 2>&1; then else HAVE_IPV6=no fi +HAVE_IPV6=yes cd testdata; sh ../testcode/mini_tpkg.sh clean diff --git a/testcode/streamtcp.c b/testcode/streamtcp.c index f646cb519..0b93835e8 100644 --- a/testcode/streamtcp.c +++ b/testcode/streamtcp.c @@ -54,13 +54,15 @@ void usage(char* argv[]) printf("usage: %s [options] name type class ...\n", argv[0]); printf(" sends the name-type-class queries over TCP.\n"); printf("-f server what ipaddr@portnr to send the queries to\n"); + printf("-u use UDP. No retries are attempted.\n"); + printf("-n do not wait for an answer.\n"); printf("-h this help text\n"); exit(1); } /** open TCP socket to svr */ static int -open_svr(char* svr) +open_svr(char* svr, int udp) { struct sockaddr_storage addr; socklen_t addrlen; @@ -71,7 +73,7 @@ open_svr(char* svr) exit(1); } fd = socket(addr_is_ip6(&addr, addrlen)?PF_INET6:PF_INET, - SOCK_STREAM, 0); + udp?SOCK_DGRAM:SOCK_STREAM, 0); if(fd == -1) { #ifndef USE_WINSOCK perror("socket() error"); @@ -93,7 +95,7 @@ open_svr(char* svr) /** write a query over the TCP fd */ static void -write_q(int fd, ldns_buffer* buf, int id, +write_q(int fd, int udp, ldns_buffer* buf, int id, char* strname, char* strtype, char* strclass) { struct query_info qinfo; @@ -121,15 +123,18 @@ write_q(int fd, ldns_buffer* buf, int id, ldns_buffer_write_u16_at(buf, 2, BIT_RD); /* send it */ - len = (uint16_t)ldns_buffer_limit(buf); - len = htons(len); - if(send(fd, (void*)&len, sizeof(len), 0) < (ssize_t)sizeof(len)) { + if(!udp) { + len = (uint16_t)ldns_buffer_limit(buf); + len = htons(len); + if(send(fd, (void*)&len, sizeof(len), 0)<(ssize_t)sizeof(len)){ #ifndef USE_WINSOCK - perror("send() len failed"); + perror("send() len failed"); #else - printf("send len: %s\n", wsa_strerror(WSAGetLastError())); + printf("send len: %s\n", + wsa_strerror(WSAGetLastError())); #endif - exit(1); + exit(1); + } } if(send(fd, ldns_buffer_begin(buf), ldns_buffer_limit(buf), 0) < (ssize_t)ldns_buffer_limit(buf)) { @@ -146,29 +151,47 @@ write_q(int fd, ldns_buffer* buf, int id, /** receive DNS datagram over TCP and print it */ static void -recv_one(int fd, ldns_buffer* buf) +recv_one(int fd, int udp, ldns_buffer* buf) { uint16_t len; ldns_pkt* pkt; ldns_status status; - if(recv(fd, (void*)&len, sizeof(len), 0) < (ssize_t)sizeof(len)) { + if(!udp) { + if(recv(fd, (void*)&len, sizeof(len), 0)<(ssize_t)sizeof(len)){ #ifndef USE_WINSOCK - perror("read() len failed"); + perror("read() len failed"); #else - printf("read len: %s\n", wsa_strerror(WSAGetLastError())); + printf("read len: %s\n", + wsa_strerror(WSAGetLastError())); #endif - exit(1); - } - len = ntohs(len); - ldns_buffer_clear(buf); - ldns_buffer_set_limit(buf, len); - if(recv(fd, ldns_buffer_begin(buf), len, 0) < (ssize_t)len) { + exit(1); + } + len = ntohs(len); + ldns_buffer_clear(buf); + ldns_buffer_set_limit(buf, len); + if(recv(fd, ldns_buffer_begin(buf), len, 0) < (ssize_t)len) { #ifndef USE_WINSOCK - perror("read() data failed"); + perror("read() data failed"); #else - printf("read data: %s\n", wsa_strerror(WSAGetLastError())); + printf("read data: %s\n", + wsa_strerror(WSAGetLastError())); #endif - exit(1); + exit(1); + } + } else { + ssize_t l; + ldns_buffer_clear(buf); + if((l=recv(fd, ldns_buffer_begin(buf), + ldns_buffer_capacity(buf), 0)) < 0) { +#ifndef USE_WINSOCK + perror("read() data failed"); +#else + printf("read data: %s\n", + wsa_strerror(WSAGetLastError())); +#endif + exit(1); + } + ldns_buffer_set_limit(buf, l); } printf("\nnext received packet\n"); log_buf(0, "data", buf); @@ -186,17 +209,18 @@ recv_one(int fd, ldns_buffer* buf) /** send the TCP queries and print answers */ static void -send_em(char* svr, int num, char** qs) +send_em(char* svr, int udp, int noanswer, int num, char** qs) { ldns_buffer* buf = ldns_buffer_new(65553); - int fd = open_svr(svr); + int fd = open_svr(svr, udp); int i; if(!buf) fatal_exit("out of memory"); for(i=0; i