From e01cfa577b8b8ff7b7a2afcc388005d1af79e833 Mon Sep 17 00:00:00 2001 From: Michael Sawyer Date: Sat, 29 Apr 2000 01:39:32 +0000 Subject: [PATCH] Add +twiddle option for testing. Fix up host resolution from resolv.conf. --- bin/dig/dig.c | 9 ++++++ bin/dig/dighost.c | 70 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 876a366bc7..126ea8a971 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -15,6 +15,8 @@ * SOFTWARE. */ +#define TWIDDLE + #include #include @@ -71,6 +73,9 @@ extern dns_name_t rootorg; extern char *rootspace[BUFSIZE]; extern isc_buffer_t rootbuf; extern int sendcount; +#ifdef TWIDDLE +extern isc_boolean_t twiddle; +#endif isc_boolean_t short_form=ISC_FALSE; @@ -394,6 +399,10 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { recurse = ISC_TRUE; } else if (strncmp(argv[0],"+norec",6) == 0) { recurse = ISC_FALSE; +#ifdef TWIDDLE + } else if (strncmp(argv[0],"+twiddle",6) == 0) { + twiddle = ISC_TRUE; +#endif } else if (strncmp(argv[0],"-f",2) == 0) { if (argv[0][2]!=0) { batchname=&argv[0][2]; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 92c660b8a6..cfea541aa8 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -#define DEBUG +#define TWIDDLE (random()%4+1) #include @@ -62,6 +62,9 @@ ISC_LIST(dig_server_t) server_list; isc_boolean_t tcp_mode = ISC_FALSE, recurse = ISC_TRUE, have_ipv6 = ISC_FALSE, free_now = ISC_FALSE; +#ifdef TWIDDLE +isc_boolean_t twiddle = ISC_FALSE; +#endif in_port_t port; unsigned int timeout; isc_mem_t *mctx = NULL; @@ -181,6 +184,32 @@ istype(char *text) { } +#ifdef TWIDDLE +void +twiddlebuf(isc_buffer_t buf) { + isc_region_t r; + int len, pos, bit; + unsigned char bitfield; + int i, tw; + + hex_dump(&buf); + tw=TWIDDLE; + printf ("Twiddling %d bits: ",tw); + for (i=0;ipending) @@ -678,9 +707,15 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) { isc_buffer_clear(&query->lengthbuf); isc_buffer_putuint16(&query->slbuf, query->lookup->sendbuf.used); ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link); - if (include_question) + if (include_question) { +#ifdef TWIDDLE + if (twiddle) { + twiddlebuf(query->lookup->sendbuf); + } +#endif ISC_LIST_ENQUEUE(query->sendlist, &query->lookup->sendbuf, link); + } ISC_LIST_ENQUEUE(query->lengthlist, &query->lengthbuf, link); result = isc_socket_recvv(query->sock, &query->lengthlist, 0, task, @@ -894,15 +929,17 @@ get_address(char *hostname, in_port_t port, isc_sockaddr_t *sockaddr) { struct in_addr in4; struct in6_addr in6; struct hostent *he; + char host[MXNAME]; debug("get_address()"); - if (have_ipv6 && inet_pton(AF_INET6, hostname, &in6) == 1) + sscanf (hostname, "%s", host); /* Force CR, etc... out */ + if (have_ipv6 && inet_pton(AF_INET6, host, &in6) == 1) isc_sockaddr_fromin6(sockaddr, &in6, port); - else if (inet_pton(AF_INET, hostname, &in4) == 1) + else if (inet_pton(AF_INET, host, &in4) == 1) isc_sockaddr_fromin(sockaddr, &in4, port); else { - he = gethostbyname(hostname); + he = gethostbyname(host); if (he == NULL) fatal("Couldn't look up your server host %s. errno=%d", hostname, h_errno); @@ -977,6 +1014,11 @@ do_lookup_udp(dig_lookup_t *lookup) { check_result(result, "isc_socket_recvv"); sendcount++; debug("Sent count number %d", sendcount); +#ifdef TWIDDLE + if (twiddle) { + twiddlebuf(lookup->sendbuf); + } +#endif ISC_LIST_ENQUEUE(query->sendlist, &lookup->sendbuf, link); debug("Sending a request."); result = isc_socket_sendtov(query->sock, &query->sendlist, @@ -1055,10 +1097,26 @@ free_lists(void) { int main(int argc, char **argv) { dig_lookup_t *lookup = NULL; +#ifdef TWIDDLE + FILE *fp; + int i,p; +#endif ISC_LIST_INIT(lookup_list); ISC_LIST_INIT(server_list); +#ifdef TWIDDLE + fp = fopen("/dev/urandom","r"); + if (fp!=NULL) { + fread (&i, sizeof(int), 1, fp); + srandom(i); + } + else { + srandom ((int)&main); + } + p = getpid()%16+8; + for (i=0 ; i