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
|
--- mtr-0.69.orig/mtr.c
+++ mtr-0.69/mtr.c
@@ -388,10 +388,6 @@
}
- if (net_set_interfaceaddress (InterfaceAddress) != 0) {
- fprintf (stderr, "mtr: Couldn't set interface addres.\n");
- exit (1);
- }
#ifdef ENABLE_IPV6
/* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */
@@ -442,6 +438,11 @@
exit(1);
}
+ if (net_set_interfaceaddress (InterfaceAddress) != 0) {
+ fprintf (stderr, "mtr: Couldn't set interface address.\n");
+ exit (1);
+ }
+
display_open();
dns_open();
--- mtr-0.69.orig/net.c
+++ mtr-0.69/net.c
@@ -322,7 +322,15 @@
int oldavg; /* usedByMin */
int oldjavg; /* usedByMin */
int i; /* usedByMin */
+#ifdef ENABLE_IPV6
+ char addrcopy[sizeof(struct in6_addr)];
+#else
+ char addrcopy[sizeof(struct in_addr)];
+#endif
+ /* Copy the from address ASAP because it can be overwritten */
+ addrcpy( (void *) &addrcopy, addr, af );
+
if (seq < 0 || seq >= MaxSequence)
return;
@@ -339,22 +347,22 @@
if ( addrcmp( (void *) &(host[index].addr),
(void *) &unspec_addr, af ) == 0 ) {
// should be out of if as addr can change
- addrcpy( (void *) &(host[index].addr), addr, af );
+ addrcpy( (void *) &(host[index].addr), addrcopy, af );
display_rawhost(index, (void *) &(host[index].addr));
/* multi paths by Min */
- addrcpy( (void *) &(host[index].addrs[0]), addr, af );
+ addrcpy( (void *) &(host[index].addrs[0]), addrcopy, af );
} else {
for( i=0; i<MAXPATH; ) {
- if( addrcmp( (void *) &(host[index].addrs[i]), (void *) &addr,
+ if( addrcmp( (void *) &(host[index].addrs[i]), (void *) &addrcopy,
af ) == 0 ||
addrcmp( (void *) &(host[index].addrs[i]),
(void *) &unspec_addr, af ) == 0 ) break;
i++;
}
- if( addrcmp( (void *) &(host[index].addrs[i]), addr, af ) != 0 &&
+ if( addrcmp( (void *) &(host[index].addrs[i]), addrcopy, af ) != 0 &&
i<MAXPATH ) {
- addrcpy( (void *) &(host[index].addrs[i]), addr, af );
+ addrcpy( (void *) &(host[index].addrs[i]), addrcopy, af );
}
/* end multi paths */
}
@@ -911,8 +919,10 @@
void net_close(void)
{
- close(sendsock);
- close(recvsock);
+ if (sendsock4 >= 0) close(sendsock4);
+ if (recvsock4 >= 0) close(recvsock4);
+ if (sendsock6 >= 0) close(sendsock6);
+ if (recvsock6 >= 0) close(recvsock6);
}
--- mtr-0.69.orig/net.h
+++ mtr-0.69/net.h
@@ -117,3 +117,6 @@
extern char available_options[];
ip_t unspec_addr;
+
+FILE *ADDRCMP;
+int i;
|