traceroute.c (171135) | traceroute.c (176428) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 14 unchanged lines hidden (view full) --- 23static const char copyright[] = 24 "@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000\n\ 25The Regents of the University of California. All rights reserved.\n"; 26#if 0 27static const char rcsid[] = 28 "@(#)$Id: traceroute.c,v 1.68 2000/12/14 08:04:33 leres Exp $ (LBL)"; 29#endif 30static const char rcsid[] = | 1/* 2 * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 14 unchanged lines hidden (view full) --- 23static const char copyright[] = 24 "@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000\n\ 25The Regents of the University of California. All rights reserved.\n"; 26#if 0 27static const char rcsid[] = 28 "@(#)$Id: traceroute.c,v 1.68 2000/12/14 08:04:33 leres Exp $ (LBL)"; 29#endif 30static const char rcsid[] = |
31 "$FreeBSD: head/contrib/traceroute/traceroute.c 171135 2007-07-01 12:08:08Z gnn $"; | 31 "$FreeBSD: head/contrib/traceroute/traceroute.c 176428 2008-02-20 23:29:53Z rpaulo $"; |
32#endif 33 34/* 35 * traceroute host - trace the route ip packets follow going to "host". 36 * 37 * Attempt to trace the route an ip packet would follow to some 38 * internet host. We find out intermediate hops by launching probe 39 * packets with a small ttl (time to live) then listening for an --- 218 unchanged lines hidden (view full) --- 258#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */ 259#endif 260#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF 261#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ 262#endif 263 264#include "findsaddr.h" 265#include "ifaddrlist.h" | 32#endif 33 34/* 35 * traceroute host - trace the route ip packets follow going to "host". 36 * 37 * Attempt to trace the route an ip packet would follow to some 38 * internet host. We find out intermediate hops by launching probe 39 * packets with a small ttl (time to live) then listening for an --- 218 unchanged lines hidden (view full) --- 258#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */ 259#endif 260#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF 261#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ 262#endif 263 264#include "findsaddr.h" 265#include "ifaddrlist.h" |
266#include "as.h" |
|
266#include "traceroute.h" 267 268/* Maximum number of gateways (include room for one noop) */ 269#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t))) 270 271#ifndef MAXHOSTNAMELEN 272#define MAXHOSTNAMELEN 64 273#endif --- 71 unchanged lines hidden (view full) --- 345int first_ttl = 1; 346u_short ident; 347u_short port; /* protocol specific base "port" */ 348 349int options; /* socket options */ 350int verbose; 351int waittime = 5; /* time to wait for response (in seconds) */ 352int nflag; /* print addresses numerically */ | 267#include "traceroute.h" 268 269/* Maximum number of gateways (include room for one noop) */ 270#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t))) 271 272#ifndef MAXHOSTNAMELEN 273#define MAXHOSTNAMELEN 64 274#endif --- 71 unchanged lines hidden (view full) --- 346int first_ttl = 1; 347u_short ident; 348u_short port; /* protocol specific base "port" */ 349 350int options; /* socket options */ 351int verbose; 352int waittime = 5; /* time to wait for response (in seconds) */ 353int nflag; /* print addresses numerically */ |
354int as_path; /* print as numbers for each hop */ 355char *as_server = NULL; 356void *asn; |
|
353#ifdef CANT_HACK_IPCKSUM 354int doipcksum = 0; /* don't calculate ip checksums by default */ 355#else 356int doipcksum = 1; /* calculate ip checksums by default */ 357#endif 358int optlen; /* length of ip options */ 359int fixedPort = 0; /* Use fixed destination port for TCP and UDP */ 360int printdiff = 0; /* Print the difference between sent and quoted */ --- 169 unchanged lines hidden (view full) --- 530 if (argv[0] == NULL) 531 prog = "traceroute"; 532 else if ((cp = strrchr(argv[0], '/')) != NULL) 533 prog = cp + 1; 534 else 535 prog = argv[0]; 536 537 opterr = 0; | 357#ifdef CANT_HACK_IPCKSUM 358int doipcksum = 0; /* don't calculate ip checksums by default */ 359#else 360int doipcksum = 1; /* calculate ip checksums by default */ 361#endif 362int optlen; /* length of ip options */ 363int fixedPort = 0; /* Use fixed destination port for TCP and UDP */ 364int printdiff = 0; /* Print the difference between sent and quoted */ --- 169 unchanged lines hidden (view full) --- 534 if (argv[0] == NULL) 535 prog = "traceroute"; 536 else if ((cp = strrchr(argv[0], '/')) != NULL) 537 prog = cp + 1; 538 else 539 prog = argv[0]; 540 541 opterr = 0; |
538 while ((op = getopt(argc, argv, "edDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF) | 542 while ((op = getopt(argc, argv, "aA:edDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF) |
539 switch (op) { | 543 switch (op) { |
540 | 544 case 'a': 545 as_path = 1; 546 break; 547 548 case 'A': 549 as_path = 1; 550 as_server = optarg; 551 break; 552 |
541 case 'd': 542 options |= SO_DEBUG; 543 break; 544 545 case 'D': 546 printdiff = 1; 547 break; 548 --- 359 unchanged lines hidden (view full) --- 908 909 /* Check the source address (-s), if any, is valid */ 910 if (bind(sndsock, (struct sockaddr *)from, sizeof(*from)) < 0) { 911 Fprintf(stderr, "%s: bind: %s\n", 912 prog, strerror(errno)); 913 exit (1); 914 } 915 | 553 case 'd': 554 options |= SO_DEBUG; 555 break; 556 557 case 'D': 558 printdiff = 1; 559 break; 560 --- 359 unchanged lines hidden (view full) --- 920 921 /* Check the source address (-s), if any, is valid */ 922 if (bind(sndsock, (struct sockaddr *)from, sizeof(*from)) < 0) { 923 Fprintf(stderr, "%s: bind: %s\n", 924 prog, strerror(errno)); 925 exit (1); 926 } 927 |
928 if (as_path) { 929 asn = as_setup(as_server); 930 if (asn == NULL) { 931 Fprintf(stderr, "%s: as_setup failed, AS# lookups" 932 " disabled\n", prog); 933 (void)fflush(stderr); 934 as_path = 0; 935 } 936 } 937 |
|
916#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) 917 if (setpolicy(sndsock, "in bypass") < 0) 918 errx(1, "%s", ipsec_strerror()); 919 920 if (setpolicy(sndsock, "out bypass") < 0) 921 errx(1, "%s", ipsec_strerror()); 922#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */ 923 --- 189 unchanged lines hidden (view full) --- 1113 if (sump) { 1114 Printf(" (%d%% loss)", (loss * 100) / nprobes); 1115 } 1116 putchar('\n'); 1117 if (got_there || 1118 (unreachable > 0 && unreachable >= nprobes - 1)) 1119 break; 1120 } | 938#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) 939 if (setpolicy(sndsock, "in bypass") < 0) 940 errx(1, "%s", ipsec_strerror()); 941 942 if (setpolicy(sndsock, "out bypass") < 0) 943 errx(1, "%s", ipsec_strerror()); 944#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */ 945 --- 189 unchanged lines hidden (view full) --- 1135 if (sump) { 1136 Printf(" (%d%% loss)", (loss * 100) / nprobes); 1137 } 1138 putchar('\n'); 1139 if (got_there || 1140 (unreachable > 0 && unreachable >= nprobes - 1)) 1141 break; 1142 } |
1143 if (as_path) 1144 as_shutdown(asn); |
|
1121 exit(0); 1122} 1123 1124int 1125wait_for_reply(register int sock, register struct sockaddr_in *fromp, 1126 register const struct timeval *tp) 1127{ 1128 fd_set *fdsp; --- 324 unchanged lines hidden (view full) --- 1453{ 1454 register struct ip *ip; 1455 register int hlen; 1456 1457 ip = (struct ip *) buf; 1458 hlen = ip->ip_hl << 2; 1459 cc -= hlen; 1460 | 1145 exit(0); 1146} 1147 1148int 1149wait_for_reply(register int sock, register struct sockaddr_in *fromp, 1150 register const struct timeval *tp) 1151{ 1152 fd_set *fdsp; --- 324 unchanged lines hidden (view full) --- 1477{ 1478 register struct ip *ip; 1479 register int hlen; 1480 1481 ip = (struct ip *) buf; 1482 hlen = ip->ip_hl << 2; 1483 cc -= hlen; 1484 |
1485 if (as_path) 1486 Printf(" [AS%d]", as_lookup(asn, &from->sin_addr)); 1487 |
|
1461 if (nflag) 1462 Printf(" %s", inet_ntoa(from->sin_addr)); 1463 else 1464 Printf(" %s (%s)", inetname(from->sin_addr), 1465 inet_ntoa(from->sin_addr)); 1466 1467 if (verbose) 1468 Printf(" %d bytes to %s", cc, inet_ntoa (ip->ip_dst)); --- 290 unchanged lines hidden (view full) --- 1759 1760void 1761usage(void) 1762{ 1763 extern char version[]; 1764 1765 Fprintf(stderr, "Version %s\n", version); 1766 Fprintf(stderr, | 1488 if (nflag) 1489 Printf(" %s", inet_ntoa(from->sin_addr)); 1490 else 1491 Printf(" %s (%s)", inetname(from->sin_addr), 1492 inet_ntoa(from->sin_addr)); 1493 1494 if (verbose) 1495 Printf(" %d bytes to %s", cc, inet_ntoa (ip->ip_dst)); --- 290 unchanged lines hidden (view full) --- 1786 1787void 1788usage(void) 1789{ 1790 extern char version[]; 1791 1792 Fprintf(stderr, "Version %s\n", version); 1793 Fprintf(stderr, |
1767 "Usage: %s [-dDeFInrSvx] [-f first_ttl] [-g gateway] [-i iface]\n" | 1794 "Usage: %s [-adDeFInrSvx] [-f first_ttl] [-g gateway] [-i iface]\n" |
1768 "\t[-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr]\n" | 1795 "\t[-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr]\n" |
1769 "\t[-t tos] [-w waittime] [-z pausemsecs] host [packetlen]\n", prog); | 1796 "\t[-t tos] [-w waittime] [-A as_server] [-z pausemsecs] host [packetlen]\n", prog); |
1770 exit(1); 1771} | 1797 exit(1); 1798} |