X-Git-Url: http://dolda2000.com/gitweb/?p=icmp-dn.git;a=blobdiff_plain;f=idnlookup.c;h=be4809bc934a443aa53a3e17c37b88dcbd6d2de6;hp=bd45b750583a7b433dba28445dd57da8759bbbfd;hb=15a913c297d12c0a4b14c01437420ac0df8b6675;hpb=3d6143ece9dc7829a59674c2d1148830a480d7ce diff --git a/idnlookup.c b/idnlookup.c index bd45b75..be4809b 100644 --- a/idnlookup.c +++ b/idnlookup.c @@ -73,11 +73,13 @@ void printdn(FILE *f, unsigned char *dnbuf, size_t size) fprintf(stderr, "domain name decompression not implemented, aborting\n"); exit(1); } - printf("%.*s.", (int)*p, p + 1); + fprintf(f, "%.*s", (int)*p, p + 1); p += 1 + (int)*p; + if(*p != 0) + fprintf(f, "."); } p++; - printf("\n"); + fprintf(f, "\n"); } } @@ -86,7 +88,7 @@ void cksum(void *hdr, size_t len) struct icmphdr *ih; u_int8_t *cb; int i; - u_int8_t b1, b2; + int b1, b2; ih = (struct icmphdr *)hdr; cb = (u_int8_t *)hdr; @@ -98,9 +100,22 @@ void cksum(void *hdr, size_t len) } if(i & 1) b1 += cb[len - 1]; + while(1) { + if(b1 >= 256) { + b2 += b1 >> 8; + b1 &= 0xff; + continue; + } + if(b2 >= 256) { + b1 += b2 >> 8; + b2 &= 0xff; + continue; + } + break; + } cb = (u_int8_t *)&ih->checksum; - cb[0] = ~b1; - cb[1] = ~b2; + cb[0] = ~(u_int8_t)b1; + cb[1] = ~(u_int8_t)b2; } void usage(void) @@ -121,14 +136,19 @@ int main(int argc, char **argv) struct pollfd pfd; struct timeval tvb, tvc; struct sockaddr_storage name; - int timeout, elapsed; + int timeout, dispttl; + int elapsed; timeout = 3000; - while((c = getopt(argc, argv, "ht:")) != -1) { + dispttl = 0; + while((c = getopt(argc, argv, "hTt:")) != -1) { switch(c) { case 't': timeout = atoi(optarg); break; + case 'T': + dispttl = 1; + break; case 'h': case '?': case ':': @@ -221,6 +241,8 @@ int main(int argc, char **argv) } } + if(dispttl) + printf("%i\n", ntohl(rep.ttl)); printdn(stdout, buf + sizeof(iphdr) + sizeof(rep), ret - sizeof(iphdr) - sizeof(rep)); close(s);