From: Roger Wolff Date: Wed, 7 Apr 2004 00:00:00 +0000 (+0000) Subject: mtr v0.57 X-Git-Tag: v0.57^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e10f7d90b89296d26f1dd6dc29202a75d4ac1e8f;p=thirdparty%2Fmtr.git mtr v0.57 - Lots of whitespace cleanups. And a DNS fix: Don't do DNS lookups in raw mode with -n specified. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.57.tar.gz --- diff --git a/NEWS b/NEWS index de4a147..18c4b87 100644 --- a/NEWS +++ b/NEWS @@ -1,11 +1,14 @@ WHAT'S NEW? + v0.57 Lots of whitespace cleanups. And a DNS fix: Don't do DNS + lookups in raw mode with -n specified. + v0.56 Fixed compile warnings. Now compiles with -Wall. If your - compiler finds things mine didn't feel free to shout. + compiler finds things mine didn't feel free to shout. v0.55 Cleanup patch. I'm going to do some maintenance on MTR, but I want to be able to say: Can you see which version - fixed/broke things for you, so you're going to see a - bunch of new releases soon. + fixed/broke things for you, so you're going to see a + bunch of new releases soon. v0.54 Added "scrolling" patch from Roland Illig, to allow scrolling in text mode. I've always wanted this...... diff --git a/configure.in b/configure.in index 59cba09..9cd9963 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT(mtr.c) -AM_INIT_AUTOMAKE(mtr, 0.56) +AM_INIT_AUTOMAKE(mtr, 0.57) AC_SUBST(GTK_OBJ) diff --git a/curses.c b/curses.c index fb002e9..1634916 100644 --- a/curses.c +++ b/curses.c @@ -102,7 +102,8 @@ int fld_index[] = { }; -void pwcenter(char *str) { +void pwcenter(char *str) +{ int maxx, maxy; int cx; @@ -113,7 +114,8 @@ void pwcenter(char *str) { printw(str); } -int mtr_curses_keyaction() { +int mtr_curses_keyaction() +{ int c = getch(); int i=0; char buf[MAXFLD]; @@ -295,7 +297,8 @@ int mtr_curses_keyaction() { return ActionNone; /* ignore unknown input */ } -void mtr_curses_hosts(int startstat) { +void mtr_curses_hosts(int startstat) +{ int max; int at; int addr, addrs; @@ -389,7 +392,8 @@ static double factors[] = { 0.02, 0.05, 0.08, 0.15, 0.33, 0.50, 0.80, 1.00 }; static int scale[8]; static int low_ms, high_ms; -void mtr_gen_scale(void) { +void mtr_gen_scale(void) +{ int *saved, i, max, at; int range; @@ -420,7 +424,8 @@ void mtr_gen_scale(void) { static const char* block_map = ".123abc>"; -void mtr_print_scaled(int ms) { +void mtr_print_scaled(int ms) +{ int i; for (i = 0; i < 8; i++) { @@ -432,7 +437,8 @@ void mtr_print_scaled(int ms) { printw(">"); } -void mtr_fill_graph(int at, int cols) { +void mtr_fill_graph(int at, int cols) +{ int* saved; int i; @@ -458,7 +464,8 @@ void mtr_fill_graph(int at, int cols) { } } -void mtr_curses_graph(int startstat, int cols) { +void mtr_curses_graph(int startstat, int cols) +{ int max, at, addr, y, x; char* name; @@ -492,7 +499,8 @@ void mtr_curses_graph(int startstat, int cols) { } } -void mtr_curses_redraw() { +void mtr_curses_redraw() +{ int maxx, maxy; int startstat; int rowstat; @@ -513,7 +521,7 @@ void mtr_curses_redraw() { pwcenter("My traceroute [v" VERSION "]"); attroff(A_BOLD); - mvprintw(1,0, "%s", LocalHostname); + mvprintw(1, 0, "%s", LocalHostname); printw("(tos=0x%X ", tos); printw("psize=%d ", abs(packetsize) ); printw("bitpattern=0x%02X)", (unsigned char)(abs(bitpattern))); @@ -597,7 +605,8 @@ void mtr_curses_redraw() { refresh(); } -void mtr_curses_open() { +void mtr_curses_open() +{ initscr(); raw(); noecho(); @@ -605,12 +614,14 @@ void mtr_curses_open() { mtr_curses_redraw(); } -void mtr_curses_close() { +void mtr_curses_close() +{ printw("\n"); endwin(); } -void mtr_curses_clear() { +void mtr_curses_clear() +{ mtr_curses_close(); mtr_curses_open(); } diff --git a/dns.c b/dns.c index d9d5a1b..ac7a428 100644 --- a/dns.c +++ b/dns.c @@ -308,7 +308,8 @@ char nullstring[] = ""; #endif -void *statmalloc(size_t size){ +void *statmalloc(size_t size) +{ void *p; size_t mallocsize; mem+= size; @@ -333,14 +334,15 @@ void *statmalloc(size_t size){ return p; } -void statfree(void *p){ - if (p){ - if (*((dword *)p - HEAD_SLACK) == 0){ +void statfree(void *p) +{ + if (p) { + if (*((dword *)p - HEAD_SLACK) == 0) { fprintf(stderr,"ERROR: Attempt to free pointer twice.\n"); *(int*)0=0; exit(-1); } else { - if (*((dword *)p - HEAD_SLACK) > 8192){ + if (*((dword *)p - HEAD_SLACK) > 8192) { fprintf(stderr,"ERROR: Corrupted free() buffer. (header)\n"); *(int*)0=0; exit(-1); @@ -349,7 +351,7 @@ void statfree(void *p){ if ((*(byte *)((char *)p + (*((dword *)p - 1)) + sizeof(byte) * 0) != 0xde) || (*(byte *)((char *)p + (*((dword *)p - 1)) + sizeof(byte) * 1) != 0xad) || (*(byte *)((char *)p + (*((dword *)p - 1)) + sizeof(byte) * 2) != 0xbe) || - (*(byte *)((char *)p + (*((dword *)p - 1)) + sizeof(byte) * 3) != 0xef)){ + (*(byte *)((char *)p + (*((dword *)p - 1)) + sizeof(byte) * 3) != 0xef)) { fprintf(stderr,"ERROR: Corrupted free() buffer. (footer)\n"); *(int*)0=0; exit(-1); @@ -365,11 +367,12 @@ void statfree(void *p){ } } -char *strtdiff(char *d,long signeddiff){ +char *strtdiff(char *d,long signeddiff) +{ dword diff; dword seconds,minutes,hours; long days; - if ((diff = labs(signeddiff))){ + if ((diff = labs(signeddiff))) { seconds = diff % 60; diff/= 60; minutes = diff % 60; diff/= 60; hours = diff % 24; @@ -389,33 +392,40 @@ char *strtdiff(char *d,long signeddiff){ return d; } -int issetfd(fd_set *set,int fd){ +int issetfd(fd_set *set,int fd) +{ return (int)((FD_ISSET(fd,set)) && 1); } -void setfd(fd_set *set,int fd){ +void setfd(fd_set *set,int fd) +{ FD_SET(fd,set); } -void clearfd(fd_set *set,int fd){ +void clearfd(fd_set *set,int fd) +{ FD_CLR(fd,set); } -void clearset(fd_set *set){ +void clearset(fd_set *set) +{ FD_ZERO(set); } -char *strlongip(ip_t ip){ +char *strlongip(ip_t ip) +{ struct in_addr a; a.s_addr = htonl(ip); return inet_ntoa(a); } -ip_t longipstr(char *s){ +ip_t longipstr(char *s) +{ return inet_addr(s); } -int dns_forward(char *name){ +int dns_forward(char *name) +{ struct hostent *host; if ((host = gethostbyname(name))) return *(int *)host->h_addr; @@ -423,14 +433,17 @@ int dns_forward(char *name){ return 0; } -int dns_waitfd(){ +int dns_waitfd(void) +{ return resfd; } -void dns_open(){ +void dns_open(void) +{ int option,i; + res_init(); - if (!_res.nscount){ + if (!_res.nscount) { fprintf(stderr,"No nameservers defined.\n"); exit(-1); } @@ -438,29 +451,30 @@ void dns_open(){ for (i = 0;i < _res.nscount;i++) _res.nsaddr_list[i].sin_family = AF_INET; resfd = socket(AF_INET, SOCK_DGRAM, 0); - if (resfd == -1){ + if (resfd == -1) { fprintf(stderr,"Unable to allocate socket for nameserver communication: %s\n", strerror(errno)); exit(-1); } option = 1; - if (setsockopt(resfd,SOL_SOCKET,SO_BROADCAST,(char *)&option,sizeof(option))){ + if (setsockopt(resfd,SOL_SOCKET,SO_BROADCAST,(char *)&option,sizeof(option))) { fprintf(stderr,"Unable to setsockopt() on nameserver communication socket: %s\n", strerror(errno)); exit(-1); } localhost = longipstr("127.0.0.1"); aseed = time(NULL) ^ (time(NULL) << 3) ^ (dword)getpid(); - for (i = 0;i < BashSize;i++){ + for (i = 0;i < BashSize;i++) { idbash[i] = NULL; hostbash[i] = NULL; } } -struct resolve *allocresolve(){ +struct resolve *allocresolve(void) +{ struct resolve *rp; rp = (struct resolve *)statmalloc(sizeof(struct resolve)); - if (!rp){ + if (!rp) { fprintf(stderr,"statmalloc() failed: %s\n",strerror(errno)); exit(-1); } @@ -468,34 +482,38 @@ struct resolve *allocresolve(){ return rp; } -dword getidbash(word id){ +dword getidbash(word id) +{ return (dword)BashModulo(id); } -dword getipbash(ip_t ip){ +dword getipbash(ip_t ip) +{ return (dword)BashModulo(ip); } -dword gethostbash(char *host){ +dword gethostbash(char *host) +{ dword bashvalue = 0; - for (;*host;host++){ + for (;*host;host++) { bashvalue^= *host; bashvalue+= (*host >> 1) + (bashvalue >> 1); } return BashModulo(bashvalue); } -void linkresolveid(struct resolve *addrp){ +void linkresolveid(struct resolve *addrp) +{ struct resolve *rp; dword bashnum; bashnum = getidbash(addrp->id); rp = idbash[bashnum]; - if (rp){ + if (rp) { while ((rp->nextid) && (addrp->id > rp->nextid->id)) rp = rp->nextid; while ((rp->previousid) && (addrp->id < rp->previousid->id)) rp = rp->previousid; - if (rp->id < addrp->id){ + if (rp->id < addrp->id) { addrp->previousid = rp; addrp->nextid = rp->nextid; if (rp->nextid) @@ -513,7 +531,8 @@ void linkresolveid(struct resolve *addrp){ idbash[bashnum] = addrp; } -void unlinkresolveid(struct resolve *rp){ +void unlinkresolveid(struct resolve *rp) +{ dword bashnum; bashnum = getidbash(rp->id); if (idbash[bashnum] == rp) @@ -524,17 +543,18 @@ void unlinkresolveid(struct resolve *rp){ rp->previousid->nextid = rp->nextid; } -void linkresolvehost(struct resolve *addrp){ +void linkresolvehost(struct resolve *addrp) +{ struct resolve *rp; dword bashnum; bashnum = gethostbash(addrp->hostname); rp = hostbash[bashnum]; - if (rp){ + if (rp) { while ((rp->nexthost) && (strcasecmp(addrp->hostname,rp->nexthost->hostname) < 0)) rp = rp->nexthost; while ((rp->previoushost) && (strcasecmp(addrp->hostname,rp->previoushost->hostname) > 0)) rp = rp->previoushost; - if (strcasecmp(addrp->hostname,rp->hostname) < 0){ + if (strcasecmp(addrp->hostname,rp->hostname) < 0) { addrp->previoushost = rp; addrp->nexthost = rp->nexthost; if (rp->nexthost) @@ -552,7 +572,8 @@ void linkresolvehost(struct resolve *addrp){ hostbash[bashnum] = addrp; } -void unlinkresolvehost(struct resolve *rp){ +void unlinkresolvehost(struct resolve *rp) +{ dword bashnum; bashnum = gethostbash(rp->hostname); if (hostbash[bashnum] == rp) @@ -564,17 +585,18 @@ void unlinkresolvehost(struct resolve *rp){ statfree(rp->hostname); } -void linkresolveip(struct resolve *addrp){ +void linkresolveip(struct resolve *addrp) +{ struct resolve *rp; dword bashnum; bashnum = getipbash(addrp->ip); rp = ipbash[bashnum]; - if (rp){ + if (rp) { while ((rp->nextip) && (addrp->ip > rp->nextip->ip)) rp = rp->nextip; while ((rp->previousip) && (addrp->ip < rp->previousip->ip)) rp = rp->previousip; - if (rp->ip < addrp->ip){ + if (rp->ip < addrp->ip) { addrp->previousip = rp; addrp->nextip = rp->nextip; if (rp->nextip) @@ -592,7 +614,8 @@ void linkresolveip(struct resolve *addrp){ ipbash[bashnum] = addrp; } -void unlinkresolveip(struct resolve *rp){ +void unlinkresolveip(struct resolve *rp) +{ dword bashnum; bashnum = getipbash(rp->ip); if (ipbash[bashnum] == rp) @@ -603,12 +626,13 @@ void unlinkresolveip(struct resolve *rp){ rp->previousip->nextip = rp->nextip; } -void linkresolve(struct resolve *rp){ +void linkresolve(struct resolve *rp) +{ struct resolve *irp; - if (expireresolves){ + if (expireresolves) { irp = expireresolves; while ((irp->next) && (rp->expiretime >= irp->expiretime)) irp = irp->next; - if (rp->expiretime >= irp->expiretime){ + if (rp->expiretime >= irp->expiretime) { rp->next = NULL; rp->previous = irp; irp->next = rp; @@ -630,13 +654,14 @@ void linkresolve(struct resolve *rp){ resolvecount++; } -void lastlinkresolve(struct resolve *rp){ +void lastlinkresolve(struct resolve *rp) +{ struct resolve *irp; - if (lastresolve){ + if (lastresolve) { irp = lastresolve; while ((irp->previous) && (rp->expiretime < irp->expiretime)) irp = irp->previous; while ((irp->next) && (rp->expiretime >= irp->expiretime)) irp = irp->next; - if (rp->expiretime >= irp->expiretime){ + if (rp->expiretime >= irp->expiretime) { rp->next = NULL; rp->previous = irp; irp->next = rp; @@ -658,7 +683,8 @@ void lastlinkresolve(struct resolve *rp){ resolvecount++; } -void untieresolve(struct resolve *rp){ +void untieresolve(struct resolve *rp) +{ if (rp->previous) rp->previous->next = rp->next; else @@ -670,7 +696,8 @@ void untieresolve(struct resolve *rp){ resolvecount--; } -void unlinkresolve(struct resolve *rp){ +void unlinkresolve(struct resolve *rp) +{ untieresolve(rp); unlinkresolveid(rp); unlinkresolveip(rp); @@ -678,17 +705,18 @@ void unlinkresolve(struct resolve *rp){ unlinkresolvehost(rp); } -struct resolve *findid(word id){ +struct resolve *findid(word id) +{ struct resolve *rp; int bashnum; bashnum = getidbash(id); rp = idbash[bashnum]; - if (rp){ + if (rp) { while ((rp->nextid) && (id >= rp->nextid->id)) rp = rp->nextid; while ((rp->previousid) && (id <= rp->previousid->id)) rp = rp->previousid; - if (id == rp->id){ + if (id == rp->id) { idbash[bashnum] = rp; return rp; } else @@ -697,12 +725,13 @@ struct resolve *findid(word id){ return rp; /* NULL */ } -struct resolve *findhost(char *hostname){ +struct resolve *findhost(char *hostname) +{ struct resolve *rp; int bashnum; bashnum = gethostbash(hostname); rp = hostbash[bashnum]; - if (rp){ + if (rp) { while ((rp->nexthost) && (strcasecmp(hostname,rp->nexthost->hostname) >= 0)) rp = rp->nexthost; while ((rp->previoushost) && (strcasecmp(hostname,rp->nexthost->hostname) <= 0)) @@ -717,17 +746,18 @@ struct resolve *findhost(char *hostname){ return rp; /* NULL */ } -struct resolve *findip(ip_t ip){ +struct resolve *findip(ip_t ip) +{ struct resolve *rp; dword bashnum; bashnum = getipbash(ip); rp = ipbash[bashnum]; - if (rp){ + if (rp) { while ((rp->nextip) && (ip >= rp->nextip->ip)) rp = rp->nextip; while ((rp->previousip) && (ip <= rp->previousip->ip)) rp = rp->previousip; - if (ip == rp->ip){ + if (ip == rp->ip) { ipbash[bashnum] = rp; return rp; } else @@ -736,17 +766,19 @@ struct resolve *findip(ip_t ip){ return rp; /* NULL */ } -void restell(char *s){ +void restell(char *s) +{ fputs(s,stderr); fputs("\r",stderr); } -void dorequest(char *s,int type,word id){ +void dorequest(char *s,int type,word id) +{ packetheader *hp; int r,i; int buf[(MaxPacketsize/sizeof (int))+1]; r = res_mkquery(QUERY,s,C_IN,type,NULL,0,NULL,(unsigned char*)buf,MaxPacketsize); - if (r == -1){ + if (r == -1) { restell("Resolver error: Query too large."); return; } @@ -757,22 +789,23 @@ void dorequest(char *s,int type,word id){ sizeof(struct sockaddr)); } -void resendrequest(struct resolve *rp,int type){ - if (type == T_A){ +void resendrequest(struct resolve *rp,int type) +{ + if (type == T_A) { dorequest(rp->hostname,type,rp->id); - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Sent reverse authentication request for \"%s\".", rp->hostname); restell(tempstring); } - } else if (type == T_PTR){ + } else if (type == T_PTR) { sprintf(tempstring,"%u.%u.%u.%u.in-addr.arpa", ((byte *)&rp->ip)[3], ((byte *)&rp->ip)[2], ((byte *)&rp->ip)[1], ((byte *)&rp->ip)[0]); dorequest(tempstring,type,rp->id); - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Sent domain lookup request for \"%s\".", strlongip(rp->ip)); restell(tempstring); @@ -780,7 +813,8 @@ void resendrequest(struct resolve *rp,int type){ } } -void sendrequest(struct resolve *rp,int type){ +void sendrequest(struct resolve *rp,int type) +{ do { idseed = (((idseed + idseed) | (long)time(NULL)) + idseed - 0x54bad4a) ^ aseed; aseed^= idseed; @@ -790,7 +824,8 @@ void sendrequest(struct resolve *rp,int type){ resendrequest(rp,type); } -void failrp(struct resolve *rp){ +void failrp(struct resolve *rp) +{ if (rp->state == STATE_FINISHED) return; rp->state = STATE_FAILED; @@ -799,17 +834,19 @@ void failrp(struct resolve *rp){ restell("Resolver: Lookup failed.\n"); } -void passrp(struct resolve *rp,long ttl){ +void passrp(struct resolve *rp,long ttl) +{ rp->state = STATE_FINISHED; rp->expiretime = sweeptime + (double)ttl; untieresolve(rp); - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Lookup successful: %s\n",rp->hostname); restell(tempstring); } } -void parserespacket(byte *s,int l){ +void parserespacket(byte *s,int l) +{ struct resolve *rp; packetheader *hp; byte *eob; @@ -818,11 +855,11 @@ void parserespacket(byte *s,int l){ int r,usefulanswer; word rr,datatype,class,qdatatype,qclass; byte rdatalength; - if (l < sizeof(packetheader)){ + if (l < sizeof(packetheader)) { restell("Resolver error: Packet smaller than standard header size."); return; } - if (l == sizeof(packetheader)){ + if (l == sizeof(packetheader)) { restell("Resolver error: Packet has empty body."); return; } @@ -830,7 +867,7 @@ void parserespacket(byte *s,int l){ /* Convert data to host byte order */ /* hp->id does not need to be redundantly byte-order flipped, it is only echoed by nameserver */ rp = findid(hp->id); - if (!rp){ + if (!rp) { res_unknownid++; return; } @@ -840,37 +877,37 @@ void parserespacket(byte *s,int l){ hp->ancount = ntohs(hp->ancount); hp->nscount = ntohs(hp->nscount); hp->arcount = ntohs(hp->arcount); - if (getheader_tc(hp)){ /* Packet truncated */ + if (getheader_tc(hp)) { /* Packet truncated */ restell("Resolver error: Nameserver packet truncated."); return; } - if (!getheader_qr(hp)){ /* Not a reply */ + if (!getheader_qr(hp)) { /* Not a reply */ restell("Resolver error: Query packet received on nameserver communication socket."); return; } - if (getheader_opcode(hp)){ /* Not opcode 0 (standard query) */ + if (getheader_opcode(hp)) { /* Not opcode 0 (standard query) */ restell("Resolver error: Invalid opcode in response packet."); return; } eob = s + l; c = s + HFIXEDSZ; - switch (getheader_rcode(hp)){ + switch (getheader_rcode(hp)) { case NOERROR: - if (hp->ancount){ - if (debug){ + if (hp->ancount) { + if (debug) { sprintf(tempstring,"Resolver: Received nameserver reply. (qd:%u an:%u ns:%u ar:%u)", hp->qdcount,hp->ancount,hp->nscount,hp->arcount); restell(tempstring); } - if (hp->qdcount != 1){ + if (hp->qdcount != 1) { restell("Resolver error: Reply does not contain one query."); return; } - if (c > eob){ + if (c > eob) { restell("Resolver error: Reply too short."); return; } - switch (rp->state){ /* Construct expected query reply */ + switch (rp->state) { /* Construct expected query reply */ case STATE_PTRREQ1: case STATE_PTRREQ2: case STATE_PTRREQ3: @@ -883,40 +920,40 @@ void parserespacket(byte *s,int l){ } *namestring = '\0'; r = dn_expand(s,s + l,c,namestring,MAXDNAME); - if (r == -1){ + if (r == -1) { restell("Resolver error: dn_expand() failed while expanding query domain."); return; } namestring[strlen(stackstring)] = '\0'; - if (strcasecmp(stackstring,namestring)){ - if (debug){ + if (strcasecmp(stackstring,namestring)) { + if (debug) { sprintf(tempstring,"Resolver: Unknown query packet dropped. (\"%s\" does not match \"%s\")", stackstring,namestring); restell(tempstring); } return; } - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Queried domain name: \"%s\"",namestring); restell(tempstring); } c+= r; - if (c + 4 > eob){ + if (c + 4 > eob) { restell("Resolver error: Query resource record truncated."); return; } qdatatype = sucknetword(c); qclass = sucknetword(c); - if (qclass != C_IN){ + if (qclass != C_IN) { sprintf(tempstring,"Resolver error: Received unsupported query class: %u (%s)", qclass,qclass < ClasstypeCount ? classtypes[qclass] : classtypes[ClasstypeCount]); restell(tempstring); } - switch (qdatatype){ + switch (qdatatype) { case T_PTR: if (!Is_PTR(rp)) - if (debug){ + if (debug) { restell("Resolver warning: Ignoring response with unexpected query type \"PTR\"."); return; } @@ -927,14 +964,14 @@ void parserespacket(byte *s,int l){ resourcetypes[qdatatype] : resourcetypes[ResourcetypeCount]); restell(tempstring); } - for (rr = hp->ancount + hp->nscount + hp->arcount;rr;rr--){ - if (c > eob){ + for (rr = hp->ancount + hp->nscount + hp->arcount;rr;rr--) { + if (c > eob) { restell("Resolver error: Packet does not contain all specified resouce records."); return; } *namestring = '\0'; r = dn_expand(s,s + l,c,namestring,MAXDNAME); - if (r == -1){ + if (r == -1) { restell("Resolver error: dn_expand() failed while expanding answer domain."); return; } @@ -943,12 +980,12 @@ void parserespacket(byte *s,int l){ usefulanswer = 0; else usefulanswer = 1; - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: answered domain query: \"%s\"",namestring); restell(tempstring); } c+= r; - if (c + 10 > eob){ + if (c + 10 > eob) { restell("Resolver error: Resource record truncated."); return; } @@ -956,7 +993,7 @@ void parserespacket(byte *s,int l){ class = sucknetword(c); ttl = sucknetlong(c); rdatalength = sucknetword(c); - if (class != qclass){ + if (class != qclass) { sprintf(tempstring,"query class: %u (%s)",qclass,qclass < ClasstypeCount ? classtypes[qclass] : classtypes[ClasstypeCount]); restell(tempstring); @@ -966,29 +1003,29 @@ void parserespacket(byte *s,int l){ restell("Resolver error: Answered class does not match queried class."); return; } - if (!rdatalength){ + if (!rdatalength) { restell("Resolver error: Zero size rdata."); return; } - if (c + rdatalength > eob){ + if (c + rdatalength > eob) { restell("Resolver error: Specified rdata length exceeds packet size."); return; } - if (datatype == qdatatype || datatype == T_CNAME){ - if (debug){ + if (datatype == qdatatype || datatype == T_CNAME) { + if (debug) { sprintf(tempstring,"Resolver: TTL: %s",strtdiff(sendstring,ttl)); restell(tempstring); } if (usefulanswer) - switch (datatype){ + switch (datatype) { case T_A: - if (rdatalength != 4){ + if (rdatalength != 4) { sprintf(tempstring,"Resolver error: Unsupported rdata format for \"A\" type. (%u bytes)", rdatalength); restell(tempstring); return; } - if (memcmp(&rp->ip,(ip_t *)c,sizeof(ip_t))){ + if (memcmp(&rp->ip,(ip_t *)c,sizeof(ip_t))) { sprintf(tempstring,"Resolver: Reverse authentication failed: %s != ", strlongip(rp->ip)); memcpy(&alignedip,(ip_t *)c,sizeof(ip_t)); @@ -1009,26 +1046,26 @@ void parserespacket(byte *s,int l){ case T_CNAME: *namestring = '\0'; r = dn_expand(s,s + l,c,namestring,MAXDNAME); - if (r == -1){ + if (r == -1) { restell("Resolver error: dn_expand() failed while expanding domain in rdata."); return; } - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Answered domain: \"%s\"",namestring); restell(tempstring); } - if (r > HostnameLength){ + if (r > HostnameLength) { restell("Resolver error: Domain name too long."); failrp(rp); return; } - if (datatype == T_CNAME){ + if (datatype == T_CNAME) { strcpy(stackstring,namestring); break; } - if (!rp->hostname){ + if (!rp->hostname) { rp->hostname = (char *)statmalloc(strlen(namestring) + 1); - if (!rp->hostname){ + if (!rp->hostname) { fprintf(stderr,"statmalloc() error: %s\n",strerror(errno)); exit(-1); } @@ -1045,7 +1082,7 @@ void parserespacket(byte *s,int l){ restell(tempstring); } } else { - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Ignoring resource type %u. (%s)", datatype,datatype < ResourcetypeCount ? resourcetypes[datatype] : resourcetypes[ResourcetypeCount]); @@ -1072,12 +1109,13 @@ void parserespacket(byte *s,int l){ } } -void dns_ack(){ +void dns_ack(void) +{ int r,i; r = recvfrom(resfd,(byte *)resrecvbuf,MaxPacketsize,0,(struct sockaddr *)&from,&fromlen); - if (r > 0){ + if (r > 0) { /* Check to see if this server is actually one we sent to */ - if (from.sin_addr.s_addr == localhost){ + if (from.sin_addr.s_addr == localhost) { for (i = 0;i < _res.nscount;i++) if ((_res.nsaddr_list[i].sin_addr.s_addr == from.sin_addr.s_addr) || (!_res.nsaddr_list[i].sin_addr.s_addr)) /* 0.0.0.0 replies as 127.0.0.1 */ @@ -1086,7 +1124,7 @@ void dns_ack(){ for (i = 0;i < _res.nscount;i++) if (_res.nsaddr_list[i].sin_addr.s_addr == from.sin_addr.s_addr) break; - if (i == _res.nscount){ + if (i == _res.nscount) { sprintf(tempstring,"Resolver error: Received reply from unknown source: %s", inet_ntoa(from.sin_addr)); restell(tempstring); @@ -1098,7 +1136,8 @@ void dns_ack(){ } } -int istime(double x,double *sinterval){ +int istime(double x,double *sinterval) +{ if (x) { if (x > sweeptime) { if (*sinterval > x - sweeptime) @@ -1109,14 +1148,15 @@ int istime(double x,double *sinterval){ return 0; } -void dns_events(double *sinterval){ +void dns_events(double *sinterval) +{ struct resolve *rp,*nextrp; - for (rp = expireresolves;(rp) && (sweeptime >= rp->expiretime);rp = nextrp){ + for (rp = expireresolves;(rp) && (sweeptime >= rp->expiretime);rp = nextrp) { nextrp = rp->next; - switch (rp->state){ + switch (rp->state) { case STATE_FINISHED: /* TTL has expired */ case STATE_FAILED: /* Fake TTL has expired */ - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Cache record for \"%s\" (%s) has expired. (state: %u) Marked for expire at: %g, time: %g.", nonull(rp->hostname),strlongip(rp->ip),rp->state,rp->expiretime,sweeptime); restell(tempstring); @@ -1151,20 +1191,21 @@ void dns_events(double *sinterval){ (void)istime(expireresolves->expiretime,sinterval); } -char *dns_lookup2(ip_t ip){ +char *dns_lookup2(ip_t ip) +{ struct resolve *rp; ip = htonl(ip); - if ((rp = findip(ip))){ - if ((rp->state == STATE_FINISHED) || (rp->state == STATE_FAILED)){ - if ((rp->state == STATE_FINISHED) && (rp->hostname)){ - if (debug){ + if ((rp = findip(ip))) { + if ((rp->state == STATE_FINISHED) || (rp->state == STATE_FAILED)) { + if ((rp->state == STATE_FINISHED) && (rp->hostname)) { + if (debug) { sprintf(tempstring,"Resolver: Used cached record: %s == \"%s\".\n", strlongip(ip),rp->hostname); restell(tempstring); } return rp->hostname; } else { - if (debug){ + if (debug) { sprintf(tempstring,"Resolver: Used failed record: %s == ???\n", strlongip(ip)); restell(tempstring); @@ -1189,7 +1230,8 @@ char *dns_lookup2(ip_t ip){ int use_dns = 1; -char *dns_lookup(ip_t ip){ +char *dns_lookup(ip_t ip) +{ char *t; if (!dns) return strlongip (ip); diff --git a/gtk.c b/gtk.c index 52357a4..2d72a29 100644 --- a/gtk.c +++ b/gtk.c @@ -56,7 +56,8 @@ void gtk_add_ping_timeout (void) } -void gtk_do_init(int *argc, char ***argv) { +void gtk_do_init(int *argc, char ***argv) +{ static int done = 0; if(!done) { @@ -66,7 +67,8 @@ void gtk_do_init(int *argc, char ***argv) { } } -int gtk_detect(int *argc, char ***argv) { +int gtk_detect(int *argc, char ***argv) +{ if(getenv("DISPLAY") != NULL) { /* If we do this here, gtk_init exits on an error. This happens BEFORE the user has had a chance to tell us not to use the @@ -77,13 +79,15 @@ int gtk_detect(int *argc, char ***argv) { } } -gint Window_destroy(GtkWidget *Window, gpointer data) { +gint Window_destroy(GtkWidget *Window, gpointer data) +{ gtk_main_quit(); return FALSE; } -gint Restart_clicked(GtkWidget *Button, gpointer data) { +gint Restart_clicked(GtkWidget *Button, gpointer data) +{ net_reset(); gtk_redraw(); @@ -91,7 +95,8 @@ gint Restart_clicked(GtkWidget *Button, gpointer data) { } -gint Pause_clicked(GtkWidget *Button, gpointer data) { +gint Pause_clicked(GtkWidget *Button, gpointer data) +{ static int paused = 0; if (paused) { @@ -114,7 +119,8 @@ gint Pause_clicked(GtkWidget *Button, gpointer data) { * What's the problem with this? (-> "I don't think so) -- REW */ -gint WaitTime_changed(GtkAdjustment *Adj, GtkWidget *Button) { +gint WaitTime_changed(GtkAdjustment *Adj, GtkWidget *Button) +{ WaitTime = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(Button)); gtk_timeout_remove (tag); gtk_add_ping_timeout (); @@ -123,7 +129,8 @@ gint WaitTime_changed(GtkAdjustment *Adj, GtkWidget *Button) { return FALSE; } -gint Host_activate(GtkWidget *Entry, gpointer data) { +gint Host_activate(GtkWidget *Entry, gpointer data) +{ int addr; addr = dns_forward(gtk_entry_get_text(GTK_ENTRY(Entry))); @@ -140,13 +147,15 @@ gint Host_activate(GtkWidget *Entry, gpointer data) { return FALSE; } -GdkPixmap *gtk_load_pixmap(char **pixmap) { +GdkPixmap *gtk_load_pixmap(char **pixmap) +{ return gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_colormap_get_system(), NULL, NULL, pixmap); } -void Toolbar_fill(GtkWidget *Toolbar) { +void Toolbar_fill(GtkWidget *Toolbar) +{ GtkWidget *Button; GtkWidget *Label; GtkWidget *Entry; @@ -203,7 +212,8 @@ int Report_Positions[] = { 10, 200, 240, 280, 320, 360, 400, 440, 480, 0 }; GtkWidget *Report; GtkWidget *ReportBody; -GtkWidget *GetRow(int index) { +GtkWidget *GetRow(int index) +{ int addr; char *name; GtkWidget *Row, *Label; @@ -228,7 +238,8 @@ GtkWidget *GetRow(int index) { return Row; } -GtkWidget *Scrollarea_create() { +GtkWidget *Scrollarea_create() +{ GtkWidget *List; GtkWidget *scroll; int count; @@ -254,7 +265,8 @@ GtkWidget *Scrollarea_create() { return scroll; } -void gtk_add_row(GtkWidget *List) { +void gtk_add_row(GtkWidget *List) +{ int at; GtkWidget *Row, *Label; @@ -280,14 +292,16 @@ void gtk_set_field(GtkCList *List, int row, int ix, char *str) { //void gtk_set_field_num(GtkCList *List, int row, int ix, char *format, int num) { // changed int to dobule byMin -void gtk_set_field_num(GtkCList *List, int row, int ix, char *format, double num) { +void gtk_set_field_num(GtkCList *List, int row, int ix, char *format, double num) +{ char str[32]; sprintf(str, format, num); gtk_set_field(List, row, ix, str); } -void gtk_update_row(GtkCList *List, int row) { +void gtk_update_row(GtkCList *List, int row) +{ int addr; char str[256], *name; GdkColor color; @@ -331,7 +345,8 @@ void gtk_update_row(GtkCList *List, int row) { } -void gtk_redraw() { +void gtk_redraw() +{ int at = net_min(); // changed from 0 to net_min for TTL stuff byMin int max = net_max(); @@ -353,7 +368,8 @@ void gtk_redraw() { gtk_clist_thaw(GTK_CLIST(ReportBody)); } -void Window_fill(GtkWidget *Window) { +void Window_fill(GtkWidget *Window) +{ GtkWidget *VBox; GtkWidget *Toolbar; GtkWidget *List; @@ -377,7 +393,8 @@ void Window_fill(GtkWidget *Window) { gtk_widget_show(VBox); } -void gtk_open() { +void gtk_open() +{ GtkWidget *Window; GdkPixmap *icon; @@ -406,14 +423,17 @@ void gtk_open() { gdk_window_set_icon_name(Window->window, "mtr"); } -void gtk_close() { +void gtk_close() +{ } -int gtk_keyaction() { +int gtk_keyaction() +{ return 0; } -gint gtk_ping(gpointer data) { +gint gtk_ping(gpointer data) +{ gtk_redraw(); net_send_batch(); gtk_timeout_remove (tag); @@ -421,18 +441,21 @@ gint gtk_ping(gpointer data) { return TRUE; } -void gtk_net_data(gpointer data, gint fd, GdkInputCondition cond) { +void gtk_net_data(gpointer data, gint fd, GdkInputCondition cond) +{ net_process_return(); } -void gtk_dns_data(gpointer data, gint fd, GdkInputCondition cond) { +void gtk_dns_data(gpointer data, gint fd, GdkInputCondition cond) +{ dns_ack(); gtk_redraw(); } -void gtk_loop() { +void gtk_loop() +{ gtk_add_ping_timeout (); gdk_input_add(net_waitfd(), GDK_INPUT_READ, gtk_net_data, NULL); gdk_input_add(dns_waitfd(), GDK_INPUT_READ, gtk_dns_data, NULL); diff --git a/raw.c b/raw.c index d8b112d..65c1129 100644 --- a/raw.c +++ b/raw.c @@ -51,7 +51,7 @@ void raw_rawping (int host, int msec) { char *name; - if (!havename[host]) { + if (dns && !havename[host]) { name = dns_lookup2(net_addr(host)); if (name) { havename[host]++; diff --git a/select.c b/select.c index bd12811..7136582 100644 --- a/select.c +++ b/select.c @@ -70,9 +70,12 @@ void select_loop() { maxfd = 1; } - dnsfd = dns_waitfd(); - FD_SET(dnsfd, &readfd); - if(dnsfd >= maxfd) maxfd = dnsfd + 1; + if (dns) { + dnsfd = dns_waitfd(); + FD_SET(dnsfd, &readfd); + if(dnsfd >= maxfd) maxfd = dnsfd + 1; + } else + dnsfd = 0; netfd = net_waitfd(); FD_SET(netfd, &readfd); @@ -136,12 +139,14 @@ void select_loop() { anyset = 1; } - /* Handle any pending resolver events */ - dnsinterval = WaitTime; - dns_events(&dnsinterval); + if (dns) { + /* Handle any pending resolver events */ + dnsinterval = WaitTime; + dns_events(&dnsinterval); + } /* Have we finished a nameservice lookup? */ - if(FD_ISSET(dnsfd, &readfd)) { + if(dns && FD_ISSET(dnsfd, &readfd)) { dns_ack(); anyset = 1; }