traceroute6.c (176154) | traceroute6.c (196475) |
---|---|
1/* $KAME: traceroute6.c,v 1.68 2004/01/25 11:16:12 suz Exp $ */ 2 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 62 unchanged lines hidden (view full) --- 71 The Regents of the University of California. All rights reserved.\n"; 72#endif /* not lint */ 73 74#ifndef lint 75#if 0 76static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; 77#endif 78static const char rcsid[] = | 1/* $KAME: traceroute6.c,v 1.68 2004/01/25 11:16:12 suz Exp $ */ 2 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 62 unchanged lines hidden (view full) --- 71 The Regents of the University of California. All rights reserved.\n"; 72#endif /* not lint */ 73 74#ifndef lint 75#if 0 76static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; 77#endif 78static const char rcsid[] = |
79 "$FreeBSD: head/usr.sbin/traceroute6/traceroute6.c 176154 2008-02-10 21:06:38Z dwmalone $"; | 79 "$FreeBSD: head/usr.sbin/traceroute6/traceroute6.c 196475 2009-08-23 17:00:16Z ume $"; |
80#endif /* not lint */ 81 82/* 83 * traceroute host - trace the route ip packets follow going to "host". 84 * 85 * Attempt to trace the route an ip packet would follow to some 86 * internet host. We find out intermediate hops by launching probe 87 * packets with a small ttl (time to live) then listening for an --- 189 unchanged lines hidden (view full) --- 277#include <netinet/icmp6.h> 278#include <netinet/udp.h> 279 280#ifdef IPSEC 281#include <net/route.h> 282#include <netipsec/ipsec.h> 283#endif 284 | 80#endif /* not lint */ 81 82/* 83 * traceroute host - trace the route ip packets follow going to "host". 84 * 85 * Attempt to trace the route an ip packet would follow to some 86 * internet host. We find out intermediate hops by launching probe 87 * packets with a small ttl (time to live) then listening for an --- 189 unchanged lines hidden (view full) --- 277#include <netinet/icmp6.h> 278#include <netinet/udp.h> 279 280#ifdef IPSEC 281#include <net/route.h> 282#include <netipsec/ipsec.h> 283#endif 284 |
285#include "as.h" 286 |
|
285#define DUMMY_PORT 10010 286 287#define MAXPACKET 65535 /* max ip packet size */ 288 289#ifndef HAVE_GETIPNODEBYNAME 290#define getipnodebyname(x, y, z, u) gethostbyname2((x), (y)) 291#define freehostent(x) 292#endif --- 61 unchanged lines hidden (view full) --- 354u_int16_t port = 32768+666; /* start udp dest port # for probe packets */ 355u_int16_t ident; 356int options; /* socket options */ 357int verbose; 358int waittime = 5; /* time to wait for response (in seconds) */ 359int nflag; /* print addresses numerically */ 360int useproto = IPPROTO_UDP; /* protocol to use to send packet */ 361int lflag; /* print both numerical address & hostname */ | 287#define DUMMY_PORT 10010 288 289#define MAXPACKET 65535 /* max ip packet size */ 290 291#ifndef HAVE_GETIPNODEBYNAME 292#define getipnodebyname(x, y, z, u) gethostbyname2((x), (y)) 293#define freehostent(x) 294#endif --- 61 unchanged lines hidden (view full) --- 356u_int16_t port = 32768+666; /* start udp dest port # for probe packets */ 357u_int16_t ident; 358int options; /* socket options */ 359int verbose; 360int waittime = 5; /* time to wait for response (in seconds) */ 361int nflag; /* print addresses numerically */ 362int useproto = IPPROTO_UDP; /* protocol to use to send packet */ 363int lflag; /* print both numerical address & hostname */ |
364int as_path; /* print as numbers for each hop */ 365char *as_server = NULL; 366void *asn; |
|
362 363int 364main(argc, argv) 365 int argc; 366 char *argv[]; 367{ 368 int mib[4] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_DEFHLIM }; 369 char hbuf[NI_MAXHOST], src0[NI_MAXHOST], *ep; --- 36 unchanged lines hidden (view full) --- 406#else /* old adv. API */ 407 if (setsockopt(rcvsock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, 408 sizeof(on)) < 0) 409 err(1, "setsockopt(IPV6_HOPLIMIT)"); 410#endif 411 412 seq = 0; 413 | 367 368int 369main(argc, argv) 370 int argc; 371 char *argv[]; 372{ 373 int mib[4] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_DEFHLIM }; 374 char hbuf[NI_MAXHOST], src0[NI_MAXHOST], *ep; --- 36 unchanged lines hidden (view full) --- 411#else /* old adv. API */ 412 if (setsockopt(rcvsock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, 413 sizeof(on)) < 0) 414 err(1, "setsockopt(IPV6_HOPLIMIT)"); 415#endif 416 417 seq = 0; 418 |
414 while ((ch = getopt(argc, argv, "df:g:Ilm:nNp:q:rs:Uvw:")) != -1) | 419 while ((ch = getopt(argc, argv, "aA:df:g:Ilm:nNp:q:rs:Uvw:")) != -1) |
415 switch (ch) { | 420 switch (ch) { |
421 case 'a': 422 as_path = 1; 423 break; 424 case 'A': 425 as_path = 1; 426 as_server = optarg; 427 break; |
|
416 case 'd': 417 options |= SO_DEBUG; 418 break; 419 case 'f': 420 ep = NULL; 421 errno = 0; 422 first_hop = strtoul(optarg, &ep, 0); 423 if (errno || !*optarg || *ep || first_hop > 255) { --- 438 unchanged lines hidden (view full) --- 862 len = sizeof(Src); 863 if (getsockname(sndsock, (struct sockaddr *)&Src, &len) < 0) { 864 perror("getsockname"); 865 exit(1); 866 } 867 srcport = ntohs(Src.sin6_port); 868 } 869 | 428 case 'd': 429 options |= SO_DEBUG; 430 break; 431 case 'f': 432 ep = NULL; 433 errno = 0; 434 first_hop = strtoul(optarg, &ep, 0); 435 if (errno || !*optarg || *ep || first_hop > 255) { --- 438 unchanged lines hidden (view full) --- 874 len = sizeof(Src); 875 if (getsockname(sndsock, (struct sockaddr *)&Src, &len) < 0) { 876 perror("getsockname"); 877 exit(1); 878 } 879 srcport = ntohs(Src.sin6_port); 880 } 881 |
882 if (as_path) { 883 asn = as_setup(as_server); 884 if (asn == NULL) { 885 fprintf(stderr, 886 "traceroute6: as_setup failed, AS# lookups" 887 " disabled\n"); 888 (void)fflush(stderr); 889 as_path = 0; 890 } 891 } 892 |
|
870 /* 871 * Message to users 872 */ 873 if (getnameinfo((struct sockaddr *)&Dst, Dst.sin6_len, hbuf, 874 sizeof(hbuf), NULL, 0, NI_NUMERICHOST)) 875 strlcpy(hbuf, "(invalid)", sizeof(hbuf)); 876 fprintf(stderr, "traceroute6"); 877 fprintf(stderr, " to %s (%s)", hostname, hbuf); --- 65 unchanged lines hidden (view full) --- 943 (void) fflush(stdout); 944 } 945 putchar('\n'); 946 if (got_there || 947 (unreachable > 0 && unreachable >= ((nprobes + 1) / 2))) { 948 exit(0); 949 } 950 } | 893 /* 894 * Message to users 895 */ 896 if (getnameinfo((struct sockaddr *)&Dst, Dst.sin6_len, hbuf, 897 sizeof(hbuf), NULL, 0, NI_NUMERICHOST)) 898 strlcpy(hbuf, "(invalid)", sizeof(hbuf)); 899 fprintf(stderr, "traceroute6"); 900 fprintf(stderr, " to %s (%s)", hostname, hbuf); --- 65 unchanged lines hidden (view full) --- 966 (void) fflush(stdout); 967 } 968 putchar('\n'); 969 if (got_there || 970 (unreachable > 0 && unreachable >= ((nprobes + 1) / 2))) { 971 exit(0); 972 } 973 } |
974 if (as_path) 975 as_shutdown(asn); |
|
951 952 exit(0); 953} 954 955int 956wait_for_reply(sock, mhdr) 957 int sock; 958 struct msghdr *mhdr; --- 397 unchanged lines hidden (view full) --- 1356 int cc; 1357{ 1358 struct sockaddr_in6 *from = (struct sockaddr_in6 *)mhdr->msg_name; 1359 char hbuf[NI_MAXHOST]; 1360 1361 if (getnameinfo((struct sockaddr *)from, from->sin6_len, 1362 hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) 1363 strlcpy(hbuf, "invalid", sizeof(hbuf)); | 976 977 exit(0); 978} 979 980int 981wait_for_reply(sock, mhdr) 982 int sock; 983 struct msghdr *mhdr; --- 397 unchanged lines hidden (view full) --- 1381 int cc; 1382{ 1383 struct sockaddr_in6 *from = (struct sockaddr_in6 *)mhdr->msg_name; 1384 char hbuf[NI_MAXHOST]; 1385 1386 if (getnameinfo((struct sockaddr *)from, from->sin6_len, 1387 hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) 1388 strlcpy(hbuf, "invalid", sizeof(hbuf)); |
1389 if (as_path) 1390 printf(" [AS%u]", as_lookup(asn, hbuf, AF_INET6)); |
|
1364 if (nflag) 1365 printf(" %s", hbuf); 1366 else if (lflag) 1367 printf(" %s (%s)", inetname((struct sockaddr *)from), hbuf); 1368 else 1369 printf(" %s", inetname((struct sockaddr *)from)); 1370 1371 if (verbose) { --- 61 unchanged lines hidden --- | 1391 if (nflag) 1392 printf(" %s", hbuf); 1393 else if (lflag) 1394 printf(" %s (%s)", inetname((struct sockaddr *)from), hbuf); 1395 else 1396 printf(" %s", inetname((struct sockaddr *)from)); 1397 1398 if (verbose) { --- 61 unchanged lines hidden --- |