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");
}
}
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;
}
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)
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 ':':
}
memset(&aihint, 0, sizeof(aihint));
- aihint.ai_family = PF_INET; /* Only IPv4 for now. */
aihint.ai_socktype = SOCK_RAW;
aihint.ai_protocol = IPPROTO_ICMP;
ret = getaddrinfo(argv[optind], NULL, &aihint, &ai);
pfd.events = POLLIN;
gettimeofday(&tvc, NULL);
elapsed = ((tvc.tv_sec - tvb.tv_sec) * 1000) + ((tvc.tv_usec - tvb.tv_usec) / 1000);
- if(elapsed > timeout) {
+ if(elapsed >= timeout) {
fprintf(stderr, "idnlookup: timeout\n");
exit(1);
}
}
}
+ if(dispttl)
+ printf("%i\n", ntohl(rep.ttl));
printdn(stdout, buf + sizeof(iphdr) + sizeof(rep), ret - sizeof(iphdr) - sizeof(rep));
close(s);