1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
$NetBSD: patch-ab,v 1.5 2011/12/22 19:06:23 is Exp $
--- tcptraceroute.c.orig 2002-07-30 21:51:27.000000000 +0000
+++ tcptraceroute.c
@@ -209,7 +209,7 @@ Updates are available from http://michae
#define AF_LINK AF_INET /* BSD defines some AF_INET network interfaces as AF_LINK */
#endif
-#if defined (__OpenBSD__) || defined(__FreeBSD__) || defined(__bsdi__)
+#if defined (__OpenBSD__) || defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__)
#define HASSALEN /* Awful, awful hack to make subinterfaces work on BSD. */
#endif
@@ -306,7 +306,7 @@ struct datalinktype {
};
/* Various globals */
-u_long dst_ip, src_ip;
+in_addr_t dst_ip, src_ip;
u_short src_prt, dst_prt;
char *device, *name, *dst, *src;
char dst_name[TEXTSIZE], dst_prt_name[TEXTSIZE], filter[TEXTSIZE];
@@ -322,7 +322,7 @@ int o_minttl, o_maxttl, o_timeout, o_deb
/* interface linked list, built later by getinterfaces() */
struct interface_entry {
char *name;
- u_long addr;
+ in_addr_t addr;
struct interface_entry *next;
} *interfaces;
@@ -332,7 +332,7 @@ typedef struct {
u_short id, src_prt;
struct timeval timestamp;
double delta;
- u_long addr;
+ in_addr_t addr;
char *state;
char *string;
} proberecord;
@@ -340,7 +340,6 @@ typedef struct {
extern char *optarg;
extern int optind, opterr, optopt;
extern char pcap_version[];
-extern int errno;
/*
* fatal() and pfatal() are useful stdarg functions from
@@ -391,10 +390,10 @@ void pfatal(char *err)
void usage(void)
{
printf("\n%s\n%s\n", VERSION, BANNER);
- fatal("Usage: %s [-nNFSAE] [-i <interface>] [-f <first ttl>]
- [-l <packet length>] [-q <number of queries>] [-t <tos>]
- [-m <max ttl>] [-pP] <source port>] [-s <source address>]
- [-w <wait time>] <host> [destination port] [packet length]\n\n", name);
+ fatal("Usage: %s [-nNFSAE] [-i <interface>] [-f <first ttl>]\n"
+" [-l <packet length>] [-q <number of queries>] [-t <tos>]\n"
+" [-m <max ttl>] [-pP] <source port>] [-s <source address>]\n"
+" [-w <wait time>] <host> [destination port] [packet length]\n\n", name);
}
void about(void)
@@ -563,7 +562,7 @@ int tvsign(struct timeval *tv)
*/
#define IPTOSBUFFERS 12
-char *iptos(u_long in)
+char *iptos(in_addr_t in)
{
static char output[IPTOSBUFFERS][3*4+3+1];
static short which;
@@ -580,7 +579,7 @@ char *iptos(u_long in)
* RFC1918 space.
*/
-char *iptohost(u_long in)
+char *iptohost(in_addr_t in)
{
u_char *p = (u_char *)∈
@@ -635,7 +634,7 @@ void getinterfaces(void)
struct ifconf ifc;
struct ifreq *ifrp, ifr;
int numreqs, i, s;
- u_long addr;
+ in_addr_t addr;
int salen;
char *x;
@@ -724,8 +723,7 @@ void getinterfaces(void)
}
#endif
- if (ifrp->ifr_addr.sa_family != AF_INET &&
- ifrp->ifr_addr.sa_family != AF_LINK)
+ if (ifrp->ifr_addr.sa_family != AF_INET)
{
debug("Ignoring non-AF_INET address on interface %s\n",
sprintable(ifr.ifr_name));
@@ -772,7 +770,7 @@ void getinterfaces(void)
* given destination address.
*/
-u_long findsrc(u_long dest)
+in_addr_t findsrc(in_addr_t dest)
{
struct sockaddr_in sinsrc, sindest;
int s, size;
@@ -808,7 +806,7 @@ u_long findsrc(u_long dest)
* interface exists with an address of 127.0.0.1.
*/
-char *finddev(u_long with_src)
+char *finddev(in_addr_t with_src)
{
struct interface_entry *p;
char *device = NULL;
@@ -905,7 +903,7 @@ void showprobe(proberecord *record)
/* Variables to keep state between calls */
static char laststate[TEXTSIZE];
static int lastttl;
- static u_long lastaddr;
+ static in_addr_t lastaddr;
static int everprint;
int printflag = 0;
@@ -1053,7 +1051,7 @@ void debugoptions(void)
void defaults(void)
{
struct servent *serv;
- u_long recommended_src;
+ in_addr_t recommended_src;
getinterfaces();
@@ -1182,9 +1180,9 @@ void initcapture(void)
if (! (pcap = pcap_open_live(device, offset + SNAPLEN, 0, 10, errbuf)))
fatal("pcap_open_live failed: %s", errbuf);
- safe_snprintf(filter, TEXTSIZE, "
- (tcp and src host %s and src port %d and dst host %s)
- or ((icmp[0] == 11 or icmp[0] == 3) and dst host %s)",
+ safe_snprintf(filter, TEXTSIZE,
+ "(tcp and src host %s and src port %d and dst host %s)"
+ " or ((icmp[0] == 11 or icmp[0] == 3) and dst host %s)",
iptos(dst_ip), dst_prt, iptos(src_ip), iptos(src_ip));
if (o_nofilter)
@@ -1783,9 +1781,14 @@ int main(int argc, char **argv)
o_dontfrag = 0;
o_timeout = 3;
o_nofilter = 0;
- o_noselect = 0;
o_nogetinterfaces = 0;
+#if defined(__NetBSD__)
+ o_noselect = 1;
+#else
+ o_noselect = 0;
+#endif
+
#if defined (__SVR4) && defined (__sun)
o_trackport = 1; /* --track-port should be the default for Solaris */
#else
@@ -2003,6 +2006,6 @@ int main(int argc, char **argv)
defaults();
initcapture();
- seteuid(getuid());
+ setuid(getuid());
return trace();
}
|