diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-08-22 19:35:36 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-08-22 19:35:36 +0000 |
commit | 1ed9dd9d062e27807745c11736b0c6401677c12e (patch) | |
tree | 658508cc9a3d78deeac6509250733097b5efaa55 | |
parent | 4534af276360675b6058e3b255a0d63f7f8c0c96 (diff) | |
download | busybox-w32-1ed9dd9d062e27807745c11736b0c6401677c12e.tar.gz busybox-w32-1ed9dd9d062e27807745c11736b0c6401677c12e.tar.bz2 busybox-w32-1ed9dd9d062e27807745c11736b0c6401677c12e.zip |
Remove duplicate definitions, run through indent
-rw-r--r-- | libbb/interface.c | 2571 |
1 files changed, 1279 insertions, 1292 deletions
diff --git a/libbb/interface.c b/libbb/interface.c index 5800e0f6a..04abda39d 100644 --- a/libbb/interface.c +++ b/libbb/interface.c | |||
@@ -15,7 +15,7 @@ | |||
15 | * that either displays or sets the characteristics of | 15 | * that either displays or sets the characteristics of |
16 | * one or more of the system's networking interfaces. | 16 | * one or more of the system's networking interfaces. |
17 | * | 17 | * |
18 | * Version: $Id: interface.c,v 1.8 2002/07/03 11:46:36 andersen Exp $ | 18 | * Version: $Id: interface.c,v 1.9 2002/08/22 19:35:36 bug1 Exp $ |
19 | * | 19 | * |
20 | * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> | 20 | * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
21 | * and others. Copyright 1993 MicroWalt Corporation | 21 | * and others. Copyright 1993 MicroWalt Corporation |
@@ -103,14 +103,14 @@ static int procnetdev_vsn = 1; | |||
103 | */ | 103 | */ |
104 | 104 | ||
105 | struct in6_ifreq { | 105 | struct in6_ifreq { |
106 | struct in6_addr ifr6_addr; | 106 | struct in6_addr ifr6_addr; |
107 | __u32 ifr6_prefixlen; | 107 | __u32 ifr6_prefixlen; |
108 | unsigned int ifr6_ifindex; | 108 | unsigned int ifr6_ifindex; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | #endif /* HAVE_AFINET6 */ | 113 | #endif /* HAVE_AFINET6 */ |
114 | 114 | ||
115 | #if HAVE_AFIPX | 115 | #if HAVE_AFIPX |
116 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | 116 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
@@ -136,34 +136,33 @@ struct in6_ifreq { | |||
136 | #endif | 136 | #endif |
137 | 137 | ||
138 | #ifndef IFF_DYNAMIC | 138 | #ifndef IFF_DYNAMIC |
139 | #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */ | 139 | #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */ |
140 | #endif | 140 | #endif |
141 | 141 | ||
142 | /* This structure defines protocol families and their handlers. */ | 142 | /* This structure defines protocol families and their handlers. */ |
143 | struct aftype { | 143 | struct aftype { |
144 | const char *name; | 144 | const char *name; |
145 | const char *title; | 145 | const char *title; |
146 | int af; | 146 | int af; |
147 | int alen; | 147 | int alen; |
148 | char *(*print) (unsigned char *); | 148 | char *(*print) (unsigned char *); |
149 | char *(*sprint) (struct sockaddr *, int numeric); | 149 | char *(*sprint) (struct sockaddr *, int numeric); |
150 | int (*input) (int type, char *bufp, struct sockaddr *); | 150 | int (*input) (int type, char *bufp, struct sockaddr *); |
151 | void (*herror) (char *text); | 151 | void (*herror) (char *text); |
152 | int (*rprint) (int options); | 152 | int (*rprint) (int options); |
153 | int (*rinput) (int typ, int ext, char **argv); | 153 | int (*rinput) (int typ, int ext, char **argv); |
154 | 154 | ||
155 | /* may modify src */ | 155 | /* may modify src */ |
156 | int (*getmask) (char *src, struct sockaddr * mask, char *name); | 156 | int (*getmask) (char *src, struct sockaddr * mask, char *name); |
157 | 157 | ||
158 | int fd; | 158 | int fd; |
159 | char *flag_file; | 159 | char *flag_file; |
160 | }; | 160 | }; |
161 | 161 | ||
162 | static struct aftype *aftypes[]; | ||
163 | |||
164 | #ifdef KEEP_UNUSED | 162 | #ifdef KEEP_UNUSED |
165 | 163 | ||
166 | static int flag_unx; | 164 | static int flag_unx; |
165 | |||
167 | #ifdef HAVE_AFIPX | 166 | #ifdef HAVE_AFIPX |
168 | static int flag_ipx; | 167 | static int flag_ipx; |
169 | #endif | 168 | #endif |
@@ -177,6 +176,7 @@ static int flag_ddp; | |||
177 | static int flag_netrom; | 176 | static int flag_netrom; |
178 | #endif | 177 | #endif |
179 | static int flag_inet; | 178 | static int flag_inet; |
179 | |||
180 | #ifdef HAVE_AFINET6 | 180 | #ifdef HAVE_AFINET6 |
181 | static int flag_inet6; | 181 | static int flag_inet6; |
182 | #endif | 182 | #endif |
@@ -192,386 +192,366 @@ static int flag_ash; | |||
192 | 192 | ||
193 | 193 | ||
194 | static struct aftrans_t { | 194 | static struct aftrans_t { |
195 | char *alias; | 195 | char *alias; |
196 | char *name; | 196 | char *name; |
197 | int *flag; | 197 | int *flag; |
198 | } aftrans[] = { | 198 | } aftrans[] = { |
199 | 199 | ||
200 | #ifdef HAVE_AFX25 | 200 | #ifdef HAVE_AFX25 |
201 | { | 201 | { |
202 | "ax25", "ax25", &flag_ax25 | 202 | "ax25", "ax25", &flag_ax25}, |
203 | }, | ||
204 | #endif | 203 | #endif |
205 | { | 204 | { |
206 | "ip", "inet", &flag_inet | 205 | "ip", "inet", &flag_inet}, |
207 | }, | ||
208 | #ifdef HAVE_AFINET6 | 206 | #ifdef HAVE_AFINET6 |
209 | { | 207 | { |
210 | "ip6", "inet6", &flag_inet6 | 208 | "ip6", "inet6", &flag_inet6}, |
211 | }, | ||
212 | #endif | 209 | #endif |
213 | #ifdef HAVE_AFIPX | 210 | #ifdef HAVE_AFIPX |
214 | { | 211 | { |
215 | "ipx", "ipx", &flag_ipx | 212 | "ipx", "ipx", &flag_ipx}, |
216 | }, | ||
217 | #endif | 213 | #endif |
218 | #ifdef HAVE_AFATALK | 214 | #ifdef HAVE_AFATALK |
219 | { | 215 | { |
220 | "appletalk", "ddp", &flag_ddp | 216 | "appletalk", "ddp", &flag_ddp}, |
221 | }, | ||
222 | #endif | 217 | #endif |
223 | #ifdef HAVE_AFNETROM | 218 | #ifdef HAVE_AFNETROM |
224 | { | 219 | { |
225 | "netrom", "netrom", &flag_netrom | 220 | "netrom", "netrom", &flag_netrom}, |
226 | }, | ||
227 | #endif | 221 | #endif |
228 | { | 222 | { |
229 | "inet", "inet", &flag_inet | 223 | "inet", "inet", &flag_inet}, |
230 | }, | ||
231 | #ifdef HAVE_AFINET6 | 224 | #ifdef HAVE_AFINET6 |
232 | { | 225 | { |
233 | "inet6", "inet6", &flag_inet6 | 226 | "inet6", "inet6", &flag_inet6}, |
234 | }, | ||
235 | #endif | 227 | #endif |
236 | #ifdef HAVE_AFATALK | 228 | #ifdef HAVE_AFATALK |
237 | { | 229 | { |
238 | "ddp", "ddp", &flag_ddp | 230 | "ddp", "ddp", &flag_ddp}, |
239 | }, | 231 | #endif |
240 | #endif | 232 | { |
241 | { | 233 | "unix", "unix", &flag_unx}, { |
242 | "unix", "unix", &flag_unx | 234 | "tcpip", "inet", &flag_inet}, |
243 | }, | ||
244 | { | ||
245 | "tcpip", "inet", &flag_inet | ||
246 | }, | ||
247 | #ifdef HAVE_AFECONET | 235 | #ifdef HAVE_AFECONET |
248 | { | 236 | { |
249 | "econet", "ec", &flag_econet | 237 | "econet", "ec", &flag_econet}, |
250 | }, | ||
251 | #endif | 238 | #endif |
252 | #ifdef HAVE_AFX25 | 239 | #ifdef HAVE_AFX25 |
253 | { | 240 | { |
254 | "x25", "x25", &flag_x25 | 241 | "x25", "x25", &flag_x25}, |
255 | }, | ||
256 | #endif | 242 | #endif |
257 | #ifdef HAVE_AFASH | 243 | #ifdef HAVE_AFASH |
258 | { | 244 | { |
259 | "ash", "ash", &flag_ash | 245 | "ash", "ash", &flag_ash}, |
260 | }, | ||
261 | #endif | 246 | #endif |
262 | { | 247 | { |
263 | 0, 0, 0 | 248 | 0, 0, 0} |
264 | } | ||
265 | }; | 249 | }; |
266 | 250 | ||
267 | static char afname[256] = ""; | 251 | static char afname[256] = ""; |
268 | #endif /* KEEP_UNUSED */ | 252 | #endif /* KEEP_UNUSED */ |
269 | 253 | ||
270 | #if HAVE_AFUNIX | 254 | #if HAVE_AFUNIX |
271 | 255 | ||
272 | /* Display a UNIX domain address. */ | 256 | /* Display a UNIX domain address. */ |
273 | static char *UNIX_print(unsigned char *ptr) | 257 | static char *UNIX_print(unsigned char *ptr) |
274 | { | 258 | { |
275 | return (ptr); | 259 | return (ptr); |
276 | } | 260 | } |
277 | 261 | ||
278 | 262 | ||
279 | /* Display a UNIX domain address. */ | 263 | /* Display a UNIX domain address. */ |
280 | static char *UNIX_sprint(struct sockaddr *sap, int numeric) | 264 | static char *UNIX_sprint(struct sockaddr *sap, int numeric) |
281 | { | 265 | { |
282 | static char buf[64]; | 266 | static char buf[64]; |
283 | 267 | ||
284 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 268 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
285 | return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); | 269 | return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
286 | return (UNIX_print(sap->sa_data)); | 270 | return (UNIX_print(sap->sa_data)); |
287 | } | 271 | } |
288 | 272 | ||
289 | 273 | ||
290 | static struct aftype unix_aftype = | 274 | static struct aftype unix_aftype = { |
291 | { | 275 | "unix", "UNIX Domain", AF_UNIX, 0, |
292 | "unix", "UNIX Domain", AF_UNIX, 0, | 276 | UNIX_print, UNIX_sprint, NULL, NULL, |
293 | UNIX_print, UNIX_sprint, NULL, NULL, | 277 | NULL, NULL, NULL, |
294 | NULL, NULL, NULL, | 278 | -1, |
295 | -1, | 279 | "/proc/net/unix" |
296 | "/proc/net/unix" | ||
297 | }; | 280 | }; |
298 | #endif /* HAVE_AFUNIX */ | 281 | #endif /* HAVE_AFUNIX */ |
299 | 282 | ||
300 | #if HAVE_AFINET | 283 | #if HAVE_AFINET |
301 | 284 | ||
302 | #ifdef KEEP_UNUSED | 285 | #ifdef KEEP_UNUSED |
303 | static void INET_reserror(char *text) | 286 | static void INET_reserror(char *text) |
304 | { | 287 | { |
305 | herror(text); | 288 | herror(text); |
306 | } | 289 | } |
307 | 290 | ||
308 | /* Display an Internet socket address. */ | 291 | /* Display an Internet socket address. */ |
309 | static char *INET_print(unsigned char *ptr) | 292 | static char *INET_print(unsigned char *ptr) |
310 | { | 293 | { |
311 | return (inet_ntoa((*(struct in_addr *) ptr))); | 294 | return (inet_ntoa((*(struct in_addr *) ptr))); |
312 | } | 295 | } |
313 | #endif /* KEEP_UNUSED */ | 296 | #endif /* KEEP_UNUSED */ |
314 | 297 | ||
315 | /* Display an Internet socket address. */ | 298 | /* Display an Internet socket address. */ |
316 | static char *INET_sprint(struct sockaddr *sap, int numeric) | 299 | static char *INET_sprint(struct sockaddr *sap, int numeric) |
317 | { | 300 | { |
318 | static char buff[128]; | 301 | static char buff[128]; |
319 | 302 | ||
320 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 303 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
321 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); | 304 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
322 | 305 | ||
323 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, | 306 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, |
324 | numeric, 0xffffff00) != 0) | 307 | numeric, 0xffffff00) != 0) |
325 | return (NULL); | 308 | return (NULL); |
326 | 309 | ||
327 | return (buff); | 310 | return (buff); |
328 | } | 311 | } |
329 | 312 | ||
330 | #ifdef KEEP_UNUSED | 313 | #ifdef KEEP_UNUSED |
331 | static char *INET_sprintmask(struct sockaddr *sap, int numeric, | 314 | static char *INET_sprintmask(struct sockaddr *sap, int numeric, |
332 | unsigned int netmask) | 315 | unsigned int netmask) |
333 | { | 316 | { |
334 | static char buff[128]; | 317 | static char buff[128]; |
335 | 318 | ||
336 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 319 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
337 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); | 320 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
338 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, | 321 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, |
339 | numeric, netmask) != 0) | 322 | numeric, netmask) != 0) |
340 | return (NULL); | 323 | return (NULL); |
341 | return (buff); | 324 | return (buff); |
342 | } | 325 | } |
343 | 326 | ||
344 | static int INET_getsock(char *bufp, struct sockaddr *sap) | 327 | static int INET_getsock(char *bufp, struct sockaddr *sap) |
345 | { | 328 | { |
346 | char *sp = bufp, *bp; | 329 | char *sp = bufp, *bp; |
347 | unsigned int i; | 330 | unsigned int i; |
348 | unsigned val; | 331 | unsigned val; |
349 | struct sockaddr_in *sin; | 332 | struct sockaddr_in *sin; |
350 | |||
351 | sin = (struct sockaddr_in *) sap; | ||
352 | sin->sin_family = AF_INET; | ||
353 | sin->sin_port = 0; | ||
354 | |||
355 | val = 0; | ||
356 | bp = (char *) &val; | ||
357 | for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { | ||
358 | *sp = toupper(*sp); | ||
359 | |||
360 | if ((*sp >= 'A') && (*sp <= 'F')) | ||
361 | bp[i] |= (int) (*sp - 'A') + 10; | ||
362 | else if ((*sp >= '0') && (*sp <= '9')) | ||
363 | bp[i] |= (int) (*sp - '0'); | ||
364 | else | ||
365 | return (-1); | ||
366 | 333 | ||
367 | bp[i] <<= 4; | 334 | sin = (struct sockaddr_in *) sap; |
368 | sp++; | 335 | sin->sin_family = AF_INET; |
369 | *sp = toupper(*sp); | 336 | sin->sin_port = 0; |
370 | 337 | ||
371 | if ((*sp >= 'A') && (*sp <= 'F')) | 338 | val = 0; |
372 | bp[i] |= (int) (*sp - 'A') + 10; | 339 | bp = (char *) &val; |
373 | else if ((*sp >= '0') && (*sp <= '9')) | 340 | for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { |
374 | bp[i] |= (int) (*sp - '0'); | 341 | *sp = toupper(*sp); |
375 | else | 342 | |
376 | return (-1); | 343 | if ((*sp >= 'A') && (*sp <= 'F')) |
377 | 344 | bp[i] |= (int) (*sp - 'A') + 10; | |
378 | sp++; | 345 | else if ((*sp >= '0') && (*sp <= '9')) |
379 | } | 346 | bp[i] |= (int) (*sp - '0'); |
380 | sin->sin_addr.s_addr = htonl(val); | 347 | else |
348 | return (-1); | ||
349 | |||
350 | bp[i] <<= 4; | ||
351 | sp++; | ||
352 | *sp = toupper(*sp); | ||
353 | |||
354 | if ((*sp >= 'A') && (*sp <= 'F')) | ||
355 | bp[i] |= (int) (*sp - 'A') + 10; | ||
356 | else if ((*sp >= '0') && (*sp <= '9')) | ||
357 | bp[i] |= (int) (*sp - '0'); | ||
358 | else | ||
359 | return (-1); | ||
360 | |||
361 | sp++; | ||
362 | } | ||
363 | sin->sin_addr.s_addr = htonl(val); | ||
381 | 364 | ||
382 | return (sp - bufp); | 365 | return (sp - bufp); |
383 | } | 366 | } |
384 | 367 | ||
385 | static int INET_input(int type, char *bufp, struct sockaddr *sap) | 368 | static int INET_input(int type, char *bufp, struct sockaddr *sap) |
386 | { | 369 | { |
387 | switch (type) { | 370 | switch (type) { |
388 | case 1: | 371 | case 1: |
389 | return (INET_getsock(bufp, sap)); | 372 | return (INET_getsock(bufp, sap)); |
390 | case 256: | 373 | case 256: |
391 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1)); | 374 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1)); |
392 | default: | 375 | default: |
393 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0)); | 376 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0)); |
394 | } | 377 | } |
395 | } | 378 | } |
396 | 379 | ||
397 | static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) | 380 | static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) |
398 | { | 381 | { |
399 | struct sockaddr_in *mask = (struct sockaddr_in *) m; | 382 | struct sockaddr_in *mask = (struct sockaddr_in *) m; |
400 | char *slash, *end; | 383 | char *slash, *end; |
401 | int prefix; | 384 | int prefix; |
402 | 385 | ||
403 | if ((slash = strchr(adr, '/')) == NULL) | 386 | if ((slash = strchr(adr, '/')) == NULL) |
404 | return 0; | 387 | return 0; |
405 | 388 | ||
406 | *slash++ = '\0'; | 389 | *slash++ = '\0'; |
407 | prefix = strtoul(slash, &end, 0); | 390 | prefix = strtoul(slash, &end, 0); |
408 | if (*end != '\0') | 391 | if (*end != '\0') |
409 | return -1; | 392 | return -1; |
410 | 393 | ||
411 | if (name) { | 394 | if (name) { |
412 | sprintf(name, "/%d", prefix); | 395 | sprintf(name, "/%d", prefix); |
413 | } | 396 | } |
414 | mask->sin_family = AF_INET; | 397 | mask->sin_family = AF_INET; |
415 | mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); | 398 | mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); |
416 | return 1; | 399 | return 1; |
417 | } | 400 | } |
418 | #endif /* KEEP_UNUSED */ | 401 | #endif /* KEEP_UNUSED */ |
419 | 402 | ||
420 | static struct aftype inet_aftype = | 403 | static struct aftype inet_aftype = { |
421 | { | 404 | "inet", "DARPA Internet", AF_INET, sizeof(unsigned long), |
422 | "inet", "DARPA Internet", AF_INET, sizeof(unsigned long), | 405 | NULL /* UNUSED INET_print */ , INET_sprint, |
423 | NULL /* UNUSED INET_print */, INET_sprint, | 406 | NULL /* UNUSED INET_input */ , NULL /* UNUSED INET_reserror */ , |
424 | NULL /* UNUSED INET_input */, NULL /* UNUSED INET_reserror */, | 407 | NULL /*INET_rprint */ , NULL /*INET_rinput */ , |
425 | NULL /*INET_rprint */ , NULL /*INET_rinput */ , | 408 | NULL /* UNUSED INET_getnetmask */ , |
426 | NULL /* UNUSED INET_getnetmask */, | 409 | -1, |
427 | -1, | 410 | NULL |
428 | NULL | ||
429 | }; | 411 | }; |
430 | 412 | ||
431 | #endif /* HAVE_AFINET */ | 413 | #endif /* HAVE_AFINET */ |
432 | 414 | ||
433 | #if HAVE_AFINET6 | 415 | #if HAVE_AFINET6 |
434 | 416 | ||
435 | #ifdef KEEP_UNUSED | 417 | #ifdef KEEP_UNUSED |
436 | static void INET6_reserror(char *text) | 418 | static void INET6_reserror(char *text) |
437 | { | 419 | { |
438 | herror(text); | 420 | herror(text); |
439 | } | 421 | } |
440 | 422 | ||
441 | /* Display an Internet socket address. */ | 423 | /* Display an Internet socket address. */ |
442 | static char *INET6_print(unsigned char *ptr) | 424 | static char *INET6_print(unsigned char *ptr) |
443 | { | 425 | { |
444 | static char name[80]; | 426 | static char name[80]; |
445 | 427 | ||
446 | inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); | 428 | inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); |
447 | return name; | 429 | return name; |
448 | } | 430 | } |
449 | #endif /* KEEP_UNUSED */ | 431 | #endif /* KEEP_UNUSED */ |
450 | 432 | ||
451 | /* Display an Internet socket address. */ | 433 | /* Display an Internet socket address. */ |
452 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ | 434 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ |
453 | static char *INET6_sprint(struct sockaddr *sap, int numeric) | 435 | static char *INET6_sprint(struct sockaddr *sap, int numeric) |
454 | { | 436 | { |
455 | static char buff[128]; | 437 | static char buff[128]; |
456 | 438 | ||
457 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 439 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
458 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); | 440 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
459 | if (INET6_rresolve(buff, sizeof(buff), (struct sockaddr_in6 *) sap, numeric) != 0) | 441 | if (INET6_rresolve |
460 | return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff)); | 442 | (buff, sizeof(buff), (struct sockaddr_in6 *) sap, numeric) != 0) |
461 | return (buff); | 443 | return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff)); |
444 | return (buff); | ||
462 | } | 445 | } |
463 | 446 | ||
464 | #ifdef KEEP_UNUSED | 447 | #ifdef KEEP_UNUSED |
465 | static int INET6_getsock(char *bufp, struct sockaddr *sap) | 448 | static int INET6_getsock(char *bufp, struct sockaddr *sap) |
466 | { | 449 | { |
467 | struct sockaddr_in6 *sin6; | 450 | struct sockaddr_in6 *sin6; |
468 | 451 | ||
469 | sin6 = (struct sockaddr_in6 *) sap; | 452 | sin6 = (struct sockaddr_in6 *) sap; |
470 | sin6->sin6_family = AF_INET6; | 453 | sin6->sin6_family = AF_INET6; |
471 | sin6->sin6_port = 0; | 454 | sin6->sin6_port = 0; |
472 | 455 | ||
473 | if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) | 456 | if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) |
474 | return (-1); | 457 | return (-1); |
475 | 458 | ||
476 | return 16; /* ?;) */ | 459 | return 16; /* ?;) */ |
477 | } | 460 | } |
478 | 461 | ||
479 | static int INET6_input(int type, char *bufp, struct sockaddr *sap) | 462 | static int INET6_input(int type, char *bufp, struct sockaddr *sap) |
480 | { | 463 | { |
481 | switch (type) { | 464 | switch (type) { |
482 | case 1: | 465 | case 1: |
483 | return (INET6_getsock(bufp, sap)); | 466 | return (INET6_getsock(bufp, sap)); |
484 | default: | 467 | default: |
485 | return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); | 468 | return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); |
486 | } | 469 | } |
487 | } | 470 | } |
488 | #endif /* KEEP_UNUSED */ | 471 | #endif /* KEEP_UNUSED */ |
489 | 472 | ||
490 | static struct aftype inet6_aftype = | 473 | static struct aftype inet6_aftype = { |
491 | { | 474 | "inet6", "IPv6", AF_INET6, sizeof(struct in6_addr), |
492 | "inet6", "IPv6", AF_INET6, sizeof(struct in6_addr), | 475 | NULL /* UNUSED INET6_print */ , INET6_sprint, |
493 | NULL /* UNUSED INET6_print */, INET6_sprint, | 476 | NULL /* UNUSED INET6_input */ , NULL /* UNUSED INET6_reserror */ , |
494 | NULL /* UNUSED INET6_input */, NULL /* UNUSED INET6_reserror */, | 477 | NULL /*INET6_rprint */ , NULL /*INET6_rinput */ , |
495 | NULL /*INET6_rprint */ , NULL /*INET6_rinput */ , | 478 | NULL /* UNUSED INET6_getnetmask */ , |
496 | NULL /* UNUSED INET6_getnetmask */, | 479 | -1, |
497 | -1, | 480 | NULL |
498 | NULL | ||
499 | }; | 481 | }; |
500 | 482 | ||
501 | #endif /* HAVE_AFINET6 */ | 483 | #endif /* HAVE_AFINET6 */ |
502 | 484 | ||
503 | /* Display an UNSPEC address. */ | 485 | /* Display an UNSPEC address. */ |
504 | static char *UNSPEC_print(unsigned char *ptr) | 486 | static char *UNSPEC_print(unsigned char *ptr) |
505 | { | 487 | { |
506 | static char buff[sizeof(struct sockaddr)*3+1]; | 488 | static char buff[sizeof(struct sockaddr) * 3 + 1]; |
507 | char *pos; | 489 | char *pos; |
508 | unsigned int i; | 490 | unsigned int i; |
509 | 491 | ||
510 | pos = buff; | 492 | pos = buff; |
511 | for (i = 0; i < sizeof(struct sockaddr); i++) { | 493 | for (i = 0; i < sizeof(struct sockaddr); i++) { |
512 | /* careful -- not every libc's sprintf returns # bytes written */ | 494 | /* careful -- not every libc's sprintf returns # bytes written */ |
513 | sprintf(pos, "%02X-", (*ptr++ & 0377)); | 495 | sprintf(pos, "%02X-", (*ptr++ & 0377)); |
514 | pos += 3; | 496 | pos += 3; |
515 | } | 497 | } |
516 | /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */ | 498 | /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */ |
517 | *--pos = '\0'; | 499 | *--pos = '\0'; |
518 | return (buff); | 500 | return (buff); |
519 | } | 501 | } |
520 | 502 | ||
521 | /* Display an UNSPEC socket address. */ | 503 | /* Display an UNSPEC socket address. */ |
522 | static char *UNSPEC_sprint(struct sockaddr *sap, int numeric) | 504 | static char *UNSPEC_sprint(struct sockaddr *sap, int numeric) |
523 | { | 505 | { |
524 | static char buf[64]; | 506 | static char buf[64]; |
525 | 507 | ||
526 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 508 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
527 | return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); | 509 | return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
528 | return (UNSPEC_print(sap->sa_data)); | 510 | return (UNSPEC_print(sap->sa_data)); |
529 | } | 511 | } |
530 | 512 | ||
531 | static struct aftype unspec_aftype = | 513 | static struct aftype unspec_aftype = { |
532 | { | 514 | "unspec", "UNSPEC", AF_UNSPEC, 0, |
533 | "unspec", "UNSPEC", AF_UNSPEC, 0, | 515 | UNSPEC_print, UNSPEC_sprint, NULL, NULL, |
534 | UNSPEC_print, UNSPEC_sprint, NULL, NULL, | 516 | NULL, |
535 | NULL, | ||
536 | }; | 517 | }; |
537 | 518 | ||
538 | static struct aftype *aftypes[] = | 519 | static struct aftype *aftypes[] = { |
539 | { | ||
540 | #if HAVE_AFUNIX | 520 | #if HAVE_AFUNIX |
541 | &unix_aftype, | 521 | &unix_aftype, |
542 | #endif | 522 | #endif |
543 | #if HAVE_AFINET | 523 | #if HAVE_AFINET |
544 | &inet_aftype, | 524 | &inet_aftype, |
545 | #endif | 525 | #endif |
546 | #if HAVE_AFINET6 | 526 | #if HAVE_AFINET6 |
547 | &inet6_aftype, | 527 | &inet6_aftype, |
548 | #endif | 528 | #endif |
549 | #if HAVE_AFAX25 | 529 | #if HAVE_AFAX25 |
550 | &ax25_aftype, | 530 | &ax25_aftype, |
551 | #endif | 531 | #endif |
552 | #if HAVE_AFNETROM | 532 | #if HAVE_AFNETROM |
553 | &netrom_aftype, | 533 | &netrom_aftype, |
554 | #endif | 534 | #endif |
555 | #if HAVE_AFROSE | 535 | #if HAVE_AFROSE |
556 | &rose_aftype, | 536 | &rose_aftype, |
557 | #endif | 537 | #endif |
558 | #if HAVE_AFIPX | 538 | #if HAVE_AFIPX |
559 | &ipx_aftype, | 539 | &ipx_aftype, |
560 | #endif | 540 | #endif |
561 | #if HAVE_AFATALK | 541 | #if HAVE_AFATALK |
562 | &ddp_aftype, | 542 | &ddp_aftype, |
563 | #endif | 543 | #endif |
564 | #if HAVE_AFECONET | 544 | #if HAVE_AFECONET |
565 | &ec_aftype, | 545 | &ec_aftype, |
566 | #endif | 546 | #endif |
567 | #if HAVE_AFASH | 547 | #if HAVE_AFASH |
568 | &ash_aftype, | 548 | &ash_aftype, |
569 | #endif | 549 | #endif |
570 | #if HAVE_AFX25 | 550 | #if HAVE_AFX25 |
571 | &x25_aftype, | 551 | &x25_aftype, |
572 | #endif | 552 | #endif |
573 | &unspec_aftype, | 553 | &unspec_aftype, |
574 | NULL | 554 | NULL |
575 | }; | 555 | }; |
576 | 556 | ||
577 | #ifdef KEEP_UNUSED | 557 | #ifdef KEEP_UNUSED |
@@ -579,626 +559,629 @@ static short sVafinit = 0; | |||
579 | 559 | ||
580 | static void afinit() | 560 | static void afinit() |
581 | { | 561 | { |
582 | unspec_aftype.title = _("UNSPEC"); | 562 | unspec_aftype.title = _("UNSPEC"); |
583 | #if HAVE_AFUNIX | 563 | #if HAVE_AFUNIX |
584 | unix_aftype.title = _("UNIX Domain"); | 564 | unix_aftype.title = _("UNIX Domain"); |
585 | #endif | 565 | #endif |
586 | #if HAVE_AFINET | 566 | #if HAVE_AFINET |
587 | inet_aftype.title = _("DARPA Internet"); | 567 | inet_aftype.title = _("DARPA Internet"); |
588 | #endif | 568 | #endif |
589 | #if HAVE_AFINET6 | 569 | #if HAVE_AFINET6 |
590 | inet6_aftype.title = _("IPv6"); | 570 | inet6_aftype.title = _("IPv6"); |
591 | #endif | 571 | #endif |
592 | #if HAVE_AFAX25 | 572 | #if HAVE_AFAX25 |
593 | ax25_aftype.title = _("AMPR AX.25"); | 573 | ax25_aftype.title = _("AMPR AX.25"); |
594 | #endif | 574 | #endif |
595 | #if HAVE_AFNETROM | 575 | #if HAVE_AFNETROM |
596 | netrom_aftype.title = _("AMPR NET/ROM"); | 576 | netrom_aftype.title = _("AMPR NET/ROM"); |
597 | #endif | 577 | #endif |
598 | #if HAVE_AFIPX | 578 | #if HAVE_AFIPX |
599 | ipx_aftype.title = _("Novell IPX"); | 579 | ipx_aftype.title = _("Novell IPX"); |
600 | #endif | 580 | #endif |
601 | #if HAVE_AFATALK | 581 | #if HAVE_AFATALK |
602 | ddp_aftype.title = _("Appletalk DDP"); | 582 | ddp_aftype.title = _("Appletalk DDP"); |
603 | #endif | 583 | #endif |
604 | #if HAVE_AFECONET | 584 | #if HAVE_AFECONET |
605 | ec_aftype.title = _("Econet"); | 585 | ec_aftype.title = _("Econet"); |
606 | #endif | 586 | #endif |
607 | #if HAVE_AFX25 | 587 | #if HAVE_AFX25 |
608 | x25_aftype.title = _("CCITT X.25"); | 588 | x25_aftype.title = _("CCITT X.25"); |
609 | #endif | 589 | #endif |
610 | #if HAVE_AFROSE | 590 | #if HAVE_AFROSE |
611 | rose_aftype.title = _("AMPR ROSE"); | 591 | rose_aftype.title = _("AMPR ROSE"); |
612 | #endif | 592 | #endif |
613 | #if HAVE_AFASH | 593 | #if HAVE_AFASH |
614 | ash_aftype.title = _("Ash"); | 594 | ash_aftype.title = _("Ash"); |
615 | #endif | 595 | #endif |
616 | sVafinit = 1; | 596 | sVafinit = 1; |
617 | } | 597 | } |
618 | 598 | ||
619 | static int aftrans_opt(const char *arg) | 599 | static int aftrans_opt(const char *arg) |
620 | { | 600 | { |
621 | struct aftrans_t *paft; | 601 | struct aftrans_t *paft; |
622 | char *tmp1, *tmp2; | 602 | char *tmp1, *tmp2; |
623 | char buf[256]; | 603 | char buf[256]; |
624 | 604 | ||
625 | safe_strncpy(buf, arg, sizeof(buf)); | 605 | safe_strncpy(buf, arg, sizeof(buf)); |
626 | 606 | ||
627 | tmp1 = buf; | 607 | tmp1 = buf; |
628 | 608 | ||
629 | while (tmp1) { | 609 | while (tmp1) { |
630 | 610 | ||
631 | tmp2 = strchr(tmp1, ','); | 611 | tmp2 = strchr(tmp1, ','); |
632 | 612 | ||
633 | if (tmp2) | 613 | if (tmp2) |
634 | *(tmp2++) = '\0'; | 614 | *(tmp2++) = '\0'; |
635 | 615 | ||
636 | paft = aftrans; | 616 | paft = aftrans; |
637 | for (paft = aftrans; paft->alias; paft++) { | 617 | for (paft = aftrans; paft->alias; paft++) { |
638 | if (strcmp(tmp1, paft->alias)) | 618 | if (strcmp(tmp1, paft->alias)) |
639 | continue; | 619 | continue; |
640 | if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) { | 620 | if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) { |
641 | fprintf(stderr, _("Too much address family arguments.\n")); | 621 | fprintf(stderr, _("Too much address family arguments.\n")); |
642 | return (0); | 622 | return (0); |
643 | } | 623 | } |
644 | if (paft->flag) | 624 | if (paft->flag) |
645 | (*paft->flag)++; | 625 | (*paft->flag)++; |
646 | if (afname[0]) | 626 | if (afname[0]) |
647 | strcat(afname, ","); | 627 | strcat(afname, ","); |
648 | strcat(afname, paft->name); | 628 | strcat(afname, paft->name); |
649 | break; | 629 | break; |
650 | } | 630 | } |
651 | if (!paft->alias) { | 631 | if (!paft->alias) { |
652 | fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1); | 632 | fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1); |
653 | return (1); | 633 | return (1); |
634 | } | ||
635 | tmp1 = tmp2; | ||
654 | } | 636 | } |
655 | tmp1 = tmp2; | ||
656 | } | ||
657 | 637 | ||
658 | return (0); | 638 | return (0); |
659 | } | 639 | } |
660 | 640 | ||
661 | /* set the default AF list from the program name or a constant value */ | 641 | /* set the default AF list from the program name or a constant value */ |
662 | static void aftrans_def(char *tool, char *argv0, char *dflt) | 642 | static void aftrans_def(char *tool, char *argv0, char *dflt) |
663 | { | 643 | { |
664 | char *tmp; | 644 | char *tmp; |
665 | char *buf; | 645 | char *buf; |
666 | 646 | ||
667 | strcpy(afname, dflt); | 647 | strcpy(afname, dflt); |
668 | 648 | ||
669 | if (!(tmp = strrchr(argv0, '/'))) | 649 | if (!(tmp = strrchr(argv0, '/'))) |
670 | tmp = argv0; /* no slash?! */ | 650 | tmp = argv0; /* no slash?! */ |
671 | else | 651 | else |
672 | tmp++; | 652 | tmp++; |
673 | 653 | ||
674 | if (!(buf = strdup(tmp))) | 654 | if (!(buf = strdup(tmp))) |
675 | return; | 655 | return; |
676 | 656 | ||
677 | if (strlen(tool) >= strlen(tmp)) { | 657 | if (strlen(tool) >= strlen(tmp)) { |
678 | free(buf); | 658 | free(buf); |
679 | return; | 659 | return; |
680 | } | 660 | } |
681 | tmp = buf + (strlen(tmp) - strlen(tool)); | 661 | tmp = buf + (strlen(tmp) - strlen(tool)); |
682 | 662 | ||
683 | if (strcmp(tmp, tool) != 0) { | 663 | if (strcmp(tmp, tool) != 0) { |
684 | free(buf); | 664 | free(buf); |
685 | return; | 665 | return; |
686 | } | 666 | } |
687 | *tmp = '\0'; | ||
688 | if ((tmp = strchr(buf, '_'))) | ||
689 | *tmp = '\0'; | 667 | *tmp = '\0'; |
668 | if ((tmp = strchr(buf, '_'))) | ||
669 | *tmp = '\0'; | ||
690 | 670 | ||
691 | afname[0] = '\0'; | 671 | afname[0] = '\0'; |
692 | if (aftrans_opt(buf)) | 672 | if (aftrans_opt(buf)) |
693 | strcpy(afname, buf); | 673 | strcpy(afname, buf); |
694 | 674 | ||
695 | free(buf); | 675 | free(buf); |
696 | } | 676 | } |
697 | 677 | ||
698 | /* Check our protocol family table for this family. */ | 678 | /* Check our protocol family table for this family. */ |
699 | static struct aftype *get_aftype(const char *name) | 679 | static struct aftype *get_aftype(const char *name) |
700 | { | 680 | { |
701 | struct aftype **afp; | 681 | struct aftype **afp; |
702 | 682 | ||
703 | #ifdef KEEP_UNUSED | 683 | #ifdef KEEP_UNUSED |
704 | if (!sVafinit) | 684 | if (!sVafinit) |
705 | afinit(); | 685 | afinit(); |
706 | #endif /* KEEP_UNUSED */ | 686 | #endif /* KEEP_UNUSED */ |
707 | 687 | ||
708 | afp = aftypes; | 688 | afp = aftypes; |
709 | while (*afp != NULL) { | 689 | while (*afp != NULL) { |
710 | if (!strcmp((*afp)->name, name)) | 690 | if (!strcmp((*afp)->name, name)) |
711 | return (*afp); | 691 | return (*afp); |
712 | afp++; | 692 | afp++; |
713 | } | 693 | } |
714 | if (strchr(name, ',')) | 694 | if (strchr(name, ',')) |
715 | fprintf(stderr, _("Please don't supply more than one address family.\n")); | 695 | fprintf(stderr, |
716 | return (NULL); | 696 | _("Please don't supply more than one address family.\n")); |
697 | return (NULL); | ||
717 | } | 698 | } |
718 | #endif /* KEEP_UNUSED */ | 699 | #endif /* KEEP_UNUSED */ |
719 | 700 | ||
720 | /* Check our protocol family table for this family. */ | 701 | /* Check our protocol family table for this family. */ |
721 | static struct aftype *get_afntype(int af) | 702 | static struct aftype *get_afntype(int af) |
722 | { | 703 | { |
723 | struct aftype **afp; | 704 | struct aftype **afp; |
724 | 705 | ||
725 | #ifdef KEEP_UNUSED | 706 | #ifdef KEEP_UNUSED |
726 | if (!sVafinit) | 707 | if (!sVafinit) |
727 | afinit(); | 708 | afinit(); |
728 | #endif /* KEEP_UNUSED */ | 709 | #endif /* KEEP_UNUSED */ |
729 | 710 | ||
730 | afp = aftypes; | 711 | afp = aftypes; |
731 | while (*afp != NULL) { | 712 | while (*afp != NULL) { |
732 | if ((*afp)->af == af) | 713 | if ((*afp)->af == af) |
733 | return (*afp); | 714 | return (*afp); |
734 | afp++; | 715 | afp++; |
735 | } | 716 | } |
736 | return (NULL); | 717 | return (NULL); |
737 | } | 718 | } |
738 | 719 | ||
739 | /* Check our protocol family table for this family and return its socket */ | 720 | /* Check our protocol family table for this family and return its socket */ |
740 | static int get_socket_for_af(int af) | 721 | static int get_socket_for_af(int af) |
741 | { | 722 | { |
742 | struct aftype **afp; | 723 | struct aftype **afp; |
743 | 724 | ||
744 | #ifdef KEEP_UNUSED | 725 | #ifdef KEEP_UNUSED |
745 | if (!sVafinit) | 726 | if (!sVafinit) |
746 | afinit(); | 727 | afinit(); |
747 | #endif /* KEEP_UNUSED */ | 728 | #endif /* KEEP_UNUSED */ |
748 | 729 | ||
749 | afp = aftypes; | 730 | afp = aftypes; |
750 | while (*afp != NULL) { | 731 | while (*afp != NULL) { |
751 | if ((*afp)->af == af) | 732 | if ((*afp)->af == af) |
752 | return (*afp)->fd; | 733 | return (*afp)->fd; |
753 | afp++; | 734 | afp++; |
754 | } | 735 | } |
755 | return -1; | 736 | return -1; |
756 | } | 737 | } |
757 | 738 | ||
758 | #ifdef KEEP_UNUSED | 739 | #ifdef KEEP_UNUSED |
759 | /* type: 0=all, 1=getroute */ | 740 | /* type: 0=all, 1=getroute */ |
760 | static void print_aflist(int type) { | 741 | static void print_aflist(int type) |
761 | int count = 0; | 742 | { |
762 | char * txt; | 743 | int count = 0; |
763 | struct aftype **afp; | 744 | char *txt; |
745 | struct aftype **afp; | ||
764 | 746 | ||
765 | #ifdef KEEP_UNUSED | 747 | #ifdef KEEP_UNUSED |
766 | if (!sVafinit) | 748 | if (!sVafinit) |
767 | afinit(); | 749 | afinit(); |
768 | #endif /* KEEP_UNUSED */ | 750 | #endif /* KEEP_UNUSED */ |
769 | 751 | ||
770 | afp = aftypes; | 752 | afp = aftypes; |
771 | while (*afp != NULL) { | 753 | while (*afp != NULL) { |
772 | if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) { | 754 | if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) { |
773 | afp++; continue; | 755 | afp++; |
756 | continue; | ||
757 | } | ||
758 | if ((count % 3) == 0) | ||
759 | fprintf(stderr, count ? "\n " : " "); | ||
760 | txt = (*afp)->name; | ||
761 | if (!txt) | ||
762 | txt = ".."; | ||
763 | fprintf(stderr, "%s (%s) ", txt, _((*afp)->title)); | ||
764 | count++; | ||
765 | afp++; | ||
774 | } | 766 | } |
775 | if ((count % 3) == 0) fprintf(stderr,count?"\n ":" "); | 767 | fprintf(stderr, "\n"); |
776 | txt = (*afp)->name; if (!txt) txt = ".."; | ||
777 | fprintf(stderr,"%s (%s) ",txt,_((*afp)->title)); | ||
778 | count++; | ||
779 | afp++; | ||
780 | } | ||
781 | fprintf(stderr,"\n"); | ||
782 | } | 768 | } |
783 | #endif /* KEEP_UNUSED */ | 769 | #endif /* KEEP_UNUSED */ |
784 | 770 | ||
785 | struct user_net_device_stats { | 771 | struct user_net_device_stats { |
786 | unsigned long long rx_packets; /* total packets received */ | 772 | unsigned long long rx_packets; /* total packets received */ |
787 | unsigned long long tx_packets; /* total packets transmitted */ | 773 | unsigned long long tx_packets; /* total packets transmitted */ |
788 | unsigned long long rx_bytes; /* total bytes received */ | 774 | unsigned long long rx_bytes; /* total bytes received */ |
789 | unsigned long long tx_bytes; /* total bytes transmitted */ | 775 | unsigned long long tx_bytes; /* total bytes transmitted */ |
790 | unsigned long rx_errors; /* bad packets received */ | 776 | unsigned long rx_errors; /* bad packets received */ |
791 | unsigned long tx_errors; /* packet transmit problems */ | 777 | unsigned long tx_errors; /* packet transmit problems */ |
792 | unsigned long rx_dropped; /* no space in linux buffers */ | 778 | unsigned long rx_dropped; /* no space in linux buffers */ |
793 | unsigned long tx_dropped; /* no space available in linux */ | 779 | unsigned long tx_dropped; /* no space available in linux */ |
794 | unsigned long rx_multicast; /* multicast packets received */ | 780 | unsigned long rx_multicast; /* multicast packets received */ |
795 | unsigned long rx_compressed; | 781 | unsigned long rx_compressed; |
796 | unsigned long tx_compressed; | 782 | unsigned long tx_compressed; |
797 | unsigned long collisions; | 783 | unsigned long collisions; |
798 | 784 | ||
799 | /* detailed rx_errors: */ | 785 | /* detailed rx_errors: */ |
800 | unsigned long rx_length_errors; | 786 | unsigned long rx_length_errors; |
801 | unsigned long rx_over_errors; /* receiver ring buff overflow */ | 787 | unsigned long rx_over_errors; /* receiver ring buff overflow */ |
802 | unsigned long rx_crc_errors; /* recved pkt with crc error */ | 788 | unsigned long rx_crc_errors; /* recved pkt with crc error */ |
803 | unsigned long rx_frame_errors; /* recv'd frame alignment error */ | 789 | unsigned long rx_frame_errors; /* recv'd frame alignment error */ |
804 | unsigned long rx_fifo_errors; /* recv'r fifo overrun */ | 790 | unsigned long rx_fifo_errors; /* recv'r fifo overrun */ |
805 | unsigned long rx_missed_errors; /* receiver missed packet */ | 791 | unsigned long rx_missed_errors; /* receiver missed packet */ |
806 | /* detailed tx_errors */ | 792 | /* detailed tx_errors */ |
807 | unsigned long tx_aborted_errors; | 793 | unsigned long tx_aborted_errors; |
808 | unsigned long tx_carrier_errors; | 794 | unsigned long tx_carrier_errors; |
809 | unsigned long tx_fifo_errors; | 795 | unsigned long tx_fifo_errors; |
810 | unsigned long tx_heartbeat_errors; | 796 | unsigned long tx_heartbeat_errors; |
811 | unsigned long tx_window_errors; | 797 | unsigned long tx_window_errors; |
812 | }; | 798 | }; |
813 | 799 | ||
814 | struct interface { | 800 | struct interface { |
815 | struct interface *next, *prev; | 801 | struct interface *next, *prev; |
816 | char name[IFNAMSIZ]; /* interface name */ | 802 | char name[IFNAMSIZ]; /* interface name */ |
817 | short type; /* if type */ | 803 | short type; /* if type */ |
818 | short flags; /* various flags */ | 804 | short flags; /* various flags */ |
819 | int metric; /* routing metric */ | 805 | int metric; /* routing metric */ |
820 | int mtu; /* MTU value */ | 806 | int mtu; /* MTU value */ |
821 | int tx_queue_len; /* transmit queue length */ | 807 | int tx_queue_len; /* transmit queue length */ |
822 | struct ifmap map; /* hardware setup */ | 808 | struct ifmap map; /* hardware setup */ |
823 | struct sockaddr addr; /* IP address */ | 809 | struct sockaddr addr; /* IP address */ |
824 | struct sockaddr dstaddr; /* P-P IP address */ | 810 | struct sockaddr dstaddr; /* P-P IP address */ |
825 | struct sockaddr broadaddr; /* IP broadcast address */ | 811 | struct sockaddr broadaddr; /* IP broadcast address */ |
826 | struct sockaddr netmask; /* IP network mask */ | 812 | struct sockaddr netmask; /* IP network mask */ |
827 | struct sockaddr ipxaddr_bb; /* IPX network address */ | 813 | struct sockaddr ipxaddr_bb; /* IPX network address */ |
828 | struct sockaddr ipxaddr_sn; /* IPX network address */ | 814 | struct sockaddr ipxaddr_sn; /* IPX network address */ |
829 | struct sockaddr ipxaddr_e3; /* IPX network address */ | 815 | struct sockaddr ipxaddr_e3; /* IPX network address */ |
830 | struct sockaddr ipxaddr_e2; /* IPX network address */ | 816 | struct sockaddr ipxaddr_e2; /* IPX network address */ |
831 | struct sockaddr ddpaddr; /* Appletalk DDP address */ | 817 | struct sockaddr ddpaddr; /* Appletalk DDP address */ |
832 | struct sockaddr ecaddr; /* Econet address */ | 818 | struct sockaddr ecaddr; /* Econet address */ |
833 | int has_ip; | 819 | int has_ip; |
834 | int has_ipx_bb; | 820 | int has_ipx_bb; |
835 | int has_ipx_sn; | 821 | int has_ipx_sn; |
836 | int has_ipx_e3; | 822 | int has_ipx_e3; |
837 | int has_ipx_e2; | 823 | int has_ipx_e2; |
838 | int has_ax25; | 824 | int has_ax25; |
839 | int has_ddp; | 825 | int has_ddp; |
840 | int has_econet; | 826 | int has_econet; |
841 | char hwaddr[32]; /* HW address */ | 827 | char hwaddr[32]; /* HW address */ |
842 | int statistics_valid; | 828 | int statistics_valid; |
843 | struct user_net_device_stats stats; /* statistics */ | 829 | struct user_net_device_stats stats; /* statistics */ |
844 | int keepalive; /* keepalive value for SLIP */ | 830 | int keepalive; /* keepalive value for SLIP */ |
845 | int outfill; /* outfill value for SLIP */ | 831 | int outfill; /* outfill value for SLIP */ |
846 | }; | 832 | }; |
847 | 833 | ||
848 | 834 | ||
849 | int interface_opt_a = 0; /* show all interfaces */ | 835 | int interface_opt_a = 0; /* show all interfaces */ |
850 | 836 | ||
851 | #ifdef KEEP_UNUSED | 837 | #ifdef KEEP_UNUSED |
852 | static int opt_i = 0; /* show the statistics */ | 838 | static int opt_i = 0; /* show the statistics */ |
853 | static int opt_v = 0; /* debugging output flag */ | 839 | static int opt_v = 0; /* debugging output flag */ |
854 | 840 | ||
855 | static int addr_family = 0; /* currently selected AF */ | 841 | static int addr_family = 0; /* currently selected AF */ |
856 | #endif /* KEEP_UNUSED */ | 842 | #endif /* KEEP_UNUSED */ |
857 | 843 | ||
858 | static struct interface *int_list, *int_last; | 844 | static struct interface *int_list, *int_last; |
859 | static int skfd = -1; /* generic raw socket desc. */ | 845 | static int skfd = -1; /* generic raw socket desc. */ |
860 | 846 | ||
861 | 847 | ||
862 | static int sockets_open(int family) | 848 | static int sockets_open(int family) |
863 | { | 849 | { |
864 | struct aftype **aft; | 850 | struct aftype **aft; |
865 | int sfd = -1; | 851 | int sfd = -1; |
866 | static int force = -1; | 852 | static int force = -1; |
867 | 853 | ||
868 | if (force < 0) { | 854 | if (force < 0) { |
869 | force = 0; | 855 | force = 0; |
870 | if (get_kernel_revision() < KRELEASE(2, 1, 0)) | 856 | if (get_kernel_revision() < KRELEASE(2, 1, 0)) |
871 | force = 1; | 857 | force = 1; |
872 | if (access("/proc/net", R_OK)) | 858 | if (access("/proc/net", R_OK)) |
873 | force = 1; | 859 | force = 1; |
874 | } | ||
875 | for (aft = aftypes; *aft; aft++) { | ||
876 | struct aftype *af = *aft; | ||
877 | int type = SOCK_DGRAM; | ||
878 | if (af->af == AF_UNSPEC) | ||
879 | continue; | ||
880 | if (family && family != af->af) | ||
881 | continue; | ||
882 | if (af->fd != -1) { | ||
883 | sfd = af->fd; | ||
884 | continue; | ||
885 | } | ||
886 | /* Check some /proc file first to not stress kmod */ | ||
887 | if (!family && !force && af->flag_file) { | ||
888 | if (access(af->flag_file, R_OK)) | ||
889 | continue; | ||
890 | } | 860 | } |
861 | for (aft = aftypes; *aft; aft++) { | ||
862 | struct aftype *af = *aft; | ||
863 | int type = SOCK_DGRAM; | ||
864 | |||
865 | if (af->af == AF_UNSPEC) | ||
866 | continue; | ||
867 | if (family && family != af->af) | ||
868 | continue; | ||
869 | if (af->fd != -1) { | ||
870 | sfd = af->fd; | ||
871 | continue; | ||
872 | } | ||
873 | /* Check some /proc file first to not stress kmod */ | ||
874 | if (!family && !force && af->flag_file) { | ||
875 | if (access(af->flag_file, R_OK)) | ||
876 | continue; | ||
877 | } | ||
891 | #if HAVE_AFNETROM | 878 | #if HAVE_AFNETROM |
892 | if (af->af == AF_NETROM) | 879 | if (af->af == AF_NETROM) |
893 | type = SOCK_SEQPACKET; | 880 | type = SOCK_SEQPACKET; |
894 | #endif | 881 | #endif |
895 | #if HAVE_AFX25 | 882 | #if HAVE_AFX25 |
896 | if (af->af == AF_X25) | 883 | if (af->af == AF_X25) |
897 | type = SOCK_SEQPACKET; | 884 | type = SOCK_SEQPACKET; |
898 | #endif | 885 | #endif |
899 | af->fd = socket(af->af, type, 0); | 886 | af->fd = socket(af->af, type, 0); |
900 | if (af->fd >= 0) | 887 | if (af->fd >= 0) |
901 | sfd = af->fd; | 888 | sfd = af->fd; |
902 | } | 889 | } |
903 | if (sfd < 0) | 890 | if (sfd < 0) |
904 | fprintf(stderr, _("No usable address families found.\n")); | 891 | fprintf(stderr, _("No usable address families found.\n")); |
905 | return sfd; | 892 | return sfd; |
906 | } | 893 | } |
907 | 894 | ||
908 | /* like strcmp(), but knows about numbers */ | 895 | /* like strcmp(), but knows about numbers */ |
909 | static int nstrcmp(const char *astr, const char *b) | 896 | static int nstrcmp(const char *astr, const char *b) |
910 | { | 897 | { |
911 | const char *a = astr; | 898 | const char *a = astr; |
912 | 899 | ||
913 | while (*a == *b) { | 900 | while (*a == *b) { |
914 | if (*a == '\0') | 901 | if (*a == '\0') |
915 | return 0; | 902 | return 0; |
916 | a++; | ||
917 | b++; | ||
918 | } | ||
919 | if (isdigit(*a)) { | ||
920 | if (!isdigit(*b)) | ||
921 | return -1; | ||
922 | while (a > astr) { | ||
923 | a--; | ||
924 | if (!isdigit(*a)) { | ||
925 | a++; | 903 | a++; |
926 | break; | 904 | b++; |
927 | } | 905 | } |
928 | if (!isdigit(*b)) | 906 | if (isdigit(*a)) { |
929 | return -1; | 907 | if (!isdigit(*b)) |
930 | b--; | 908 | return -1; |
909 | while (a > astr) { | ||
910 | a--; | ||
911 | if (!isdigit(*a)) { | ||
912 | a++; | ||
913 | break; | ||
914 | } | ||
915 | if (!isdigit(*b)) | ||
916 | return -1; | ||
917 | b--; | ||
918 | } | ||
919 | return atoi(a) > atoi(b) ? 1 : -1; | ||
931 | } | 920 | } |
932 | return atoi(a) > atoi(b) ? 1 : -1; | 921 | return *a - *b; |
933 | } | ||
934 | return *a - *b; | ||
935 | } | 922 | } |
936 | 923 | ||
937 | static struct interface *add_interface(char *name) | 924 | static struct interface *add_interface(char *name) |
938 | { | 925 | { |
939 | struct interface *ife, **nextp, *new; | 926 | struct interface *ife, **nextp, *new; |
940 | 927 | ||
941 | for (ife = int_last; ife; ife = ife->prev) { | 928 | for (ife = int_last; ife; ife = ife->prev) { |
942 | int n = nstrcmp(ife->name, name); | 929 | int n = nstrcmp(ife->name, name); |
943 | if (n == 0) | 930 | |
944 | return ife; | 931 | if (n == 0) |
945 | if (n < 0) | 932 | return ife; |
946 | break; | 933 | if (n < 0) |
947 | } | 934 | break; |
948 | new(new); | 935 | } |
949 | safe_strncpy(new->name, name, IFNAMSIZ); | 936 | new(new); |
950 | nextp = ife ? &ife->next : &int_list; | 937 | safe_strncpy(new->name, name, IFNAMSIZ); |
951 | new->prev = ife; | 938 | nextp = ife ? &ife->next : &int_list; |
952 | new->next = *nextp; | 939 | new->prev = ife; |
953 | if (new->next) | 940 | new->next = *nextp; |
954 | new->next->prev = new; | 941 | if (new->next) |
955 | else | 942 | new->next->prev = new; |
956 | int_last = new; | 943 | else |
957 | *nextp = new; | 944 | int_last = new; |
958 | return new; | 945 | *nextp = new; |
946 | return new; | ||
959 | } | 947 | } |
960 | 948 | ||
961 | 949 | ||
962 | static int if_readconf(void) | 950 | static int if_readconf(void) |
963 | { | 951 | { |
964 | int numreqs = 30; | 952 | int numreqs = 30; |
965 | struct ifconf ifc; | 953 | struct ifconf ifc; |
966 | struct ifreq *ifr; | 954 | struct ifreq *ifr; |
967 | int n, err = -1; | 955 | int n, err = -1; |
968 | int skfd2; | 956 | int skfd2; |
969 | 957 | ||
970 | /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets | 958 | /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets |
971 | (as of 2.1.128) */ | 959 | (as of 2.1.128) */ |
972 | skfd2 = get_socket_for_af(AF_INET); | 960 | skfd2 = get_socket_for_af(AF_INET); |
973 | if (skfd2 < 0) { | 961 | if (skfd2 < 0) { |
974 | fprintf(stderr, _("warning: no inet socket available: %s\n"), | 962 | fprintf(stderr, _("warning: no inet socket available: %s\n"), |
975 | strerror(errno)); | 963 | strerror(errno)); |
976 | /* Try to soldier on with whatever socket we can get hold of. */ | 964 | /* Try to soldier on with whatever socket we can get hold of. */ |
977 | skfd2 = sockets_open(0); | 965 | skfd2 = sockets_open(0); |
978 | if (skfd2 < 0) | 966 | if (skfd2 < 0) |
979 | return -1; | 967 | return -1; |
980 | } | 968 | } |
981 | 969 | ||
982 | ifc.ifc_buf = NULL; | 970 | ifc.ifc_buf = NULL; |
983 | for (;;) { | 971 | for (;;) { |
984 | ifc.ifc_len = sizeof(struct ifreq) * numreqs; | 972 | ifc.ifc_len = sizeof(struct ifreq) * numreqs; |
985 | ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); | 973 | ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); |
986 | 974 | ||
987 | if (ioctl(skfd2, SIOCGIFCONF, &ifc) < 0) { | 975 | if (ioctl(skfd2, SIOCGIFCONF, &ifc) < 0) { |
988 | perror("SIOCGIFCONF"); | 976 | perror("SIOCGIFCONF"); |
989 | goto out; | 977 | goto out; |
978 | } | ||
979 | if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { | ||
980 | /* assume it overflowed and try again */ | ||
981 | numreqs += 10; | ||
982 | continue; | ||
983 | } | ||
984 | break; | ||
990 | } | 985 | } |
991 | if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { | 986 | |
992 | /* assume it overflowed and try again */ | 987 | ifr = ifc.ifc_req; |
993 | numreqs += 10; | 988 | for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) { |
994 | continue; | 989 | add_interface(ifr->ifr_name); |
990 | ifr++; | ||
995 | } | 991 | } |
996 | break; | 992 | err = 0; |
997 | } | 993 | |
998 | 994 | out: | |
999 | ifr = ifc.ifc_req; | 995 | free(ifc.ifc_buf); |
1000 | for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) { | 996 | return err; |
1001 | add_interface(ifr->ifr_name); | ||
1002 | ifr++; | ||
1003 | } | ||
1004 | err = 0; | ||
1005 | |||
1006 | out: | ||
1007 | free(ifc.ifc_buf); | ||
1008 | return err; | ||
1009 | } | 997 | } |
1010 | 998 | ||
1011 | static char *get_name(char *name, char *p) | 999 | static char *get_name(char *name, char *p) |
1012 | { | 1000 | { |
1013 | while (isspace(*p)) | 1001 | while (isspace(*p)) |
1014 | p++; | 1002 | p++; |
1015 | while (*p) { | 1003 | while (*p) { |
1016 | if (isspace(*p)) | 1004 | if (isspace(*p)) |
1017 | break; | 1005 | break; |
1018 | if (*p == ':') { /* could be an alias */ | 1006 | if (*p == ':') { /* could be an alias */ |
1019 | char *dot = p, *dotname = name; | 1007 | char *dot = p, *dotname = name; |
1020 | *name++ = *p++; | 1008 | |
1021 | while (isdigit(*p)) | 1009 | *name++ = *p++; |
1010 | while (isdigit(*p)) | ||
1011 | *name++ = *p++; | ||
1012 | if (*p != ':') { /* it wasn't, backup */ | ||
1013 | p = dot; | ||
1014 | name = dotname; | ||
1015 | } | ||
1016 | if (*p == '\0') | ||
1017 | return NULL; | ||
1018 | p++; | ||
1019 | break; | ||
1020 | } | ||
1022 | *name++ = *p++; | 1021 | *name++ = *p++; |
1023 | if (*p != ':') { /* it wasn't, backup */ | ||
1024 | p = dot; | ||
1025 | name = dotname; | ||
1026 | } | ||
1027 | if (*p == '\0') | ||
1028 | return NULL; | ||
1029 | p++; | ||
1030 | break; | ||
1031 | } | 1022 | } |
1032 | *name++ = *p++; | 1023 | *name++ = '\0'; |
1033 | } | 1024 | return p; |
1034 | *name++ = '\0'; | ||
1035 | return p; | ||
1036 | } | 1025 | } |
1037 | 1026 | ||
1038 | static int get_dev_fields(char *bp, struct interface *ife) | 1027 | static int get_dev_fields(char *bp, struct interface *ife) |
1039 | { | 1028 | { |
1040 | switch (procnetdev_vsn) { | 1029 | switch (procnetdev_vsn) { |
1041 | case 3: | 1030 | case 3: |
1042 | sscanf(bp, | 1031 | sscanf(bp, |
1043 | "%Lu %Lu %lu %lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu %lu", | 1032 | "%Lu %Lu %lu %lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu %lu", |
1044 | &ife->stats.rx_bytes, | 1033 | &ife->stats.rx_bytes, |
1045 | &ife->stats.rx_packets, | 1034 | &ife->stats.rx_packets, |
1046 | &ife->stats.rx_errors, | 1035 | &ife->stats.rx_errors, |
1047 | &ife->stats.rx_dropped, | 1036 | &ife->stats.rx_dropped, |
1048 | &ife->stats.rx_fifo_errors, | 1037 | &ife->stats.rx_fifo_errors, |
1049 | &ife->stats.rx_frame_errors, | 1038 | &ife->stats.rx_frame_errors, |
1050 | &ife->stats.rx_compressed, | 1039 | &ife->stats.rx_compressed, |
1051 | &ife->stats.rx_multicast, | 1040 | &ife->stats.rx_multicast, |
1052 | 1041 | &ife->stats.tx_bytes, | |
1053 | &ife->stats.tx_bytes, | 1042 | &ife->stats.tx_packets, |
1054 | &ife->stats.tx_packets, | 1043 | &ife->stats.tx_errors, |
1055 | &ife->stats.tx_errors, | 1044 | &ife->stats.tx_dropped, |
1056 | &ife->stats.tx_dropped, | 1045 | &ife->stats.tx_fifo_errors, |
1057 | &ife->stats.tx_fifo_errors, | 1046 | &ife->stats.collisions, |
1058 | &ife->stats.collisions, | 1047 | &ife->stats.tx_carrier_errors, &ife->stats.tx_compressed); |
1059 | &ife->stats.tx_carrier_errors, | 1048 | break; |
1060 | &ife->stats.tx_compressed); | 1049 | case 2: |
1061 | break; | 1050 | sscanf(bp, "%Lu %Lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu", |
1062 | case 2: | 1051 | &ife->stats.rx_bytes, |
1063 | sscanf(bp, "%Lu %Lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu", | 1052 | &ife->stats.rx_packets, |
1064 | &ife->stats.rx_bytes, | 1053 | &ife->stats.rx_errors, |
1065 | &ife->stats.rx_packets, | 1054 | &ife->stats.rx_dropped, |
1066 | &ife->stats.rx_errors, | 1055 | &ife->stats.rx_fifo_errors, |
1067 | &ife->stats.rx_dropped, | 1056 | &ife->stats.rx_frame_errors, |
1068 | &ife->stats.rx_fifo_errors, | 1057 | &ife->stats.tx_bytes, |
1069 | &ife->stats.rx_frame_errors, | 1058 | &ife->stats.tx_packets, |
1070 | 1059 | &ife->stats.tx_errors, | |
1071 | &ife->stats.tx_bytes, | 1060 | &ife->stats.tx_dropped, |
1072 | &ife->stats.tx_packets, | 1061 | &ife->stats.tx_fifo_errors, |
1073 | &ife->stats.tx_errors, | 1062 | &ife->stats.collisions, &ife->stats.tx_carrier_errors); |
1074 | &ife->stats.tx_dropped, | 1063 | ife->stats.rx_multicast = 0; |
1075 | &ife->stats.tx_fifo_errors, | 1064 | break; |
1076 | &ife->stats.collisions, | 1065 | case 1: |
1077 | &ife->stats.tx_carrier_errors); | 1066 | sscanf(bp, "%Lu %lu %lu %lu %lu %Lu %lu %lu %lu %lu %lu", |
1078 | ife->stats.rx_multicast = 0; | 1067 | &ife->stats.rx_packets, |
1079 | break; | 1068 | &ife->stats.rx_errors, |
1080 | case 1: | 1069 | &ife->stats.rx_dropped, |
1081 | sscanf(bp, "%Lu %lu %lu %lu %lu %Lu %lu %lu %lu %lu %lu", | 1070 | &ife->stats.rx_fifo_errors, |
1082 | &ife->stats.rx_packets, | 1071 | &ife->stats.rx_frame_errors, |
1083 | &ife->stats.rx_errors, | 1072 | &ife->stats.tx_packets, |
1084 | &ife->stats.rx_dropped, | 1073 | &ife->stats.tx_errors, |
1085 | &ife->stats.rx_fifo_errors, | 1074 | &ife->stats.tx_dropped, |
1086 | &ife->stats.rx_frame_errors, | 1075 | &ife->stats.tx_fifo_errors, |
1087 | 1076 | &ife->stats.collisions, &ife->stats.tx_carrier_errors); | |
1088 | &ife->stats.tx_packets, | 1077 | ife->stats.rx_bytes = 0; |
1089 | &ife->stats.tx_errors, | 1078 | ife->stats.tx_bytes = 0; |
1090 | &ife->stats.tx_dropped, | 1079 | ife->stats.rx_multicast = 0; |
1091 | &ife->stats.tx_fifo_errors, | 1080 | break; |
1092 | &ife->stats.collisions, | 1081 | } |
1093 | &ife->stats.tx_carrier_errors); | 1082 | return 0; |
1094 | ife->stats.rx_bytes = 0; | ||
1095 | ife->stats.tx_bytes = 0; | ||
1096 | ife->stats.rx_multicast = 0; | ||
1097 | break; | ||
1098 | } | ||
1099 | return 0; | ||
1100 | } | 1083 | } |
1101 | 1084 | ||
1102 | static inline int procnetdev_version(char *buf) | 1085 | static inline int procnetdev_version(char *buf) |
1103 | { | 1086 | { |
1104 | if (strstr(buf, "compressed")) | 1087 | if (strstr(buf, "compressed")) |
1105 | return 3; | 1088 | return 3; |
1106 | if (strstr(buf, "bytes")) | 1089 | if (strstr(buf, "bytes")) |
1107 | return 2; | 1090 | return 2; |
1108 | return 1; | 1091 | return 1; |
1109 | } | 1092 | } |
1110 | 1093 | ||
1111 | static int if_readlist_proc(char *target) | 1094 | static int if_readlist_proc(char *target) |
1112 | { | 1095 | { |
1113 | static int proc_read; | 1096 | static int proc_read; |
1114 | FILE *fh; | 1097 | FILE *fh; |
1115 | char buf[512]; | 1098 | char buf[512]; |
1116 | struct interface *ife; | 1099 | struct interface *ife; |
1117 | int err; | 1100 | int err; |
1118 | 1101 | ||
1119 | if (proc_read) | 1102 | if (proc_read) |
1120 | return 0; | 1103 | return 0; |
1121 | if (!target) | 1104 | if (!target) |
1122 | proc_read = 1; | 1105 | proc_read = 1; |
1123 | 1106 | ||
1124 | fh = fopen(_PATH_PROCNET_DEV, "r"); | 1107 | fh = fopen(_PATH_PROCNET_DEV, "r"); |
1125 | if (!fh) { | 1108 | if (!fh) { |
1126 | fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"), | 1109 | fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"), |
1127 | _PATH_PROCNET_DEV, strerror(errno)); | 1110 | _PATH_PROCNET_DEV, strerror(errno)); |
1128 | return if_readconf(); | 1111 | return if_readconf(); |
1129 | } | 1112 | } |
1130 | fgets(buf, sizeof buf, fh); /* eat line */ | 1113 | fgets(buf, sizeof buf, fh); /* eat line */ |
1131 | fgets(buf, sizeof buf, fh); | 1114 | fgets(buf, sizeof buf, fh); |
1132 | 1115 | ||
1133 | #if 0 /* pretty, but can't cope with missing fields */ | 1116 | #if 0 /* pretty, but can't cope with missing fields */ |
1134 | fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh, | 1117 | fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh, "face", "", /* parsed separately */ |
1135 | "face", "", /* parsed separately */ | 1118 | "bytes", "%lu", |
1136 | "bytes", "%lu", | 1119 | "packets", "%lu", |
1137 | "packets", "%lu", | 1120 | "errs", "%lu", |
1138 | "errs", "%lu", | 1121 | "drop", "%lu", |
1139 | "drop", "%lu", | 1122 | "fifo", "%lu", |
1140 | "fifo", "%lu", | 1123 | "frame", "%lu", |
1141 | "frame", "%lu", | 1124 | "compressed", "%lu", |
1142 | "compressed", "%lu", | 1125 | "multicast", "%lu", |
1143 | "multicast", "%lu", | 1126 | "bytes", "%lu", |
1144 | "bytes", "%lu", | 1127 | "packets", "%lu", |
1145 | "packets", "%lu", | 1128 | "errs", "%lu", |
1146 | "errs", "%lu", | 1129 | "drop", "%lu", |
1147 | "drop", "%lu", | 1130 | "fifo", "%lu", |
1148 | "fifo", "%lu", | 1131 | "colls", "%lu", |
1149 | "colls", "%lu", | 1132 | "carrier", "%lu", "compressed", "%lu", NULL); |
1150 | "carrier", "%lu", | 1133 | if (!fmt) |
1151 | "compressed", "%lu", | 1134 | return -1; |
1152 | NULL); | ||
1153 | if (!fmt) | ||
1154 | return -1; | ||
1155 | #else | 1135 | #else |
1156 | procnetdev_vsn = procnetdev_version(buf); | 1136 | procnetdev_vsn = procnetdev_version(buf); |
1157 | #endif | 1137 | #endif |
1158 | 1138 | ||
1159 | err = 0; | 1139 | err = 0; |
1160 | while (fgets(buf, sizeof buf, fh)) { | 1140 | while (fgets(buf, sizeof buf, fh)) { |
1161 | char *s, name[IFNAMSIZ]; | 1141 | char *s, name[IFNAMSIZ]; |
1162 | s = get_name(name, buf); | ||
1163 | ife = add_interface(name); | ||
1164 | get_dev_fields(s, ife); | ||
1165 | ife->statistics_valid = 1; | ||
1166 | if (target && !strcmp(target,name)) | ||
1167 | break; | ||
1168 | } | ||
1169 | if (ferror(fh)) { | ||
1170 | perror(_PATH_PROCNET_DEV); | ||
1171 | err = -1; | ||
1172 | proc_read = 0; | ||
1173 | } | ||
1174 | 1142 | ||
1143 | s = get_name(name, buf); | ||
1144 | ife = add_interface(name); | ||
1145 | get_dev_fields(s, ife); | ||
1146 | ife->statistics_valid = 1; | ||
1147 | if (target && !strcmp(target, name)) | ||
1148 | break; | ||
1149 | } | ||
1150 | if (ferror(fh)) { | ||
1151 | perror(_PATH_PROCNET_DEV); | ||
1152 | err = -1; | ||
1153 | proc_read = 0; | ||
1154 | } | ||
1175 | #if 0 | 1155 | #if 0 |
1176 | free(fmt); | 1156 | free(fmt); |
1177 | #endif | 1157 | #endif |
1178 | fclose(fh); | 1158 | fclose(fh); |
1179 | return err; | 1159 | return err; |
1180 | } | 1160 | } |
1181 | 1161 | ||
1182 | static int if_readlist(void) | 1162 | static int if_readlist(void) |
1183 | { | 1163 | { |
1184 | int err = if_readlist_proc(NULL); | 1164 | int err = if_readlist_proc(NULL); |
1185 | if (!err) | 1165 | |
1186 | err = if_readconf(); | 1166 | if (!err) |
1187 | return err; | 1167 | err = if_readconf(); |
1188 | } | 1168 | return err; |
1169 | } | ||
1189 | 1170 | ||
1190 | static int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie) | 1171 | static int for_all_interfaces(int (*doit) (struct interface *, void *), |
1172 | void *cookie) | ||
1191 | { | 1173 | { |
1192 | struct interface *ife; | 1174 | struct interface *ife; |
1193 | 1175 | ||
1194 | if (!int_list && (if_readlist() < 0)) | 1176 | if (!int_list && (if_readlist() < 0)) |
1195 | return -1; | 1177 | return -1; |
1196 | for (ife = int_list; ife; ife = ife->next) { | 1178 | for (ife = int_list; ife; ife = ife->next) { |
1197 | int err = doit(ife, cookie); | 1179 | int err = doit(ife, cookie); |
1198 | if (err) | 1180 | |
1199 | return err; | 1181 | if (err) |
1200 | } | 1182 | return err; |
1201 | return 0; | 1183 | } |
1184 | return 0; | ||
1202 | } | 1185 | } |
1203 | 1186 | ||
1204 | /* Support for fetching an IPX address */ | 1187 | /* Support for fetching an IPX address */ |
@@ -1206,8 +1189,8 @@ static int for_all_interfaces(int (*doit) (struct interface *, void *), void *co | |||
1206 | #if HAVE_AFIPX | 1189 | #if HAVE_AFIPX |
1207 | static int ipx_getaddr(int sock, int ft, struct ifreq *ifr) | 1190 | static int ipx_getaddr(int sock, int ft, struct ifreq *ifr) |
1208 | { | 1191 | { |
1209 | ((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft; | 1192 | ((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft; |
1210 | return ioctl(sock, SIOCGIFADDR, ifr); | 1193 | return ioctl(sock, SIOCGIFADDR, ifr); |
1211 | } | 1194 | } |
1212 | #endif | 1195 | #endif |
1213 | 1196 | ||
@@ -1215,313 +1198,311 @@ static int ipx_getaddr(int sock, int ft, struct ifreq *ifr) | |||
1215 | /* Fetch the interface configuration from the kernel. */ | 1198 | /* Fetch the interface configuration from the kernel. */ |
1216 | static int if_fetch(struct interface *ife) | 1199 | static int if_fetch(struct interface *ife) |
1217 | { | 1200 | { |
1218 | struct ifreq ifr; | 1201 | struct ifreq ifr; |
1219 | int fd; | 1202 | int fd; |
1220 | char *ifname = ife->name; | 1203 | char *ifname = ife->name; |
1221 | |||
1222 | strcpy(ifr.ifr_name, ifname); | ||
1223 | if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) | ||
1224 | return (-1); | ||
1225 | ife->flags = ifr.ifr_flags; | ||
1226 | |||
1227 | strcpy(ifr.ifr_name, ifname); | ||
1228 | if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0) | ||
1229 | memset(ife->hwaddr, 0, 32); | ||
1230 | else | ||
1231 | memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8); | ||
1232 | |||
1233 | ife->type = ifr.ifr_hwaddr.sa_family; | ||
1234 | |||
1235 | strcpy(ifr.ifr_name, ifname); | ||
1236 | if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) | ||
1237 | ife->metric = 0; | ||
1238 | else | ||
1239 | ife->metric = ifr.ifr_metric; | ||
1240 | |||
1241 | strcpy(ifr.ifr_name, ifname); | ||
1242 | if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0) | ||
1243 | ife->mtu = 0; | ||
1244 | else | ||
1245 | ife->mtu = ifr.ifr_mtu; | ||
1246 | 1204 | ||
1247 | #ifdef HAVE_HWSLIP | ||
1248 | if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP || | ||
1249 | ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 || | ||
1250 | ife->type == ARPHRD_ADAPT) { | ||
1251 | #ifdef SIOCGOUTFILL | ||
1252 | strcpy(ifr.ifr_name, ifname); | 1205 | strcpy(ifr.ifr_name, ifname); |
1253 | if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0) | 1206 | if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) |
1254 | ife->outfill = 0; | 1207 | return (-1); |
1208 | ife->flags = ifr.ifr_flags; | ||
1209 | |||
1210 | strcpy(ifr.ifr_name, ifname); | ||
1211 | if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0) | ||
1212 | memset(ife->hwaddr, 0, 32); | ||
1255 | else | 1213 | else |
1256 | ife->outfill = (unsigned int) ifr.ifr_data; | 1214 | memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8); |
1257 | #endif | 1215 | |
1258 | #ifdef SIOCGKEEPALIVE | 1216 | ife->type = ifr.ifr_hwaddr.sa_family; |
1217 | |||
1218 | strcpy(ifr.ifr_name, ifname); | ||
1219 | if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) | ||
1220 | ife->metric = 0; | ||
1221 | else | ||
1222 | ife->metric = ifr.ifr_metric; | ||
1223 | |||
1259 | strcpy(ifr.ifr_name, ifname); | 1224 | strcpy(ifr.ifr_name, ifname); |
1260 | if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0) | 1225 | if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0) |
1261 | ife->keepalive = 0; | 1226 | ife->mtu = 0; |
1262 | else | 1227 | else |
1263 | ife->keepalive = (unsigned int) ifr.ifr_data; | 1228 | ife->mtu = ifr.ifr_mtu; |
1229 | |||
1230 | #ifdef HAVE_HWSLIP | ||
1231 | if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP || | ||
1232 | ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 || | ||
1233 | ife->type == ARPHRD_ADAPT) { | ||
1234 | #ifdef SIOCGOUTFILL | ||
1235 | strcpy(ifr.ifr_name, ifname); | ||
1236 | if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0) | ||
1237 | ife->outfill = 0; | ||
1238 | else | ||
1239 | ife->outfill = (unsigned int) ifr.ifr_data; | ||
1240 | #endif | ||
1241 | #ifdef SIOCGKEEPALIVE | ||
1242 | strcpy(ifr.ifr_name, ifname); | ||
1243 | if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0) | ||
1244 | ife->keepalive = 0; | ||
1245 | else | ||
1246 | ife->keepalive = (unsigned int) ifr.ifr_data; | ||
1264 | #endif | 1247 | #endif |
1265 | } | 1248 | } |
1266 | #endif | 1249 | #endif |
1267 | 1250 | ||
1268 | strcpy(ifr.ifr_name, ifname); | 1251 | strcpy(ifr.ifr_name, ifname); |
1269 | if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) | 1252 | if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) |
1270 | memset(&ife->map, 0, sizeof(struct ifmap)); | 1253 | memset(&ife->map, 0, sizeof(struct ifmap)); |
1271 | else | 1254 | else |
1272 | memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap)); | 1255 | memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap)); |
1273 | 1256 | ||
1274 | strcpy(ifr.ifr_name, ifname); | 1257 | strcpy(ifr.ifr_name, ifname); |
1275 | if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) | 1258 | if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) |
1276 | memset(&ife->map, 0, sizeof(struct ifmap)); | 1259 | memset(&ife->map, 0, sizeof(struct ifmap)); |
1277 | else | 1260 | else |
1278 | ife->map = ifr.ifr_map; | 1261 | ife->map = ifr.ifr_map; |
1279 | 1262 | ||
1280 | #ifdef HAVE_TXQUEUELEN | 1263 | #ifdef HAVE_TXQUEUELEN |
1281 | strcpy(ifr.ifr_name, ifname); | 1264 | strcpy(ifr.ifr_name, ifname); |
1282 | if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0) | 1265 | if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0) |
1283 | ife->tx_queue_len = -1; /* unknown value */ | 1266 | ife->tx_queue_len = -1; /* unknown value */ |
1284 | else | 1267 | else |
1285 | ife->tx_queue_len = ifr.ifr_qlen; | 1268 | ife->tx_queue_len = ifr.ifr_qlen; |
1286 | #else | 1269 | #else |
1287 | ife->tx_queue_len = -1; /* unknown value */ | 1270 | ife->tx_queue_len = -1; /* unknown value */ |
1288 | #endif | 1271 | #endif |
1289 | 1272 | ||
1290 | #if HAVE_AFINET | 1273 | #if HAVE_AFINET |
1291 | /* IPv4 address? */ | 1274 | /* IPv4 address? */ |
1292 | fd = get_socket_for_af(AF_INET); | 1275 | fd = get_socket_for_af(AF_INET); |
1293 | if (fd >= 0) { | 1276 | if (fd >= 0) { |
1294 | strcpy(ifr.ifr_name, ifname); | 1277 | strcpy(ifr.ifr_name, ifname); |
1295 | ifr.ifr_addr.sa_family = AF_INET; | 1278 | ifr.ifr_addr.sa_family = AF_INET; |
1296 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { | 1279 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
1297 | ife->has_ip = 1; | 1280 | ife->has_ip = 1; |
1298 | ife->addr = ifr.ifr_addr; | 1281 | ife->addr = ifr.ifr_addr; |
1299 | strcpy(ifr.ifr_name, ifname); | 1282 | strcpy(ifr.ifr_name, ifname); |
1300 | if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0) | 1283 | if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0) |
1301 | memset(&ife->dstaddr, 0, sizeof(struct sockaddr)); | 1284 | memset(&ife->dstaddr, 0, sizeof(struct sockaddr)); |
1302 | else | 1285 | else |
1303 | ife->dstaddr = ifr.ifr_dstaddr; | 1286 | ife->dstaddr = ifr.ifr_dstaddr; |
1304 | 1287 | ||
1305 | strcpy(ifr.ifr_name, ifname); | 1288 | strcpy(ifr.ifr_name, ifname); |
1306 | if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) | 1289 | if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) |
1307 | memset(&ife->broadaddr, 0, sizeof(struct sockaddr)); | 1290 | memset(&ife->broadaddr, 0, sizeof(struct sockaddr)); |
1308 | else | 1291 | else |
1309 | ife->broadaddr = ifr.ifr_broadaddr; | 1292 | ife->broadaddr = ifr.ifr_broadaddr; |
1310 | 1293 | ||
1311 | strcpy(ifr.ifr_name, ifname); | 1294 | strcpy(ifr.ifr_name, ifname); |
1312 | if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) | 1295 | if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) |
1313 | memset(&ife->netmask, 0, sizeof(struct sockaddr)); | 1296 | memset(&ife->netmask, 0, sizeof(struct sockaddr)); |
1314 | else | 1297 | else |
1315 | ife->netmask = ifr.ifr_netmask; | 1298 | ife->netmask = ifr.ifr_netmask; |
1316 | } else | 1299 | } else |
1317 | memset(&ife->addr, 0, sizeof(struct sockaddr)); | 1300 | memset(&ife->addr, 0, sizeof(struct sockaddr)); |
1318 | } | 1301 | } |
1319 | #endif | 1302 | #endif |
1320 | 1303 | ||
1321 | #if HAVE_AFATALK | 1304 | #if HAVE_AFATALK |
1322 | /* DDP address maybe ? */ | 1305 | /* DDP address maybe ? */ |
1323 | fd = get_socket_for_af(AF_APPLETALK); | 1306 | fd = get_socket_for_af(AF_APPLETALK); |
1324 | if (fd >= 0) { | 1307 | if (fd >= 0) { |
1325 | strcpy(ifr.ifr_name, ifname); | 1308 | strcpy(ifr.ifr_name, ifname); |
1326 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { | 1309 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
1327 | ife->ddpaddr = ifr.ifr_addr; | 1310 | ife->ddpaddr = ifr.ifr_addr; |
1328 | ife->has_ddp = 1; | 1311 | ife->has_ddp = 1; |
1312 | } | ||
1329 | } | 1313 | } |
1330 | } | ||
1331 | #endif | 1314 | #endif |
1332 | 1315 | ||
1333 | #if HAVE_AFIPX | 1316 | #if HAVE_AFIPX |
1334 | /* Look for IPX addresses with all framing types */ | 1317 | /* Look for IPX addresses with all framing types */ |
1335 | fd = get_socket_for_af(AF_IPX); | 1318 | fd = get_socket_for_af(AF_IPX); |
1336 | if (fd >= 0) { | 1319 | if (fd >= 0) { |
1337 | strcpy(ifr.ifr_name, ifname); | 1320 | strcpy(ifr.ifr_name, ifname); |
1338 | if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) { | 1321 | if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) { |
1339 | ife->has_ipx_bb = 1; | 1322 | ife->has_ipx_bb = 1; |
1340 | ife->ipxaddr_bb = ifr.ifr_addr; | 1323 | ife->ipxaddr_bb = ifr.ifr_addr; |
1341 | } | 1324 | } |
1342 | strcpy(ifr.ifr_name, ifname); | 1325 | strcpy(ifr.ifr_name, ifname); |
1343 | if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) { | 1326 | if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) { |
1344 | ife->has_ipx_sn = 1; | 1327 | ife->has_ipx_sn = 1; |
1345 | ife->ipxaddr_sn = ifr.ifr_addr; | 1328 | ife->ipxaddr_sn = ifr.ifr_addr; |
1346 | } | 1329 | } |
1347 | strcpy(ifr.ifr_name, ifname); | 1330 | strcpy(ifr.ifr_name, ifname); |
1348 | if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) { | 1331 | if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) { |
1349 | ife->has_ipx_e3 = 1; | 1332 | ife->has_ipx_e3 = 1; |
1350 | ife->ipxaddr_e3 = ifr.ifr_addr; | 1333 | ife->ipxaddr_e3 = ifr.ifr_addr; |
1351 | } | 1334 | } |
1352 | strcpy(ifr.ifr_name, ifname); | 1335 | strcpy(ifr.ifr_name, ifname); |
1353 | if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) { | 1336 | if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) { |
1354 | ife->has_ipx_e2 = 1; | 1337 | ife->has_ipx_e2 = 1; |
1355 | ife->ipxaddr_e2 = ifr.ifr_addr; | 1338 | ife->ipxaddr_e2 = ifr.ifr_addr; |
1339 | } | ||
1356 | } | 1340 | } |
1357 | } | ||
1358 | #endif | 1341 | #endif |
1359 | 1342 | ||
1360 | #if HAVE_AFECONET | 1343 | #if HAVE_AFECONET |
1361 | /* Econet address maybe? */ | 1344 | /* Econet address maybe? */ |
1362 | fd = get_socket_for_af(AF_ECONET); | 1345 | fd = get_socket_for_af(AF_ECONET); |
1363 | if (fd >= 0) { | 1346 | if (fd >= 0) { |
1364 | strcpy(ifr.ifr_name, ifname); | 1347 | strcpy(ifr.ifr_name, ifname); |
1365 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { | 1348 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
1366 | ife->ecaddr = ifr.ifr_addr; | 1349 | ife->ecaddr = ifr.ifr_addr; |
1367 | ife->has_econet = 1; | 1350 | ife->has_econet = 1; |
1351 | } | ||
1368 | } | 1352 | } |
1369 | } | ||
1370 | #endif | 1353 | #endif |
1371 | 1354 | ||
1372 | return 0; | 1355 | return 0; |
1373 | } | 1356 | } |
1374 | 1357 | ||
1375 | 1358 | ||
1376 | static int do_if_fetch(struct interface *ife) | 1359 | static int do_if_fetch(struct interface *ife) |
1377 | { | 1360 | { |
1378 | if (if_fetch(ife) < 0) { | 1361 | if (if_fetch(ife) < 0) { |
1379 | char *errmsg; | 1362 | char *errmsg; |
1380 | if (errno == ENODEV) { | 1363 | |
1381 | /* Give better error message for this case. */ | 1364 | if (errno == ENODEV) { |
1382 | errmsg = _("Device not found"); | 1365 | /* Give better error message for this case. */ |
1383 | } else { | 1366 | errmsg = _("Device not found"); |
1384 | errmsg = strerror(errno); | 1367 | } else { |
1368 | errmsg = strerror(errno); | ||
1369 | } | ||
1370 | fprintf(stderr, _("%s: error fetching interface information: %s\n"), | ||
1371 | ife->name, errmsg); | ||
1372 | return -1; | ||
1385 | } | 1373 | } |
1386 | fprintf(stderr, _("%s: error fetching interface information: %s\n"), | 1374 | return 0; |
1387 | ife->name, errmsg); | ||
1388 | return -1; | ||
1389 | } | ||
1390 | return 0; | ||
1391 | } | 1375 | } |
1392 | 1376 | ||
1393 | /* This structure defines hardware protocols and their handlers. */ | 1377 | /* This structure defines hardware protocols and their handlers. */ |
1394 | struct hwtype { | 1378 | struct hwtype { |
1395 | const char *name; | 1379 | const char *name; |
1396 | const char *title; | 1380 | const char *title; |
1397 | int type; | 1381 | int type; |
1398 | int alen; | 1382 | int alen; |
1399 | char *(*print) (unsigned char *); | 1383 | char *(*print) (unsigned char *); |
1400 | int (*input) (char *, struct sockaddr *); | 1384 | int (*input) (char *, struct sockaddr *); |
1401 | int (*activate) (int fd); | 1385 | int (*activate) (int fd); |
1402 | int suppress_null_addr; | 1386 | int suppress_null_addr; |
1403 | }; | 1387 | }; |
1404 | 1388 | ||
1405 | static struct hwtype unspec_hwtype = | 1389 | static struct hwtype unspec_hwtype = { |
1406 | { | 1390 | "unspec", "UNSPEC", -1, 0, |
1407 | "unspec", "UNSPEC", -1, 0, | 1391 | UNSPEC_print, NULL, NULL |
1408 | UNSPEC_print, NULL, NULL | ||
1409 | }; | 1392 | }; |
1410 | 1393 | ||
1411 | static struct hwtype loop_hwtype = | 1394 | static struct hwtype loop_hwtype = { |
1412 | { | 1395 | "loop", "Local Loopback", ARPHRD_LOOPBACK, 0, |
1413 | "loop", "Local Loopback", ARPHRD_LOOPBACK, 0, | 1396 | NULL, NULL, NULL |
1414 | NULL, NULL, NULL | ||
1415 | }; | 1397 | }; |
1416 | 1398 | ||
1417 | #if HAVE_HWETHER | 1399 | #if HAVE_HWETHER |
1418 | #include <net/if_arp.h> | 1400 | #include <net/if_arp.h> |
1419 | #include <linux/if_ether.h> | 1401 | #include <linux/if_ether.h> |
1420 | 1402 | ||
1421 | static struct hwtype ether_hwtype; | ||
1422 | |||
1423 | /* Display an Ethernet address in readable format. */ | 1403 | /* Display an Ethernet address in readable format. */ |
1424 | static char *pr_ether(unsigned char *ptr) | 1404 | static char *pr_ether(unsigned char *ptr) |
1425 | { | 1405 | { |
1426 | static char buff[64]; | 1406 | static char buff[64]; |
1427 | 1407 | ||
1428 | snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", | 1408 | snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", |
1429 | (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), | 1409 | (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
1430 | (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) | 1410 | (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
1431 | ); | 1411 | ); |
1432 | return (buff); | 1412 | return (buff); |
1433 | } | 1413 | } |
1434 | 1414 | ||
1435 | #ifdef KEEP_UNUSED | 1415 | #ifdef KEEP_UNUSED |
1436 | /* Input an Ethernet address and convert to binary. */ | 1416 | /* Input an Ethernet address and convert to binary. */ |
1437 | static int in_ether(char *bufp, struct sockaddr *sap) | 1417 | static int in_ether(char *bufp, struct sockaddr *sap) |
1438 | { | 1418 | { |
1439 | unsigned char *ptr; | 1419 | unsigned char *ptr; |
1440 | char c, *orig; | 1420 | char c, *orig; |
1441 | int i; | 1421 | int i; |
1442 | unsigned val; | 1422 | unsigned val; |
1443 | 1423 | ||
1444 | sap->sa_family = ether_hwtype.type; | 1424 | sap->sa_family = ether_hwtype.type; |
1445 | ptr = sap->sa_data; | 1425 | ptr = sap->sa_data; |
1446 | 1426 | ||
1447 | i = 0; | 1427 | i = 0; |
1448 | orig = bufp; | 1428 | orig = bufp; |
1449 | while ((*bufp != '\0') && (i < ETH_ALEN)) { | 1429 | while ((*bufp != '\0') && (i < ETH_ALEN)) { |
1450 | val = 0; | 1430 | val = 0; |
1451 | c = *bufp++; | 1431 | c = *bufp++; |
1452 | if (isdigit(c)) | 1432 | if (isdigit(c)) |
1453 | val = c - '0'; | 1433 | val = c - '0'; |
1454 | else if (c >= 'a' && c <= 'f') | 1434 | else if (c >= 'a' && c <= 'f') |
1455 | val = c - 'a' + 10; | 1435 | val = c - 'a' + 10; |
1456 | else if (c >= 'A' && c <= 'F') | 1436 | else if (c >= 'A' && c <= 'F') |
1457 | val = c - 'A' + 10; | 1437 | val = c - 'A' + 10; |
1458 | else { | 1438 | else { |
1459 | #ifdef DEBUG | 1439 | #ifdef DEBUG |
1460 | fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); | 1440 | fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), |
1441 | orig); | ||
1461 | #endif | 1442 | #endif |
1462 | errno = EINVAL; | 1443 | errno = EINVAL; |
1463 | return (-1); | 1444 | return (-1); |
1464 | } | 1445 | } |
1465 | val <<= 4; | 1446 | val <<= 4; |
1466 | c = *bufp; | 1447 | c = *bufp; |
1467 | if (isdigit(c)) | 1448 | if (isdigit(c)) |
1468 | val |= c - '0'; | 1449 | val |= c - '0'; |
1469 | else if (c >= 'a' && c <= 'f') | 1450 | else if (c >= 'a' && c <= 'f') |
1470 | val |= c - 'a' + 10; | 1451 | val |= c - 'a' + 10; |
1471 | else if (c >= 'A' && c <= 'F') | 1452 | else if (c >= 'A' && c <= 'F') |
1472 | val |= c - 'A' + 10; | 1453 | val |= c - 'A' + 10; |
1473 | else if (c == ':' || c == 0) | 1454 | else if (c == ':' || c == 0) |
1474 | val >>= 4; | 1455 | val >>= 4; |
1475 | else { | 1456 | else { |
1476 | #ifdef DEBUG | 1457 | #ifdef DEBUG |
1477 | fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); | 1458 | fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), |
1459 | orig); | ||
1478 | #endif | 1460 | #endif |
1479 | errno = EINVAL; | 1461 | errno = EINVAL; |
1480 | return (-1); | 1462 | return (-1); |
1481 | } | 1463 | } |
1482 | if (c != 0) | 1464 | if (c != 0) |
1483 | bufp++; | 1465 | bufp++; |
1484 | *ptr++ = (unsigned char) (val & 0377); | 1466 | *ptr++ = (unsigned char) (val & 0377); |
1485 | i++; | 1467 | i++; |
1486 | 1468 | ||
1487 | /* We might get a semicolon here - not required. */ | 1469 | /* We might get a semicolon here - not required. */ |
1488 | if (*bufp == ':') { | 1470 | if (*bufp == ':') { |
1489 | if (i == ETH_ALEN) { | 1471 | if (i == ETH_ALEN) { |
1490 | #ifdef DEBUG | 1472 | #ifdef DEBUG |
1491 | fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"), | 1473 | fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"), |
1492 | orig) | 1474 | orig) |
1493 | #endif | 1475 | #endif |
1494 | ; /* nothing */ | 1476 | ; /* nothing */ |
1495 | } | 1477 | } |
1496 | bufp++; | 1478 | bufp++; |
1479 | } | ||
1497 | } | 1480 | } |
1498 | } | ||
1499 | 1481 | ||
1500 | /* That's it. Any trailing junk? */ | 1482 | /* That's it. Any trailing junk? */ |
1501 | if ((i == ETH_ALEN) && (*bufp != '\0')) { | 1483 | if ((i == ETH_ALEN) && (*bufp != '\0')) { |
1502 | #ifdef DEBUG | 1484 | #ifdef DEBUG |
1503 | fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig); | 1485 | fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig); |
1504 | errno = EINVAL; | 1486 | errno = EINVAL; |
1505 | return (-1); | 1487 | return (-1); |
1506 | #endif | 1488 | #endif |
1507 | } | 1489 | } |
1508 | #ifdef DEBUG | 1490 | #ifdef DEBUG |
1509 | fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data)); | 1491 | fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data)); |
1510 | #endif | 1492 | #endif |
1511 | 1493 | ||
1512 | return (0); | 1494 | return (0); |
1513 | } | 1495 | } |
1514 | #endif /* KEEP_UNUSED */ | 1496 | #endif /* KEEP_UNUSED */ |
1515 | 1497 | ||
1516 | 1498 | ||
1517 | static struct hwtype ether_hwtype = | 1499 | static struct hwtype ether_hwtype = { |
1518 | { | 1500 | "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN, |
1519 | "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN, | 1501 | pr_ether, NULL /* UNUSED in_ether */ , NULL |
1520 | pr_ether, NULL /* UNUSED in_ether */, NULL | ||
1521 | }; | 1502 | }; |
1522 | 1503 | ||
1523 | 1504 | ||
1524 | #endif /* HAVE_HWETHER */ | 1505 | #endif /* HAVE_HWETHER */ |
1525 | 1506 | ||
1526 | 1507 | ||
1527 | #if HAVE_HWPPP | 1508 | #if HAVE_HWPPP |
@@ -1532,93 +1513,91 @@ static struct hwtype ether_hwtype = | |||
1532 | /* Start the PPP encapsulation on the file descriptor. */ | 1513 | /* Start the PPP encapsulation on the file descriptor. */ |
1533 | static int do_ppp(int fd) | 1514 | static int do_ppp(int fd) |
1534 | { | 1515 | { |
1535 | fprintf(stderr, _("You cannot start PPP with this program.\n")); | 1516 | fprintf(stderr, _("You cannot start PPP with this program.\n")); |
1536 | return -1; | 1517 | return -1; |
1537 | } | 1518 | } |
1538 | #endif /* KEEP_UNUSED */ | 1519 | #endif /* KEEP_UNUSED */ |
1539 | 1520 | ||
1540 | static struct hwtype ppp_hwtype = | 1521 | static struct hwtype ppp_hwtype = { |
1541 | { | 1522 | "ppp", "Point-Point Protocol", ARPHRD_PPP, 0, |
1542 | "ppp", "Point-Point Protocol", ARPHRD_PPP, 0, | 1523 | NULL, NULL, NULL /* UNUSED do_ppp */ , 0 |
1543 | NULL, NULL, NULL /* UNUSED do_ppp */, 0 | ||
1544 | }; | 1524 | }; |
1545 | 1525 | ||
1546 | 1526 | ||
1547 | #endif /* HAVE_PPP */ | 1527 | #endif /* HAVE_PPP */ |
1548 | 1528 | ||
1549 | static struct hwtype *hwtypes[] = | 1529 | static struct hwtype *hwtypes[] = { |
1550 | { | ||
1551 | 1530 | ||
1552 | &loop_hwtype, | 1531 | &loop_hwtype, |
1553 | 1532 | ||
1554 | #if HAVE_HWSLIP | 1533 | #if HAVE_HWSLIP |
1555 | &slip_hwtype, | 1534 | &slip_hwtype, |
1556 | &cslip_hwtype, | 1535 | &cslip_hwtype, |
1557 | &slip6_hwtype, | 1536 | &slip6_hwtype, |
1558 | &cslip6_hwtype, | 1537 | &cslip6_hwtype, |
1559 | &adaptive_hwtype, | 1538 | &adaptive_hwtype, |
1560 | #endif | 1539 | #endif |
1561 | #if HAVE_HWSTRIP | 1540 | #if HAVE_HWSTRIP |
1562 | &strip_hwtype, | 1541 | &strip_hwtype, |
1563 | #endif | 1542 | #endif |
1564 | #if HAVE_HWASH | 1543 | #if HAVE_HWASH |
1565 | &ash_hwtype, | 1544 | &ash_hwtype, |
1566 | #endif | 1545 | #endif |
1567 | #if HAVE_HWETHER | 1546 | #if HAVE_HWETHER |
1568 | ðer_hwtype, | 1547 | ðer_hwtype, |
1569 | #endif | 1548 | #endif |
1570 | #if HAVE_HWTR | 1549 | #if HAVE_HWTR |
1571 | &tr_hwtype, | 1550 | &tr_hwtype, |
1572 | #ifdef ARPHRD_IEEE802_TR | 1551 | #ifdef ARPHRD_IEEE802_TR |
1573 | &tr_hwtype1, | 1552 | &tr_hwtype1, |
1574 | #endif | 1553 | #endif |
1575 | #endif | 1554 | #endif |
1576 | #if HAVE_HWAX25 | 1555 | #if HAVE_HWAX25 |
1577 | &ax25_hwtype, | 1556 | &ax25_hwtype, |
1578 | #endif | 1557 | #endif |
1579 | #if HAVE_HWNETROM | 1558 | #if HAVE_HWNETROM |
1580 | &netrom_hwtype, | 1559 | &netrom_hwtype, |
1581 | #endif | 1560 | #endif |
1582 | #if HAVE_HWROSE | 1561 | #if HAVE_HWROSE |
1583 | &rose_hwtype, | 1562 | &rose_hwtype, |
1584 | #endif | 1563 | #endif |
1585 | #if HAVE_HWTUNNEL | 1564 | #if HAVE_HWTUNNEL |
1586 | &tunnel_hwtype, | 1565 | &tunnel_hwtype, |
1587 | #endif | 1566 | #endif |
1588 | #if HAVE_HWPPP | 1567 | #if HAVE_HWPPP |
1589 | &ppp_hwtype, | 1568 | &ppp_hwtype, |
1590 | #endif | 1569 | #endif |
1591 | #if HAVE_HWHDLCLAPB | 1570 | #if HAVE_HWHDLCLAPB |
1592 | &hdlc_hwtype, | 1571 | &hdlc_hwtype, |
1593 | &lapb_hwtype, | 1572 | &lapb_hwtype, |
1594 | #endif | 1573 | #endif |
1595 | #if HAVE_HWARC | 1574 | #if HAVE_HWARC |
1596 | &arcnet_hwtype, | 1575 | &arcnet_hwtype, |
1597 | #endif | 1576 | #endif |
1598 | #if HAVE_HWFR | 1577 | #if HAVE_HWFR |
1599 | &dlci_hwtype, | 1578 | &dlci_hwtype, |
1600 | &frad_hwtype, | 1579 | &frad_hwtype, |
1601 | #endif | 1580 | #endif |
1602 | #if HAVE_HWSIT | 1581 | #if HAVE_HWSIT |
1603 | &sit_hwtype, | 1582 | &sit_hwtype, |
1604 | #endif | 1583 | #endif |
1605 | #if HAVE_HWFDDI | 1584 | #if HAVE_HWFDDI |
1606 | &fddi_hwtype, | 1585 | &fddi_hwtype, |
1607 | #endif | 1586 | #endif |
1608 | #if HAVE_HWHIPPI | 1587 | #if HAVE_HWHIPPI |
1609 | &hippi_hwtype, | 1588 | &hippi_hwtype, |
1610 | #endif | 1589 | #endif |
1611 | #if HAVE_HWIRDA | 1590 | #if HAVE_HWIRDA |
1612 | &irda_hwtype, | 1591 | &irda_hwtype, |
1613 | #endif | 1592 | #endif |
1614 | #if HAVE_HWEC | 1593 | #if HAVE_HWEC |
1615 | &ec_hwtype, | 1594 | &ec_hwtype, |
1616 | #endif | 1595 | #endif |
1617 | #if HAVE_HWX25 | 1596 | #if HAVE_HWX25 |
1618 | &x25_hwtype, | 1597 | &x25_hwtype, |
1619 | #endif | 1598 | #endif |
1620 | &unspec_hwtype, | 1599 | &unspec_hwtype, |
1621 | NULL | 1600 | NULL |
1622 | }; | 1601 | }; |
1623 | 1602 | ||
1624 | #ifdef KEEP_UNUSED | 1603 | #ifdef KEEP_UNUSED |
@@ -1626,118 +1605,118 @@ static short sVhwinit = 0; | |||
1626 | 1605 | ||
1627 | static void hwinit() | 1606 | static void hwinit() |
1628 | { | 1607 | { |
1629 | loop_hwtype.title = _("Local Loopback"); | 1608 | loop_hwtype.title = _("Local Loopback"); |
1630 | unspec_hwtype.title = _("UNSPEC"); | 1609 | unspec_hwtype.title = _("UNSPEC"); |
1631 | #if HAVE_HWSLIP | 1610 | #if HAVE_HWSLIP |
1632 | slip_hwtype.title = _("Serial Line IP"); | 1611 | slip_hwtype.title = _("Serial Line IP"); |
1633 | cslip_hwtype.title = _("VJ Serial Line IP"); | 1612 | cslip_hwtype.title = _("VJ Serial Line IP"); |
1634 | slip6_hwtype.title = _("6-bit Serial Line IP"); | 1613 | slip6_hwtype.title = _("6-bit Serial Line IP"); |
1635 | cslip6_hwtype.title = _("VJ 6-bit Serial Line IP"); | 1614 | cslip6_hwtype.title = _("VJ 6-bit Serial Line IP"); |
1636 | adaptive_hwtype.title = _("Adaptive Serial Line IP"); | 1615 | adaptive_hwtype.title = _("Adaptive Serial Line IP"); |
1637 | #endif | 1616 | #endif |
1638 | #if HAVE_HWETHER | 1617 | #if HAVE_HWETHER |
1639 | ether_hwtype.title = _("Ethernet"); | 1618 | ether_hwtype.title = _("Ethernet"); |
1640 | #endif | 1619 | #endif |
1641 | #if HAVE_HWASH | 1620 | #if HAVE_HWASH |
1642 | ash_hwtype.title = _("Ash"); | 1621 | ash_hwtype.title = _("Ash"); |
1643 | #endif | 1622 | #endif |
1644 | #if HAVE_HWFDDI | 1623 | #if HAVE_HWFDDI |
1645 | fddi_hwtype.title = _("Fiber Distributed Data Interface"); | 1624 | fddi_hwtype.title = _("Fiber Distributed Data Interface"); |
1646 | #endif | 1625 | #endif |
1647 | #if HAVE_HWHIPPI | 1626 | #if HAVE_HWHIPPI |
1648 | hippi_hwtype.title = _("HIPPI"); | 1627 | hippi_hwtype.title = _("HIPPI"); |
1649 | #endif | 1628 | #endif |
1650 | #if HAVE_HWAX25 | 1629 | #if HAVE_HWAX25 |
1651 | ax25_hwtype.title = _("AMPR AX.25"); | 1630 | ax25_hwtype.title = _("AMPR AX.25"); |
1652 | #endif | 1631 | #endif |
1653 | #if HAVE_HWROSE | 1632 | #if HAVE_HWROSE |
1654 | rose_hwtype.title = _("AMPR ROSE"); | 1633 | rose_hwtype.title = _("AMPR ROSE"); |
1655 | #endif | 1634 | #endif |
1656 | #if HAVE_HWNETROM | 1635 | #if HAVE_HWNETROM |
1657 | netrom_hwtype.title = _("AMPR NET/ROM"); | 1636 | netrom_hwtype.title = _("AMPR NET/ROM"); |
1658 | #endif | 1637 | #endif |
1659 | #if HAVE_HWX25 | 1638 | #if HAVE_HWX25 |
1660 | x25_hwtype.title = _("generic X.25"); | 1639 | x25_hwtype.title = _("generic X.25"); |
1661 | #endif | 1640 | #endif |
1662 | #if HAVE_HWTUNNEL | 1641 | #if HAVE_HWTUNNEL |
1663 | tunnel_hwtype.title = _("IPIP Tunnel"); | 1642 | tunnel_hwtype.title = _("IPIP Tunnel"); |
1664 | #endif | 1643 | #endif |
1665 | #if HAVE_HWPPP | 1644 | #if HAVE_HWPPP |
1666 | ppp_hwtype.title = _("Point-to-Point Protocol"); | 1645 | ppp_hwtype.title = _("Point-to-Point Protocol"); |
1667 | #endif | 1646 | #endif |
1668 | #if HAVE_HWHDLCLAPB | 1647 | #if HAVE_HWHDLCLAPB |
1669 | hdlc_hwtype.title = _("(Cisco)-HDLC"); | 1648 | hdlc_hwtype.title = _("(Cisco)-HDLC"); |
1670 | lapb_hwtype.title = _("LAPB"); | 1649 | lapb_hwtype.title = _("LAPB"); |
1671 | #endif | 1650 | #endif |
1672 | #if HAVE_HWARC | 1651 | #if HAVE_HWARC |
1673 | arcnet_hwtype.title = _("ARCnet"); | 1652 | arcnet_hwtype.title = _("ARCnet"); |
1674 | #endif | 1653 | #endif |
1675 | #if HAVE_HWFR | 1654 | #if HAVE_HWFR |
1676 | dlci_hwtype.title = _("Frame Relay DLCI"); | 1655 | dlci_hwtype.title = _("Frame Relay DLCI"); |
1677 | frad_hwtype.title = _("Frame Relay Access Device"); | 1656 | frad_hwtype.title = _("Frame Relay Access Device"); |
1678 | #endif | 1657 | #endif |
1679 | #if HAVE_HWSIT | 1658 | #if HAVE_HWSIT |
1680 | sit_hwtype.title = _("IPv6-in-IPv4"); | 1659 | sit_hwtype.title = _("IPv6-in-IPv4"); |
1681 | #endif | 1660 | #endif |
1682 | #if HAVE_HWIRDA | 1661 | #if HAVE_HWIRDA |
1683 | irda_hwtype.title = _("IrLAP"); | 1662 | irda_hwtype.title = _("IrLAP"); |
1684 | #endif | 1663 | #endif |
1685 | #if HAVE_HWTR | 1664 | #if HAVE_HWTR |
1686 | tr_hwtype.title = _("16/4 Mbps Token Ring"); | 1665 | tr_hwtype.title = _("16/4 Mbps Token Ring"); |
1687 | #ifdef ARPHRD_IEEE802_TR | 1666 | #ifdef ARPHRD_IEEE802_TR |
1688 | tr_hwtype1.title = _("16/4 Mbps Token Ring (New)") ; | 1667 | tr_hwtype1.title = _("16/4 Mbps Token Ring (New)"); |
1689 | #endif | 1668 | #endif |
1690 | #endif | 1669 | #endif |
1691 | #if HAVE_HWEC | 1670 | #if HAVE_HWEC |
1692 | ec_hwtype.title = _("Econet"); | 1671 | ec_hwtype.title = _("Econet"); |
1693 | #endif | 1672 | #endif |
1694 | sVhwinit = 1; | 1673 | sVhwinit = 1; |
1695 | } | 1674 | } |
1696 | #endif /* KEEP_UNUSED */ | 1675 | #endif /* KEEP_UNUSED */ |
1697 | 1676 | ||
1698 | #ifdef IFF_PORTSEL | 1677 | #ifdef IFF_PORTSEL |
1699 | static const char *if_port_text[][4] = | 1678 | static const char *if_port_text[][4] = { |
1700 | { | 1679 | /* Keep in step with <linux/netdevice.h> */ |
1701 | /* Keep in step with <linux/netdevice.h> */ | 1680 | {"unknown", NULL, NULL, NULL}, |
1702 | {"unknown", NULL, NULL, NULL}, | 1681 | {"10base2", "bnc", "coax", NULL}, |
1703 | {"10base2", "bnc", "coax", NULL}, | 1682 | {"10baseT", "utp", "tpe", NULL}, |
1704 | {"10baseT", "utp", "tpe", NULL}, | 1683 | {"AUI", "thick", "db15", NULL}, |
1705 | {"AUI", "thick", "db15", NULL}, | 1684 | {"100baseT", NULL, NULL, NULL}, |
1706 | {"100baseT", NULL, NULL, NULL}, | 1685 | {"100baseTX", NULL, NULL, NULL}, |
1707 | {"100baseTX", NULL, NULL, NULL}, | 1686 | {"100baseFX", NULL, NULL, NULL}, |
1708 | {"100baseFX", NULL, NULL, NULL}, | 1687 | {NULL, NULL, NULL, NULL}, |
1709 | {NULL, NULL, NULL, NULL}, | ||
1710 | }; | 1688 | }; |
1711 | #endif | 1689 | #endif |
1712 | 1690 | ||
1713 | /* Check our hardware type table for this type. */ | 1691 | /* Check our hardware type table for this type. */ |
1714 | static struct hwtype *get_hwntype(int type) | 1692 | static struct hwtype *get_hwntype(int type) |
1715 | { | 1693 | { |
1716 | struct hwtype **hwp; | 1694 | struct hwtype **hwp; |
1717 | 1695 | ||
1718 | #ifdef KEEP_UNUSED | 1696 | #ifdef KEEP_UNUSED |
1719 | if (!sVhwinit) | 1697 | if (!sVhwinit) |
1720 | hwinit(); | 1698 | hwinit(); |
1721 | #endif /* KEEP_UNUSED */ | 1699 | #endif /* KEEP_UNUSED */ |
1722 | 1700 | ||
1723 | hwp = hwtypes; | 1701 | hwp = hwtypes; |
1724 | while (*hwp != NULL) { | 1702 | while (*hwp != NULL) { |
1725 | if ((*hwp)->type == type) | 1703 | if ((*hwp)->type == type) |
1726 | return (*hwp); | 1704 | return (*hwp); |
1727 | hwp++; | 1705 | hwp++; |
1728 | } | 1706 | } |
1729 | return (NULL); | 1707 | return (NULL); |
1730 | } | 1708 | } |
1731 | 1709 | ||
1732 | /* return 1 if address is all zeros */ | 1710 | /* return 1 if address is all zeros */ |
1733 | static int hw_null_address(struct hwtype *hw, void *ap) | 1711 | static int hw_null_address(struct hwtype *hw, void *ap) |
1734 | { | 1712 | { |
1735 | unsigned int i; | 1713 | unsigned int i; |
1736 | unsigned char *address = (unsigned char *)ap; | 1714 | unsigned char *address = (unsigned char *) ap; |
1737 | for (i = 0; i < hw->alen; i++) | 1715 | |
1738 | if (address[i]) | 1716 | for (i = 0; i < hw->alen; i++) |
1739 | return 0; | 1717 | if (address[i]) |
1740 | return 1; | 1718 | return 0; |
1719 | return 1; | ||
1741 | } | 1720 | } |
1742 | 1721 | ||
1743 | static const char TRext[] = "\0\0k\0M"; | 1722 | static const char TRext[] = "\0\0k\0M"; |
@@ -1752,11 +1731,11 @@ static void print_bytes_scaled(unsigned long long ull, const char *end) | |||
1752 | frac_part = 0; | 1731 | frac_part = 0; |
1753 | ext = TRext; | 1732 | ext = TRext; |
1754 | int_part = ull; | 1733 | int_part = ull; |
1755 | for (i=0 ; i<2 ; i++) { | 1734 | for (i = 0; i < 2; i++) { |
1756 | if (int_part >= 1024) { | 1735 | if (int_part >= 1024) { |
1757 | frac_part = ((int_part % 1024) * 10) / 1024; | 1736 | frac_part = ((int_part % 1024) * 10) / 1024; |
1758 | int_part /= 1024; | 1737 | int_part /= 1024; |
1759 | ext += 2; /* Kb, Mb */ | 1738 | ext += 2; /* Kb, Mb */ |
1760 | } | 1739 | } |
1761 | } | 1740 | } |
1762 | 1741 | ||
@@ -1765,68 +1744,68 @@ static void print_bytes_scaled(unsigned long long ull, const char *end) | |||
1765 | 1744 | ||
1766 | static void ife_print(struct interface *ptr) | 1745 | static void ife_print(struct interface *ptr) |
1767 | { | 1746 | { |
1768 | struct aftype *ap; | 1747 | struct aftype *ap; |
1769 | struct hwtype *hw; | 1748 | struct hwtype *hw; |
1770 | int hf; | 1749 | int hf; |
1771 | int can_compress = 0; | 1750 | int can_compress = 0; |
1772 | 1751 | ||
1773 | #if HAVE_AFIPX | 1752 | #if HAVE_AFIPX |
1774 | static struct aftype *ipxtype = NULL; | 1753 | static struct aftype *ipxtype = NULL; |
1775 | #endif | 1754 | #endif |
1776 | #if HAVE_AFECONET | 1755 | #if HAVE_AFECONET |
1777 | static struct aftype *ectype = NULL; | 1756 | static struct aftype *ectype = NULL; |
1778 | #endif | 1757 | #endif |
1779 | #if HAVE_AFATALK | 1758 | #if HAVE_AFATALK |
1780 | static struct aftype *ddptype = NULL; | 1759 | static struct aftype *ddptype = NULL; |
1781 | #endif | 1760 | #endif |
1782 | #if HAVE_AFINET6 | 1761 | #if HAVE_AFINET6 |
1783 | FILE *f; | 1762 | FILE *f; |
1784 | char addr6[40], devname[20]; | 1763 | char addr6[40], devname[20]; |
1785 | struct sockaddr_in6 sap; | 1764 | struct sockaddr_in6 sap; |
1786 | int plen, scope, dad_status, if_idx; | 1765 | int plen, scope, dad_status, if_idx; |
1787 | char addr6p[8][5]; | 1766 | char addr6p[8][5]; |
1788 | #endif | 1767 | #endif |
1789 | 1768 | ||
1790 | ap = get_afntype(ptr->addr.sa_family); | 1769 | ap = get_afntype(ptr->addr.sa_family); |
1791 | if (ap == NULL) | 1770 | if (ap == NULL) |
1792 | ap = get_afntype(0); | 1771 | ap = get_afntype(0); |
1793 | 1772 | ||
1794 | hf = ptr->type; | 1773 | hf = ptr->type; |
1795 | 1774 | ||
1796 | if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6) | 1775 | if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6) |
1797 | can_compress = 1; | 1776 | can_compress = 1; |
1798 | 1777 | ||
1799 | hw = get_hwntype(hf); | 1778 | hw = get_hwntype(hf); |
1800 | if (hw == NULL) | 1779 | if (hw == NULL) |
1801 | hw = get_hwntype(-1); | 1780 | hw = get_hwntype(-1); |
1802 | 1781 | ||
1803 | printf(_("%-9.9s Link encap:%s "), ptr->name, _(hw->title)); | 1782 | printf(_("%-9.9s Link encap:%s "), ptr->name, _(hw->title)); |
1804 | /* For some hardware types (eg Ash, ATM) we don't print the | 1783 | /* For some hardware types (eg Ash, ATM) we don't print the |
1805 | hardware address if it's null. */ | 1784 | hardware address if it's null. */ |
1806 | if (hw->print != NULL && (! (hw_null_address(hw, ptr->hwaddr) && | 1785 | if (hw->print != NULL && (!(hw_null_address(hw, ptr->hwaddr) && |
1807 | hw->suppress_null_addr))) | 1786 | hw->suppress_null_addr))) |
1808 | printf(_("HWaddr %s "), hw->print(ptr->hwaddr)); | 1787 | printf(_("HWaddr %s "), hw->print(ptr->hwaddr)); |
1809 | #ifdef IFF_PORTSEL | 1788 | #ifdef IFF_PORTSEL |
1810 | if (ptr->flags & IFF_PORTSEL) { | 1789 | if (ptr->flags & IFF_PORTSEL) { |
1811 | printf(_("Media:%s"), if_port_text[ptr->map.port][0]); | 1790 | printf(_("Media:%s"), if_port_text[ptr->map.port][0]); |
1812 | if (ptr->flags & IFF_AUTOMEDIA) | 1791 | if (ptr->flags & IFF_AUTOMEDIA) |
1813 | printf(_("(auto)")); | 1792 | printf(_("(auto)")); |
1814 | } | 1793 | } |
1815 | #endif | 1794 | #endif |
1816 | printf("\n"); | 1795 | printf("\n"); |
1817 | 1796 | ||
1818 | #if HAVE_AFINET | 1797 | #if HAVE_AFINET |
1819 | if (ptr->has_ip) { | 1798 | if (ptr->has_ip) { |
1820 | printf(_(" %s addr:%s "), ap->name, | 1799 | printf(_(" %s addr:%s "), ap->name, |
1821 | ap->sprint(&ptr->addr, 1)); | 1800 | ap->sprint(&ptr->addr, 1)); |
1822 | if (ptr->flags & IFF_POINTOPOINT) { | 1801 | if (ptr->flags & IFF_POINTOPOINT) { |
1823 | printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1)); | 1802 | printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1)); |
1824 | } | 1803 | } |
1825 | if (ptr->flags & IFF_BROADCAST) { | 1804 | if (ptr->flags & IFF_BROADCAST) { |
1826 | printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1)); | 1805 | printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1)); |
1806 | } | ||
1807 | printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1)); | ||
1827 | } | 1808 | } |
1828 | printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1)); | ||
1829 | } | ||
1830 | #endif | 1809 | #endif |
1831 | 1810 | ||
1832 | #if HAVE_AFINET6 | 1811 | #if HAVE_AFINET6 |
@@ -1840,238 +1819,246 @@ static void ife_print(struct interface *ptr) | |||
1840 | #define IPV6_ADDR_LOOPBACK 0x0010U | 1819 | #define IPV6_ADDR_LOOPBACK 0x0010U |
1841 | #define IPV6_ADDR_LINKLOCAL 0x0020U | 1820 | #define IPV6_ADDR_LINKLOCAL 0x0020U |
1842 | #define IPV6_ADDR_SITELOCAL 0x0040U | 1821 | #define IPV6_ADDR_SITELOCAL 0x0040U |
1843 | 1822 | ||
1844 | #define IPV6_ADDR_COMPATv4 0x0080U | 1823 | #define IPV6_ADDR_COMPATv4 0x0080U |
1845 | 1824 | ||
1846 | #define IPV6_ADDR_SCOPE_MASK 0x00f0U | 1825 | #define IPV6_ADDR_SCOPE_MASK 0x00f0U |
1847 | 1826 | ||
1848 | #define IPV6_ADDR_MAPPED 0x1000U | 1827 | #define IPV6_ADDR_MAPPED 0x1000U |
1849 | #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */ | 1828 | #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */ |
1850 | 1829 | ||
1851 | if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) { | 1830 | if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) { |
1852 | while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", | 1831 | while (fscanf |
1853 | addr6p[0], addr6p[1], addr6p[2], addr6p[3], | 1832 | (f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", |
1854 | addr6p[4], addr6p[5], addr6p[6], addr6p[7], | 1833 | addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], |
1855 | &if_idx, &plen, &scope, &dad_status, devname) != EOF) { | 1834 | addr6p[5], addr6p[6], addr6p[7], &if_idx, &plen, &scope, |
1856 | if (!strcmp(devname, ptr->name)) { | 1835 | &dad_status, devname) != EOF) { |
1857 | sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", | 1836 | if (!strcmp(devname, ptr->name)) { |
1858 | addr6p[0], addr6p[1], addr6p[2], addr6p[3], | 1837 | sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", |
1859 | addr6p[4], addr6p[5], addr6p[6], addr6p[7]); | 1838 | addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
1860 | inet_pton(AF_INET6, addr6, (struct sockaddr *) &sap.sin6_addr); | 1839 | addr6p[4], addr6p[5], addr6p[6], addr6p[7]); |
1861 | sap.sin6_family=AF_INET6; | 1840 | inet_pton(AF_INET6, addr6, |
1862 | printf(_(" inet6 addr: %s/%d"), | 1841 | (struct sockaddr *) &sap.sin6_addr); |
1863 | inet6_aftype.sprint((struct sockaddr *) &sap, 1), plen); | 1842 | sap.sin6_family = AF_INET6; |
1864 | printf(_(" Scope:")); | 1843 | printf(_(" inet6 addr: %s/%d"), |
1865 | switch (scope & IPV6_ADDR_SCOPE_MASK) { | 1844 | inet6_aftype.sprint((struct sockaddr *) &sap, 1), |
1866 | case 0: | 1845 | plen); |
1867 | printf(_("Global")); | 1846 | printf(_(" Scope:")); |
1868 | break; | 1847 | switch (scope & IPV6_ADDR_SCOPE_MASK) { |
1869 | case IPV6_ADDR_LINKLOCAL: | 1848 | case 0: |
1870 | printf(_("Link")); | 1849 | printf(_("Global")); |
1871 | break; | 1850 | break; |
1872 | case IPV6_ADDR_SITELOCAL: | 1851 | case IPV6_ADDR_LINKLOCAL: |
1873 | printf(_("Site")); | 1852 | printf(_("Link")); |
1874 | break; | 1853 | break; |
1875 | case IPV6_ADDR_COMPATv4: | 1854 | case IPV6_ADDR_SITELOCAL: |
1876 | printf(_("Compat")); | 1855 | printf(_("Site")); |
1877 | break; | 1856 | break; |
1878 | case IPV6_ADDR_LOOPBACK: | 1857 | case IPV6_ADDR_COMPATv4: |
1879 | printf(_("Host")); | 1858 | printf(_("Compat")); |
1880 | break; | 1859 | break; |
1881 | default: | 1860 | case IPV6_ADDR_LOOPBACK: |
1882 | printf(_("Unknown")); | 1861 | printf(_("Host")); |
1862 | break; | ||
1863 | default: | ||
1864 | printf(_("Unknown")); | ||
1865 | } | ||
1866 | printf("\n"); | ||
1867 | } | ||
1883 | } | 1868 | } |
1884 | printf("\n"); | 1869 | fclose(f); |
1885 | } | ||
1886 | } | 1870 | } |
1887 | fclose(f); | ||
1888 | } | ||
1889 | #endif | 1871 | #endif |
1890 | 1872 | ||
1891 | #if HAVE_AFIPX | 1873 | #if HAVE_AFIPX |
1892 | if (ipxtype == NULL) | 1874 | if (ipxtype == NULL) |
1893 | ipxtype = get_afntype(AF_IPX); | 1875 | ipxtype = get_afntype(AF_IPX); |
1894 | 1876 | ||
1895 | if (ipxtype != NULL) { | 1877 | if (ipxtype != NULL) { |
1896 | if (ptr->has_ipx_bb) | 1878 | if (ptr->has_ipx_bb) |
1897 | printf(_(" IPX/Ethernet II addr:%s\n"), | 1879 | printf(_(" IPX/Ethernet II addr:%s\n"), |
1898 | ipxtype->sprint(&ptr->ipxaddr_bb, 1)); | 1880 | ipxtype->sprint(&ptr->ipxaddr_bb, 1)); |
1899 | if (ptr->has_ipx_sn) | 1881 | if (ptr->has_ipx_sn) |
1900 | printf(_(" IPX/Ethernet SNAP addr:%s\n"), | 1882 | printf(_(" IPX/Ethernet SNAP addr:%s\n"), |
1901 | ipxtype->sprint(&ptr->ipxaddr_sn, 1)); | 1883 | ipxtype->sprint(&ptr->ipxaddr_sn, 1)); |
1902 | if (ptr->has_ipx_e2) | 1884 | if (ptr->has_ipx_e2) |
1903 | printf(_(" IPX/Ethernet 802.2 addr:%s\n"), | 1885 | printf(_(" IPX/Ethernet 802.2 addr:%s\n"), |
1904 | ipxtype->sprint(&ptr->ipxaddr_e2, 1)); | 1886 | ipxtype->sprint(&ptr->ipxaddr_e2, 1)); |
1905 | if (ptr->has_ipx_e3) | 1887 | if (ptr->has_ipx_e3) |
1906 | printf(_(" IPX/Ethernet 802.3 addr:%s\n"), | 1888 | printf(_(" IPX/Ethernet 802.3 addr:%s\n"), |
1907 | ipxtype->sprint(&ptr->ipxaddr_e3, 1)); | 1889 | ipxtype->sprint(&ptr->ipxaddr_e3, 1)); |
1908 | } | 1890 | } |
1909 | #endif | 1891 | #endif |
1910 | 1892 | ||
1911 | #if HAVE_AFATALK | 1893 | #if HAVE_AFATALK |
1912 | if (ddptype == NULL) | 1894 | if (ddptype == NULL) |
1913 | ddptype = get_afntype(AF_APPLETALK); | 1895 | ddptype = get_afntype(AF_APPLETALK); |
1914 | if (ddptype != NULL) { | 1896 | if (ddptype != NULL) { |
1915 | if (ptr->has_ddp) | 1897 | if (ptr->has_ddp) |
1916 | printf(_(" EtherTalk Phase 2 addr:%s\n"), ddptype->sprint(&ptr->ddpaddr, 1)); | 1898 | printf(_(" EtherTalk Phase 2 addr:%s\n"), |
1917 | } | 1899 | ddptype->sprint(&ptr->ddpaddr, 1)); |
1900 | } | ||
1918 | #endif | 1901 | #endif |
1919 | 1902 | ||
1920 | #if HAVE_AFECONET | 1903 | #if HAVE_AFECONET |
1921 | if (ectype == NULL) | 1904 | if (ectype == NULL) |
1922 | ectype = get_afntype(AF_ECONET); | 1905 | ectype = get_afntype(AF_ECONET); |
1923 | if (ectype != NULL) { | 1906 | if (ectype != NULL) { |
1924 | if (ptr->has_econet) | 1907 | if (ptr->has_econet) |
1925 | printf(_(" econet addr:%s\n"), ectype->sprint(&ptr->ecaddr, 1)); | 1908 | printf(_(" econet addr:%s\n"), |
1926 | } | 1909 | ectype->sprint(&ptr->ecaddr, 1)); |
1927 | #endif | 1910 | } |
1928 | 1911 | #endif | |
1929 | printf(" "); | 1912 | |
1930 | /* DONT FORGET TO ADD THE FLAGS IN ife_print_short, too */ | 1913 | printf(" "); |
1931 | if (ptr->flags == 0) | 1914 | /* DONT FORGET TO ADD THE FLAGS IN ife_print_short, too */ |
1932 | printf(_("[NO FLAGS] ")); | 1915 | if (ptr->flags == 0) |
1933 | if (ptr->flags & IFF_UP) | 1916 | printf(_("[NO FLAGS] ")); |
1934 | printf(_("UP ")); | 1917 | if (ptr->flags & IFF_UP) |
1935 | if (ptr->flags & IFF_BROADCAST) | 1918 | printf(_("UP ")); |
1936 | printf(_("BROADCAST ")); | 1919 | if (ptr->flags & IFF_BROADCAST) |
1937 | if (ptr->flags & IFF_DEBUG) | 1920 | printf(_("BROADCAST ")); |
1938 | printf(_("DEBUG ")); | 1921 | if (ptr->flags & IFF_DEBUG) |
1939 | if (ptr->flags & IFF_LOOPBACK) | 1922 | printf(_("DEBUG ")); |
1940 | printf(_("LOOPBACK ")); | 1923 | if (ptr->flags & IFF_LOOPBACK) |
1941 | if (ptr->flags & IFF_POINTOPOINT) | 1924 | printf(_("LOOPBACK ")); |
1942 | printf(_("POINTOPOINT ")); | 1925 | if (ptr->flags & IFF_POINTOPOINT) |
1943 | if (ptr->flags & IFF_NOTRAILERS) | 1926 | printf(_("POINTOPOINT ")); |
1944 | printf(_("NOTRAILERS ")); | 1927 | if (ptr->flags & IFF_NOTRAILERS) |
1945 | if (ptr->flags & IFF_RUNNING) | 1928 | printf(_("NOTRAILERS ")); |
1946 | printf(_("RUNNING ")); | 1929 | if (ptr->flags & IFF_RUNNING) |
1947 | if (ptr->flags & IFF_NOARP) | 1930 | printf(_("RUNNING ")); |
1948 | printf(_("NOARP ")); | 1931 | if (ptr->flags & IFF_NOARP) |
1949 | if (ptr->flags & IFF_PROMISC) | 1932 | printf(_("NOARP ")); |
1950 | printf(_("PROMISC ")); | 1933 | if (ptr->flags & IFF_PROMISC) |
1951 | if (ptr->flags & IFF_ALLMULTI) | 1934 | printf(_("PROMISC ")); |
1952 | printf(_("ALLMULTI ")); | 1935 | if (ptr->flags & IFF_ALLMULTI) |
1953 | if (ptr->flags & IFF_SLAVE) | 1936 | printf(_("ALLMULTI ")); |
1954 | printf(_("SLAVE ")); | 1937 | if (ptr->flags & IFF_SLAVE) |
1955 | if (ptr->flags & IFF_MASTER) | 1938 | printf(_("SLAVE ")); |
1956 | printf(_("MASTER ")); | 1939 | if (ptr->flags & IFF_MASTER) |
1957 | if (ptr->flags & IFF_MULTICAST) | 1940 | printf(_("MASTER ")); |
1958 | printf(_("MULTICAST ")); | 1941 | if (ptr->flags & IFF_MULTICAST) |
1942 | printf(_("MULTICAST ")); | ||
1959 | #ifdef HAVE_DYNAMIC | 1943 | #ifdef HAVE_DYNAMIC |
1960 | if (ptr->flags & IFF_DYNAMIC) | 1944 | if (ptr->flags & IFF_DYNAMIC) |
1961 | printf(_("DYNAMIC ")); | 1945 | printf(_("DYNAMIC ")); |
1962 | #endif | 1946 | #endif |
1963 | /* DONT FORGET TO ADD THE FLAGS IN ife_print_short */ | 1947 | /* DONT FORGET TO ADD THE FLAGS IN ife_print_short */ |
1964 | printf(_(" MTU:%d Metric:%d"), | 1948 | printf(_(" MTU:%d Metric:%d"), ptr->mtu, ptr->metric ? ptr->metric : 1); |
1965 | ptr->mtu, ptr->metric ? ptr->metric : 1); | ||
1966 | #ifdef SIOCSKEEPALIVE | 1949 | #ifdef SIOCSKEEPALIVE |
1967 | if (ptr->outfill || ptr->keepalive) | 1950 | if (ptr->outfill || ptr->keepalive) |
1968 | printf(_(" Outfill:%d Keepalive:%d"), | 1951 | printf(_(" Outfill:%d Keepalive:%d"), ptr->outfill, ptr->keepalive); |
1969 | ptr->outfill, ptr->keepalive); | ||
1970 | #endif | 1952 | #endif |
1971 | printf("\n"); | 1953 | printf("\n"); |
1972 | 1954 | ||
1973 | /* If needed, display the interface statistics. */ | 1955 | /* If needed, display the interface statistics. */ |
1956 | |||
1957 | if (ptr->statistics_valid) { | ||
1958 | /* XXX: statistics are currently only printed for the primary address, | ||
1959 | * not for the aliases, although strictly speaking they're shared | ||
1960 | * by all addresses. | ||
1961 | */ | ||
1962 | printf(" "); | ||
1963 | |||
1964 | printf(_ | ||
1965 | ("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"), | ||
1966 | ptr->stats.rx_packets, ptr->stats.rx_errors, | ||
1967 | ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, | ||
1968 | ptr->stats.rx_frame_errors); | ||
1969 | if (can_compress) | ||
1970 | printf(_(" compressed:%lu\n"), | ||
1971 | ptr->stats.rx_compressed); | ||
1972 | printf(" "); | ||
1973 | printf(_ | ||
1974 | ("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"), | ||
1975 | ptr->stats.tx_packets, ptr->stats.tx_errors, | ||
1976 | ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, | ||
1977 | ptr->stats.tx_carrier_errors); | ||
1978 | printf(_(" collisions:%lu "), ptr->stats.collisions); | ||
1979 | if (can_compress) | ||
1980 | printf(_("compressed:%lu "), ptr->stats.tx_compressed); | ||
1981 | if (ptr->tx_queue_len != -1) | ||
1982 | printf(_("txqueuelen:%d "), ptr->tx_queue_len); | ||
1983 | printf("\n R"); | ||
1984 | print_bytes_scaled(ptr->stats.rx_bytes, " T"); | ||
1985 | print_bytes_scaled(ptr->stats.tx_bytes, "\n"); | ||
1974 | 1986 | ||
1975 | if (ptr->statistics_valid) { | 1987 | } |
1976 | /* XXX: statistics are currently only printed for the primary address, | ||
1977 | * not for the aliases, although strictly speaking they're shared | ||
1978 | * by all addresses. | ||
1979 | */ | ||
1980 | printf(" "); | ||
1981 | 1988 | ||
1982 | printf(_("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"), | 1989 | if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma || |
1983 | ptr->stats.rx_packets, ptr->stats.rx_errors, | 1990 | ptr->map.base_addr)) { |
1984 | ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, | 1991 | printf(" "); |
1985 | ptr->stats.rx_frame_errors); | 1992 | if (ptr->map.irq) |
1986 | if (can_compress) | 1993 | printf(_("Interrupt:%d "), ptr->map.irq); |
1987 | printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed); | 1994 | if (ptr->map.base_addr >= 0x100) /* Only print devices using it for |
1988 | printf(" "); | 1995 | I/O maps */ |
1989 | printf(_("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"), | 1996 | printf(_("Base address:0x%lx "), |
1990 | ptr->stats.tx_packets, ptr->stats.tx_errors, | 1997 | (unsigned long) ptr->map.base_addr); |
1991 | ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, | 1998 | if (ptr->map.mem_start) { |
1992 | ptr->stats.tx_carrier_errors); | 1999 | printf(_("Memory:%lx-%lx "), ptr->map.mem_start, |
1993 | printf(_(" collisions:%lu "), ptr->stats.collisions); | 2000 | ptr->map.mem_end); |
1994 | if (can_compress) | 2001 | } |
1995 | printf(_("compressed:%lu "), ptr->stats.tx_compressed); | 2002 | if (ptr->map.dma) |
1996 | if (ptr->tx_queue_len != -1) | 2003 | printf(_("DMA chan:%x "), ptr->map.dma); |
1997 | printf(_("txqueuelen:%d "), ptr->tx_queue_len); | 2004 | printf("\n"); |
1998 | printf("\n R"); | ||
1999 | print_bytes_scaled(ptr->stats.rx_bytes, " T"); | ||
2000 | print_bytes_scaled(ptr->stats.tx_bytes, "\n"); | ||
2001 | |||
2002 | } | ||
2003 | |||
2004 | if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma || | ||
2005 | ptr->map.base_addr)) { | ||
2006 | printf(" "); | ||
2007 | if (ptr->map.irq) | ||
2008 | printf(_("Interrupt:%d "), ptr->map.irq); | ||
2009 | if (ptr->map.base_addr >= 0x100) /* Only print devices using it for | ||
2010 | I/O maps */ | ||
2011 | printf(_("Base address:0x%lx "), (unsigned long)ptr->map.base_addr); | ||
2012 | if (ptr->map.mem_start) { | ||
2013 | printf(_("Memory:%lx-%lx "), ptr->map.mem_start, ptr->map.mem_end); | ||
2014 | } | 2005 | } |
2015 | if (ptr->map.dma) | ||
2016 | printf(_("DMA chan:%x "), ptr->map.dma); | ||
2017 | printf("\n"); | 2006 | printf("\n"); |
2018 | } | ||
2019 | printf("\n"); | ||
2020 | } | 2007 | } |
2021 | 2008 | ||
2022 | 2009 | ||
2023 | static int do_if_print(struct interface *ife, void *cookie) | 2010 | static int do_if_print(struct interface *ife, void *cookie) |
2024 | { | 2011 | { |
2025 | int *opt_a = (int *) cookie; | 2012 | int *opt_a = (int *) cookie; |
2026 | int res; | 2013 | int res; |
2027 | 2014 | ||
2028 | res = do_if_fetch(ife); | 2015 | res = do_if_fetch(ife); |
2029 | if (res >= 0) { | 2016 | if (res >= 0) { |
2030 | if ((ife->flags & IFF_UP) || *opt_a) | 2017 | if ((ife->flags & IFF_UP) || *opt_a) |
2031 | ife_print(ife); | 2018 | ife_print(ife); |
2032 | } | 2019 | } |
2033 | return res; | 2020 | return res; |
2034 | } | 2021 | } |
2035 | 2022 | ||
2036 | static struct interface *lookup_interface(char *name) | 2023 | static struct interface *lookup_interface(char *name) |
2037 | { | 2024 | { |
2038 | struct interface *ife = NULL; | 2025 | struct interface *ife = NULL; |
2039 | 2026 | ||
2040 | if (if_readlist_proc(name) < 0) | 2027 | if (if_readlist_proc(name) < 0) |
2041 | return NULL; | 2028 | return NULL; |
2042 | ife = add_interface(name); | 2029 | ife = add_interface(name); |
2043 | return ife; | 2030 | return ife; |
2044 | } | 2031 | } |
2045 | 2032 | ||
2046 | /* for ipv4 add/del modes */ | 2033 | /* for ipv4 add/del modes */ |
2047 | static int if_print(char *ifname) | 2034 | static int if_print(char *ifname) |
2048 | { | 2035 | { |
2049 | int res; | 2036 | int res; |
2050 | 2037 | ||
2051 | if (!ifname) { | 2038 | if (!ifname) { |
2052 | res = for_all_interfaces(do_if_print, &interface_opt_a); | 2039 | res = for_all_interfaces(do_if_print, &interface_opt_a); |
2053 | } else { | 2040 | } else { |
2054 | struct interface *ife; | 2041 | struct interface *ife; |
2055 | 2042 | ||
2056 | ife = lookup_interface(ifname); | 2043 | ife = lookup_interface(ifname); |
2057 | res = do_if_fetch(ife); | 2044 | res = do_if_fetch(ife); |
2058 | if (res >= 0) | 2045 | if (res >= 0) |
2059 | ife_print(ife); | 2046 | ife_print(ife); |
2060 | } | 2047 | } |
2061 | return res; | 2048 | return res; |
2062 | } | 2049 | } |
2063 | 2050 | ||
2064 | int display_interfaces(char *ifname) | 2051 | int display_interfaces(char *ifname) |
2065 | { | 2052 | { |
2066 | int status; | 2053 | int status; |
2067 | 2054 | ||
2068 | /* Create a channel to the NET kernel. */ | 2055 | /* Create a channel to the NET kernel. */ |
2069 | if ((skfd = sockets_open(0)) < 0) { | 2056 | if ((skfd = sockets_open(0)) < 0) { |
2070 | perror_msg_and_die("socket"); | 2057 | perror_msg_and_die("socket"); |
2071 | } | 2058 | } |
2072 | 2059 | ||
2073 | /* Do we have to show the current setup? */ | 2060 | /* Do we have to show the current setup? */ |
2074 | status = if_print(ifname); | 2061 | status = if_print(ifname); |
2075 | close(skfd); | 2062 | close(skfd); |
2076 | exit(status < 0); | 2063 | exit(status < 0); |
2077 | } | 2064 | } |