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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
$NetBSD: patch-de,v 1.1 2006/03/19 22:03:29 joerg Exp $
--- agent/mibgroup/mibII/ipv6.c.orig 2005-11-16 19:44:51.000000000 +0000
+++ agent/mibgroup/mibII/ipv6.c
@@ -11,7 +11,7 @@
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
# if HAVE_SYS_SOCKETVAR_H
# include <sys/socketvar.h>
# endif
@@ -80,7 +80,7 @@
# include <netinet6/ip6_var.h>
#endif
#include <net/route.h>
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
# if HAVE_NETINET_IN_PCB_H
# include <netinet/in_pcb.h>
# endif
@@ -575,7 +575,7 @@ if_getifnet(int idx, struct ifnet *resul
memcpy(result, &tmp, sizeof(tmp));
return 0;
}
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
q = (caddr_t) TAILQ_NEXT(&tmp, if_link);
#else
# if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -806,7 +806,7 @@ var_ifv6Entry(register struct variable *
if (if_getifnet(interface, &ifnet) < 0)
break;
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
ifa = (caddr_t) TAILQ_FIRST(&ifnet.if_addrhead);
#else
# if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -827,7 +827,7 @@ var_ifv6Entry(register struct variable *
*var_len = sdl.sdl_alen;
return (u_char *) (sdl.sdl_data + sdl.sdl_nlen);
}
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
ifa = (caddr_t) TAILQ_NEXT(&ifaddr, ifa_link);
#else
# if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -1230,7 +1230,11 @@ var_udp6(register struct variable * vp,
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
struct inpcbtable udbtable;
caddr_t first;
-#elif (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#elif defined(dragonfly)
+ char *sysctl_buf;
+ struct xinpcb *xig;
+ size_t sysctl_len;
+#elif defined(freebsd3) || defined(darwin)
char *sysctl_buf;
struct xinpgen *xig, *oxig;
#else
@@ -1245,10 +1249,31 @@ var_udp6(register struct variable * vp,
if (!auto_nlist("udbtable", (char *) &udbtable, sizeof(udbtable)))
return NULL;
first = p = (caddr_t)udbtable.inpt_queue.cqh_first;
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
if (!auto_nlist("udb6", (char *) &udb6, sizeof(udb6)))
return NULL;
p = (caddr_t) udb6.in6p_next;
+#elif defined(dragonfly)
+ {
+ const char *udblist = "net.inet.udp.pcblist";
+ const char *pp = udblist;
+
+ if (sysctlbyname(udblist, 0, &sysctl_len, 0, 0) < 0)
+ return NULL;
+ if ((sysctl_buf = malloc(sysctl_len)) == NULL)
+ return NULL;
+ udblist = pp;
+ if (sysctlbyname(udblist, sysctl_buf, &sysctl_len, 0, 0) < 0) {
+ free(sysctl_buf);
+ return NULL;
+ }
+ xig = (struct xinpcb *) sysctl_buf;
+ if (xig->xi_len != sizeof(*xig)) {
+ free(sysctl_buf);
+ return NULL;
+ }
+ p = (caddr_t) ((char *) xig); /* silence compiler warning */
+ }
#else
{
const char *udblist = "net.inet.udp.pcblist";
@@ -1276,15 +1301,17 @@ var_udp6(register struct variable * vp,
while (
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
p && p != first
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
p && (u_long) p != auto_nlist_value("udb6")
+#elif defined(dragonfly)
+ (char *)xig + xig->xi_len <= sysctl_buf + sysctl_len
#else
xig->xig_len > sizeof(struct xinpgen)
#endif
) {
DEBUGMSGTL(("mibII/ipv6", "looping: p=%x\n", p));
-#if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#if !defined(freebsd3) && !defined(darwin)
if (klookup((u_long) p, (char *) &in6pcb, sizeof(in6pcb)) < 0) {
DEBUGMSGTL(("mibII/ipv6", "klookup fail for udb6 at %x\n",
p));
@@ -1297,7 +1324,7 @@ var_udp6(register struct variable * vp,
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
if (in6pcb.in6p_af != AF_INET6)
goto skip;
-#elif (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#elif defined(freebsd3) || defined(darwin)
if (0 == (in6pcb.inp_vflag & INP_IPV6))
goto skip;
#endif
@@ -1340,13 +1367,15 @@ var_udp6(register struct variable * vp,
skip:
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
p = (caddr_t)in6pcb.in6p_queue.cqe_next;
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
p = (caddr_t) in6pcb.in6p_next;
+#elif defined(__DragonFly__)
+ xig = (struct xinpcb *) ((char *) xig + xig->xi_len);
#else
xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
#endif
}
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
free(sysctl_buf);
#endif
DEBUGMSGTL(("mibII/ipv6", "found=%d\n", found));
@@ -1405,7 +1434,7 @@ var_tcp6(register struct variable * vp,
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
struct inpcbtable tcbtable;
caddr_t first;
-#elif (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#elif defined(freebsd3) || defined(darwin)
char *sysctl_buf;
struct xinpgen *xig, *oxig;
#else
@@ -1435,7 +1464,7 @@ var_tcp6(register struct variable * vp,
if (!auto_nlist("tcbtable", (char *) &tcbtable, sizeof(tcbtable)))
return NULL;
first = p = (caddr_t)tcbtable.inpt_queue.cqh_first;
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
if (!auto_nlist("tcb6", (char *) &tcb6, sizeof(tcb6)))
return NULL;
p = (caddr_t) tcb6.in6p_next;
@@ -1466,7 +1495,7 @@ var_tcp6(register struct variable * vp,
while (
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
p && p != first
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
p && (u_long) p != auto_nlist_value("tcb6")
#else
xig->xig_len > sizeof(struct xinpgen)
@@ -1474,7 +1503,7 @@ var_tcp6(register struct variable * vp,
) {
DEBUGMSGTL(("mibII/ipv6", "looping: p=%x\n", p));
-#if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#if !defined(freebsd3) && !defined(darwin)
if (klookup((u_long) p, (char *) &in6pcb, sizeof(in6pcb)) < 0) {
DEBUGMSGTL(("mibII/ipv6", "klookup fail for tcb6 at %x\n",
p));
@@ -1487,7 +1516,7 @@ var_tcp6(register struct variable * vp,
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
if (in6pcb.in6p_af != AF_INET6)
goto skip;
-#elif (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#elif defined(freebsd3) || defined(darwin)
if (0 == (in6pcb.inp_vflag & INP_IPV6))
goto skip;
#endif
@@ -1546,13 +1575,13 @@ var_tcp6(register struct variable * vp,
skip:
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
p = (caddr_t)in6pcb.in6p_queue.cqe_next;
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
p = (caddr_t) in6pcb.in6p_next;
#else
xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
#endif
}
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
free(sysctl_buf);
#endif
DEBUGMSGTL(("mibII/ipv6", "found=%d\n", found));
@@ -1644,7 +1673,11 @@ var_tcp6(register struct variable * vp,
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
struct inpcbtable tcbtable;
caddr_t first;
-#elif (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#elif defined(dragonfly)
+ char *sysctl_buf;
+ size_t sysctl_len;
+ struct xtcpcb *xtp;
+#elif defined(freebsd3) || defined(darwin)
char *sysctl_buf;
struct xinpgen *xig, *oxig;
#else
@@ -1659,10 +1692,31 @@ var_tcp6(register struct variable * vp,
if (!auto_nlist("tcbtable", (char *) &tcbtable, sizeof(tcbtable)))
return NULL;
first = p = (caddr_t)tcbtable.inpt_queue.cqh_first;
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
if (!auto_nlist("tcb6", (char *) &tcb6, sizeof(tcb6)))
return NULL;
p = (caddr_t) tcb6.in6p_next;
+#elif defined(dragonfly)
+ {
+ const char *tcblist = "net.inet.tcp.pcblist";
+ const char *pp = tcblist;
+
+ if (sysctlbyname(tcblist, 0, &sysctl_len, 0, 0) < 0)
+ return NULL;
+ if ((sysctl_buf = malloc(sysctl_len)) == NULL)
+ return NULL;
+ tcblist = pp;
+ if (sysctlbyname(tcblist, sysctl_buf, &sysctl_len, 0, 0) < 0) {
+ free(sysctl_buf);
+ return NULL;
+ }
+ xtp = (struct xtcpcb *) sysctl_buf;
+ if (xtp->xt_len != sizeof(*xtp)) {
+ free(sysctl_buf);
+ return NULL;
+ }
+ p = (caddr_t) ((char *) xtp); /* silence compiler warning */
+ }
#else
{
const char *tcblist = "net.inet.tcp.pcblist";
@@ -1679,7 +1733,8 @@ var_tcp6(register struct variable * vp,
return NULL;
}
oxig = (struct xinpgen *) sysctl_buf;
- xig = (struct xinpgen *) ((char *) oxig + oxig->xig_len);
+ xig = (struct xinpgen *) ((char *) oxtp + oxtp->xt_len);
+ if (oxig
p = (caddr_t) ((char *) xig); /* silence compiler warning */
}
#endif
@@ -1690,28 +1745,32 @@ var_tcp6(register struct variable * vp,
while (
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
p && p != first
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
p && (u_long) p != auto_nlist_value("tcb6")
+#elif defined(dragonfly)
+ (char *)xtp + xtp->xt_len < sysctl_buf + sysctl_len
#else
xig->xig_len > sizeof(struct xinpgen)
#endif
) {
DEBUGMSGTL(("mibII/ipv6", "looping: p=%x\n", p));
-#if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#if !defined(freebsd3) && !defined(darwin)
if (klookup((u_long) p, (char *) &in6pcb, sizeof(in6pcb)) < 0) {
DEBUGMSGTL(("mibII/ipv6", "klookup fail for tcb6 at %x\n",
p));
found = 0;
break;
}
+#elif defined(dragonfly)
+ in6pcb = xtp->xt_inp;
#else
in6pcb = ((struct xinpcb *) xig)->xi_inp;
#endif
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
if (in6pcb.in6p_af != AF_INET6)
goto skip;
-#elif (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#elif defined(freebsd3) || defined(darwin)
if (0 == (in6pcb.inp_vflag & INP_IPV6))
goto skip;
#endif
@@ -1769,13 +1828,15 @@ var_tcp6(register struct variable * vp,
skip:
#if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 /*1.6Y*/
p = (caddr_t)in6pcb.in6p_queue.cqe_next;
-#elif !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(darwin)
+#elif !defined(freebsd3) && !defined(darwin)
p = (caddr_t) in6pcb.in6p_next;
+#elif defined(dragonfly)
+ xtp = (struct xtcpcb *) ((char *)xtp + xtp->xt_len);
#else
xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
#endif
}
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(darwin)
+#if defined(freebsd3) || defined(darwin)
free(sysctl_buf);
#endif
DEBUGMSGTL(("mibII/ipv6", "found=%d\n", found));
|