seq = 0; done = 0; for (ttl = 1; ttl <= max_ttl && done == 0; ttl++) { Setsockopt(sendfd, pr->ttllevel, pr->ttloptname, &ttl, sizeof(int)); bzero(pr->salast, pr->salen);
printf("%2d ", ttl); fflush(stdout);
for (probe = 0; probe < nprobes; probe++) { rec = (struct rec *) sendbuf; rec->rec_seq = ++seq; rec->rec_ttl = ttl; Gettimeofday(&rec->rec_tv, NULL);
sock_set_port(pr->sasend, pr->salen, htons(dport + seq)); Sendto(sendfd, sendbuf, datalen, 0, pr->sasend, pr->salen);
if ( (code = (*pr->recv)(seq, &tvrecv)) == -3) printf(" *"); /* timeout, no reply */ else { char str[NI_MAXHOST];
if (sock_cmp_addr(pr->sarecv, pr->salast, pr->salen) != 0) { if (getnameinfo(pr->sarecv, pr->salen, str, sizeof(str), NULL, 0, 0) == 0) printf(" %s (%s)", str, Sock_ntop_host(pr->sarecv, pr->salen)); else printf(" %s", Sock_ntop_host(pr->sarecv, pr->salen)); memcpy(pr->salast, pr->sarecv, pr->salen); } tv_sub(&tvrecv, &rec->rec_tv); rtt = tvrecv.tv_sec * 1000.0 + tvrecv.tv_usec / 1000.0; printf(" %.3f ms", rtt);
if (code == -1) /* port unreachable; at destination */ done++; else if (code >= 0) printf(" (ICMP %s)", (*pr->icmpcode)(code)); } fflush(stdout); } printf("\n"); }
|