diff options
| author | Rob Landley <rob@landley.net> | 2006-06-03 21:23:20 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2006-06-03 21:23:20 +0000 |
| commit | e84f4343b2212ec2ff9d87521ebd1d30576cdff3 (patch) | |
| tree | 73ef4b4c1ffe83d1cbb2cebc4023b780b50fe7a5 /networking/interface.c | |
| parent | 5084c78cbe63ae92c3e86fbadb2709cb57e8897c (diff) | |
| download | busybox-w32-e84f4343b2212ec2ff9d87521ebd1d30576cdff3.tar.gz busybox-w32-e84f4343b2212ec2ff9d87521ebd1d30576cdff3.tar.bz2 busybox-w32-e84f4343b2212ec2ff9d87521ebd1d30576cdff3.zip | |
Remove #ifdeffed out code, both KEEP_UNUSED and #if 0.
Diffstat (limited to 'networking/interface.c')
| -rw-r--r-- | networking/interface.c | 493 |
1 files changed, 1 insertions, 492 deletions
diff --git a/networking/interface.c b/networking/interface.c index 260dac073..4f8e46de4 100644 --- a/networking/interface.c +++ b/networking/interface.c | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | * | 4 | * |
| 5 | * Heavily modified by Manuel Novoa III Mar 12, 2001 | 5 | * Heavily modified by Manuel Novoa III Mar 12, 2001 |
| 6 | * | 6 | * |
| 7 | * Pruned unused code using KEEP_UNUSED define. | ||
| 8 | * Added print_bytes_scaled function to reduce code size. | 7 | * Added print_bytes_scaled function to reduce code size. |
| 9 | * Added some (potentially) missing defines. | 8 | * Added some (potentially) missing defines. |
| 10 | * Improved display support for -a and for a named interface. | 9 | * Improved display support for -a and for a named interface. |
| @@ -20,11 +19,7 @@ | |||
| 20 | * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> | 19 | * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
| 21 | * and others. Copyright 1993 MicroWalt Corporation | 20 | * and others. Copyright 1993 MicroWalt Corporation |
| 22 | * | 21 | * |
| 23 | * This program is free software; you can redistribute it | 22 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 24 | * and/or modify it under the terms of the GNU General | ||
| 25 | * Public License as published by the Free Software | ||
| 26 | * Foundation; either version 2 of the License, or (at | ||
| 27 | * your option) any later version. | ||
| 28 | * | 23 | * |
| 29 | * Patched to support 'add' and 'del' keywords for INET(4) addresses | 24 | * Patched to support 'add' and 'del' keywords for INET(4) addresses |
| 30 | * by Mrs. Brisby <mrs.brisby@nimh.org> | 25 | * by Mrs. Brisby <mrs.brisby@nimh.org> |
| @@ -36,8 +31,6 @@ | |||
| 36 | * (default AF was wrong) | 31 | * (default AF was wrong) |
| 37 | */ | 32 | */ |
| 38 | 33 | ||
| 39 | /* #define KEEP_UNUSED */ | ||
| 40 | |||
| 41 | /* | 34 | /* |
| 42 | * | 35 | * |
| 43 | * Protocol Families. | 36 | * Protocol Families. |
| @@ -133,39 +126,6 @@ struct aftype { | |||
| 133 | char *flag_file; | 126 | char *flag_file; |
| 134 | }; | 127 | }; |
| 135 | 128 | ||
| 136 | #ifdef KEEP_UNUSED | ||
| 137 | |||
| 138 | static int flag_unx; | ||
| 139 | static int flag_inet; | ||
| 140 | |||
| 141 | static struct aftrans_t { | ||
| 142 | char *alias; | ||
| 143 | char *name; | ||
| 144 | int *flag; | ||
| 145 | } aftrans[] = { | ||
| 146 | |||
| 147 | { | ||
| 148 | "ip", "inet", &flag_inet}, | ||
| 149 | #ifdef HAVE_AFINET6 | ||
| 150 | { | ||
| 151 | "ip6", "inet6", &flag_inet6}, | ||
| 152 | #endif | ||
| 153 | { | ||
| 154 | "inet", "inet", &flag_inet}, | ||
| 155 | #ifdef HAVE_AFINET6 | ||
| 156 | { | ||
| 157 | "inet6", "inet6", &flag_inet6}, | ||
| 158 | #endif | ||
| 159 | { | ||
| 160 | "unix", "unix", &flag_unx}, { | ||
| 161 | "tcpip", "inet", &flag_inet}, | ||
| 162 | { | ||
| 163 | 0, 0, 0} | ||
| 164 | }; | ||
| 165 | |||
| 166 | static char afname[256] = ""; | ||
| 167 | #endif /* KEEP_UNUSED */ | ||
| 168 | |||
| 169 | #if HAVE_AFUNIX | 129 | #if HAVE_AFUNIX |
| 170 | 130 | ||
| 171 | /* Display a UNIX domain address. */ | 131 | /* Display a UNIX domain address. */ |
| @@ -197,19 +157,6 @@ static struct aftype unix_aftype = { | |||
| 197 | 157 | ||
| 198 | #if HAVE_AFINET | 158 | #if HAVE_AFINET |
| 199 | 159 | ||
| 200 | #ifdef KEEP_UNUSED | ||
| 201 | static void INET_reserror(char *text) | ||
| 202 | { | ||
| 203 | herror(text); | ||
| 204 | } | ||
| 205 | |||
| 206 | /* Display an Internet socket address. */ | ||
| 207 | static char *INET_print(unsigned char *ptr) | ||
| 208 | { | ||
| 209 | return (inet_ntoa((*(struct in_addr *) ptr))); | ||
| 210 | } | ||
| 211 | #endif /* KEEP_UNUSED */ | ||
| 212 | |||
| 213 | /* Display an Internet socket address. */ | 160 | /* Display an Internet socket address. */ |
| 214 | static char *INET_sprint(struct sockaddr *sap, int numeric) | 161 | static char *INET_sprint(struct sockaddr *sap, int numeric) |
| 215 | { | 162 | { |
| @@ -225,96 +172,6 @@ static char *INET_sprint(struct sockaddr *sap, int numeric) | |||
| 225 | return (buff); | 172 | return (buff); |
| 226 | } | 173 | } |
| 227 | 174 | ||
| 228 | #ifdef KEEP_UNUSED | ||
| 229 | static char *INET_sprintmask(struct sockaddr *sap, int numeric, | ||
| 230 | unsigned int netmask) | ||
| 231 | { | ||
| 232 | static char buff[128]; | ||
| 233 | |||
| 234 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | ||
| 235 | return safe_strncpy(buff, "[NONE SET]", sizeof(buff)); | ||
| 236 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, | ||
| 237 | numeric, netmask) != 0) | ||
| 238 | return (NULL); | ||
| 239 | return (buff); | ||
| 240 | } | ||
| 241 | |||
| 242 | static int INET_getsock(char *bufp, struct sockaddr *sap) | ||
| 243 | { | ||
| 244 | char *sp = bufp, *bp; | ||
| 245 | unsigned int i; | ||
| 246 | unsigned val; | ||
| 247 | struct sockaddr_in *sin; | ||
| 248 | |||
| 249 | sin = (struct sockaddr_in *) sap; | ||
| 250 | sin->sin_family = AF_INET; | ||
| 251 | sin->sin_port = 0; | ||
| 252 | |||
| 253 | val = 0; | ||
| 254 | bp = (char *) &val; | ||
| 255 | for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { | ||
| 256 | *sp = toupper(*sp); | ||
| 257 | |||
| 258 | if ((*sp >= 'A') && (*sp <= 'F')) | ||
| 259 | bp[i] |= (int) (*sp - 'A') + 10; | ||
| 260 | else if ((*sp >= '0') && (*sp <= '9')) | ||
| 261 | bp[i] |= (int) (*sp - '0'); | ||
| 262 | else | ||
| 263 | return (-1); | ||
| 264 | |||
| 265 | bp[i] <<= 4; | ||
| 266 | sp++; | ||
| 267 | *sp = toupper(*sp); | ||
| 268 | |||
| 269 | if ((*sp >= 'A') && (*sp <= 'F')) | ||
| 270 | bp[i] |= (int) (*sp - 'A') + 10; | ||
| 271 | else if ((*sp >= '0') && (*sp <= '9')) | ||
| 272 | bp[i] |= (int) (*sp - '0'); | ||
| 273 | else | ||
| 274 | return (-1); | ||
| 275 | |||
| 276 | sp++; | ||
| 277 | } | ||
| 278 | sin->sin_addr.s_addr = htonl(val); | ||
| 279 | |||
| 280 | return (sp - bufp); | ||
| 281 | } | ||
| 282 | |||
| 283 | static int INET_input(int type, char *bufp, struct sockaddr *sap) | ||
| 284 | { | ||
| 285 | switch (type) { | ||
| 286 | case 1: | ||
| 287 | return (INET_getsock(bufp, sap)); | ||
| 288 | case 256: | ||
| 289 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1)); | ||
| 290 | default: | ||
| 291 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0)); | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) | ||
| 296 | { | ||
| 297 | struct sockaddr_in *mask = (struct sockaddr_in *) m; | ||
| 298 | char *slash, *end; | ||
| 299 | int prefix; | ||
| 300 | |||
| 301 | if ((slash = strchr(adr, '/')) == NULL) | ||
| 302 | return 0; | ||
| 303 | |||
| 304 | *slash++ = '\0'; | ||
| 305 | prefix = strtoul(slash, &end, 0); | ||
| 306 | if (*end != '\0') | ||
| 307 | return -1; | ||
| 308 | |||
| 309 | if (name) { | ||
| 310 | sprintf(name, "/%d", prefix); | ||
| 311 | } | ||
| 312 | mask->sin_family = AF_INET; | ||
| 313 | mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); | ||
| 314 | return 1; | ||
| 315 | } | ||
| 316 | #endif /* KEEP_UNUSED */ | ||
| 317 | |||
| 318 | static struct aftype inet_aftype = { | 175 | static struct aftype inet_aftype = { |
| 319 | "inet", "DARPA Internet", AF_INET, sizeof(unsigned long), | 176 | "inet", "DARPA Internet", AF_INET, sizeof(unsigned long), |
| 320 | NULL /* UNUSED INET_print */ , INET_sprint, | 177 | NULL /* UNUSED INET_print */ , INET_sprint, |
| @@ -329,22 +186,6 @@ static struct aftype inet_aftype = { | |||
| 329 | 186 | ||
| 330 | #if HAVE_AFINET6 | 187 | #if HAVE_AFINET6 |
| 331 | 188 | ||
| 332 | #ifdef KEEP_UNUSED | ||
| 333 | static void INET6_reserror(char *text) | ||
| 334 | { | ||
| 335 | herror(text); | ||
| 336 | } | ||
| 337 | |||
| 338 | /* Display an Internet socket address. */ | ||
| 339 | static char *INET6_print(unsigned char *ptr) | ||
| 340 | { | ||
| 341 | static char name[80]; | ||
| 342 | |||
| 343 | inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); | ||
| 344 | return name; | ||
| 345 | } | ||
| 346 | #endif /* KEEP_UNUSED */ | ||
| 347 | |||
| 348 | /* Display an Internet socket address. */ | 189 | /* Display an Internet socket address. */ |
| 349 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ | 190 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ |
| 350 | static char *INET6_sprint(struct sockaddr *sap, int numeric) | 191 | static char *INET6_sprint(struct sockaddr *sap, int numeric) |
| @@ -359,32 +200,6 @@ static char *INET6_sprint(struct sockaddr *sap, int numeric) | |||
| 359 | return (buff); | 200 | return (buff); |
| 360 | } | 201 | } |
| 361 | 202 | ||
| 362 | #ifdef KEEP_UNUSED | ||
| 363 | static int INET6_getsock(char *bufp, struct sockaddr *sap) | ||
| 364 | { | ||
| 365 | struct sockaddr_in6 *sin6; | ||
| 366 | |||
| 367 | sin6 = (struct sockaddr_in6 *) sap; | ||
| 368 | sin6->sin6_family = AF_INET6; | ||
| 369 | sin6->sin6_port = 0; | ||
| 370 | |||
| 371 | if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) | ||
| 372 | return (-1); | ||
| 373 | |||
| 374 | return 16; /* ?;) */ | ||
| 375 | } | ||
| 376 | |||
| 377 | static int INET6_input(int type, char *bufp, struct sockaddr *sap) | ||
| 378 | { | ||
| 379 | switch (type) { | ||
| 380 | case 1: | ||
| 381 | return (INET6_getsock(bufp, sap)); | ||
| 382 | default: | ||
| 383 | return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | #endif /* KEEP_UNUSED */ | ||
| 387 | |||
| 388 | static struct aftype inet6_aftype = { | 203 | static struct aftype inet6_aftype = { |
| 389 | "inet6", "IPv6", AF_INET6, sizeof(struct in6_addr), | 204 | "inet6", "IPv6", AF_INET6, sizeof(struct in6_addr), |
| 390 | NULL /* UNUSED INET6_print */ , INET6_sprint, | 205 | NULL /* UNUSED INET6_print */ , INET6_sprint, |
| @@ -445,135 +260,11 @@ static struct aftype * const aftypes[] = { | |||
| 445 | NULL | 260 | NULL |
| 446 | }; | 261 | }; |
| 447 | 262 | ||
| 448 | #ifdef KEEP_UNUSED | ||
| 449 | static short sVafinit = 0; | ||
| 450 | |||
| 451 | static void afinit() | ||
| 452 | { | ||
| 453 | unspec_aftype.title = "UNSPEC"; | ||
| 454 | #if HAVE_AFUNIX | ||
| 455 | unix_aftype.title = "UNIX Domain"; | ||
| 456 | #endif | ||
| 457 | #if HAVE_AFINET | ||
| 458 | inet_aftype.title = "DARPA Internet"; | ||
| 459 | #endif | ||
| 460 | #if HAVE_AFINET6 | ||
| 461 | inet6_aftype.title = "IPv6"; | ||
| 462 | #endif | ||
| 463 | sVafinit = 1; | ||
| 464 | } | ||
| 465 | |||
| 466 | static int aftrans_opt(const char *arg) | ||
| 467 | { | ||
| 468 | struct aftrans_t *paft; | ||
| 469 | char *tmp1, *tmp2; | ||
| 470 | char buf[256]; | ||
| 471 | |||
| 472 | safe_strncpy(buf, arg, sizeof(buf)); | ||
| 473 | |||
| 474 | tmp1 = buf; | ||
| 475 | |||
| 476 | while (tmp1) { | ||
| 477 | |||
| 478 | tmp2 = strchr(tmp1, ','); | ||
| 479 | |||
| 480 | if (tmp2) | ||
| 481 | *(tmp2++) = '\0'; | ||
| 482 | |||
| 483 | paft = aftrans; | ||
| 484 | for (paft = aftrans; paft->alias; paft++) { | ||
| 485 | if (strcmp(tmp1, paft->alias)) | ||
| 486 | continue; | ||
| 487 | if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) { | ||
| 488 | bb_error_msg("Too many address family arguments."); | ||
| 489 | return (0); | ||
| 490 | } | ||
| 491 | if (paft->flag) | ||
| 492 | (*paft->flag)++; | ||
| 493 | if (afname[0]) | ||
| 494 | strcat(afname, ","); | ||
| 495 | strcat(afname, paft->name); | ||
| 496 | break; | ||
| 497 | } | ||
| 498 | if (!paft->alias) { | ||
| 499 | bb_error_msg("Unknown address family `%s'.", tmp1); | ||
| 500 | return (1); | ||
| 501 | } | ||
| 502 | tmp1 = tmp2; | ||
| 503 | } | ||
| 504 | |||
| 505 | return (0); | ||
| 506 | } | ||
| 507 | |||
| 508 | /* set the default AF list from the program name or a constant value */ | ||
| 509 | static void aftrans_def(char *tool, char *argv0, char *dflt) | ||
| 510 | { | ||
| 511 | char *tmp; | ||
| 512 | char *buf; | ||
| 513 | |||
| 514 | strcpy(afname, dflt); | ||
| 515 | |||
| 516 | if (!(tmp = strrchr(argv0, '/'))) | ||
| 517 | tmp = argv0; /* no slash?! */ | ||
| 518 | else | ||
| 519 | tmp++; | ||
| 520 | |||
| 521 | if (!(buf = strdup(tmp))) | ||
| 522 | return; | ||
| 523 | |||
| 524 | if (strlen(tool) >= strlen(tmp)) { | ||
| 525 | free(buf); | ||
| 526 | return; | ||
| 527 | } | ||
| 528 | tmp = buf + (strlen(tmp) - strlen(tool)); | ||
| 529 | |||
| 530 | if (strcmp(tmp, tool) != 0) { | ||
| 531 | free(buf); | ||
| 532 | return; | ||
| 533 | } | ||
| 534 | *tmp = '\0'; | ||
| 535 | if ((tmp = strchr(buf, '_'))) | ||
| 536 | *tmp = '\0'; | ||
| 537 | |||
| 538 | afname[0] = '\0'; | ||
| 539 | if (aftrans_opt(buf)) | ||
| 540 | strcpy(afname, buf); | ||
| 541 | |||
| 542 | free(buf); | ||
| 543 | } | ||
| 544 | |||
| 545 | /* Check our protocol family table for this family. */ | ||
| 546 | static struct aftype *get_aftype(const char *name) | ||
| 547 | { | ||
| 548 | struct aftype * const *afp; | ||
| 549 | |||
| 550 | #ifdef KEEP_UNUSED | ||
| 551 | if (!sVafinit) | ||
| 552 | afinit(); | ||
| 553 | #endif /* KEEP_UNUSED */ | ||
| 554 | |||
| 555 | afp = aftypes; | ||
| 556 | while (*afp != NULL) { | ||
| 557 | if (!strcmp((*afp)->name, name)) | ||
| 558 | return (*afp); | ||
| 559 | afp++; | ||
| 560 | } | ||
| 561 | if (strchr(name, ',')) | ||
| 562 | bb_error_msg("Only one address family."); | ||
| 563 | return (NULL); | ||
| 564 | } | ||
| 565 | #endif /* KEEP_UNUSED */ | ||
| 566 | |||
| 567 | /* Check our protocol family table for this family. */ | 263 | /* Check our protocol family table for this family. */ |
| 568 | static struct aftype *get_afntype(int af) | 264 | static struct aftype *get_afntype(int af) |
| 569 | { | 265 | { |
| 570 | struct aftype * const *afp; | 266 | struct aftype * const *afp; |
| 571 | 267 | ||
| 572 | #ifdef KEEP_UNUSED | ||
| 573 | if (!sVafinit) | ||
| 574 | afinit(); | ||
| 575 | #endif /* KEEP_UNUSED */ | ||
| 576 | |||
| 577 | afp = aftypes; | 268 | afp = aftypes; |
| 578 | while (*afp != NULL) { | 269 | while (*afp != NULL) { |
| 579 | if ((*afp)->af == af) | 270 | if ((*afp)->af == af) |
| @@ -588,11 +279,6 @@ static int get_socket_for_af(int af) | |||
| 588 | { | 279 | { |
| 589 | struct aftype * const *afp; | 280 | struct aftype * const *afp; |
| 590 | 281 | ||
| 591 | #ifdef KEEP_UNUSED | ||
| 592 | if (!sVafinit) | ||
| 593 | afinit(); | ||
| 594 | #endif /* KEEP_UNUSED */ | ||
| 595 | |||
| 596 | afp = aftypes; | 282 | afp = aftypes; |
| 597 | while (*afp != NULL) { | 283 | while (*afp != NULL) { |
| 598 | if ((*afp)->af == af) | 284 | if ((*afp)->af == af) |
| @@ -602,38 +288,6 @@ static int get_socket_for_af(int af) | |||
| 602 | return -1; | 288 | return -1; |
| 603 | } | 289 | } |
| 604 | 290 | ||
| 605 | #ifdef KEEP_UNUSED | ||
| 606 | /* type: 0=all, 1=getroute */ | ||
| 607 | static void print_aflist(int type) | ||
| 608 | { | ||
| 609 | int count = 0; | ||
| 610 | char *txt; | ||
| 611 | struct aftype * const *afp; | ||
| 612 | |||
| 613 | #ifdef KEEP_UNUSED | ||
| 614 | if (!sVafinit) | ||
| 615 | afinit(); | ||
| 616 | #endif /* KEEP_UNUSED */ | ||
| 617 | |||
| 618 | afp = aftypes; | ||
| 619 | while (*afp != NULL) { | ||
| 620 | if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) { | ||
| 621 | afp++; | ||
| 622 | continue; | ||
| 623 | } | ||
| 624 | if ((count % 3) == 0) | ||
| 625 | fprintf(stderr, count ? "\n " : " "); | ||
| 626 | txt = (*afp)->name; | ||
| 627 | if (!txt) | ||
| 628 | txt = ".."; | ||
| 629 | fprintf(stderr, "%s (%s) ", txt, (*afp)->title); | ||
| 630 | count++; | ||
| 631 | afp++; | ||
| 632 | } | ||
| 633 | fprintf(stderr, "\n"); | ||
| 634 | } | ||
| 635 | #endif /* KEEP_UNUSED */ | ||
| 636 | |||
| 637 | struct user_net_device_stats { | 291 | struct user_net_device_stats { |
| 638 | unsigned long long rx_packets; /* total packets received */ | 292 | unsigned long long rx_packets; /* total packets received */ |
| 639 | unsigned long long tx_packets; /* total packets transmitted */ | 293 | unsigned long long tx_packets; /* total packets transmitted */ |
| @@ -687,13 +341,6 @@ struct interface { | |||
| 687 | 341 | ||
| 688 | int interface_opt_a = 0; /* show all interfaces */ | 342 | int interface_opt_a = 0; /* show all interfaces */ |
| 689 | 343 | ||
| 690 | #ifdef KEEP_UNUSED | ||
| 691 | static int opt_i = 0; /* show the statistics */ | ||
| 692 | static int opt_v = 0; /* debugging output flag */ | ||
| 693 | |||
| 694 | static int addr_family = 0; /* currently selected AF */ | ||
| 695 | #endif /* KEEP_UNUSED */ | ||
| 696 | |||
| 697 | static struct interface *int_list, *int_last; | 344 | static struct interface *int_list, *int_last; |
| 698 | static int skfd = -1; /* generic raw socket desc. */ | 345 | static int skfd = -1; /* generic raw socket desc. */ |
| 699 | 346 | ||
| @@ -1170,84 +817,6 @@ static char *pr_ether(unsigned char *ptr) | |||
| 1170 | return (buff); | 817 | return (buff); |
| 1171 | } | 818 | } |
| 1172 | 819 | ||
| 1173 | #ifdef KEEP_UNUSED | ||
| 1174 | /* Input an Ethernet address and convert to binary. */ | ||
| 1175 | static int in_ether(char *bufp, struct sockaddr *sap) | ||
| 1176 | { | ||
| 1177 | unsigned char *ptr; | ||
| 1178 | char c, *orig; | ||
| 1179 | int i; | ||
| 1180 | unsigned val; | ||
| 1181 | |||
| 1182 | sap->sa_family = ether_hwtype.type; | ||
| 1183 | ptr = sap->sa_data; | ||
| 1184 | |||
| 1185 | i = 0; | ||
| 1186 | orig = bufp; | ||
| 1187 | while ((*bufp != '\0') && (i < ETH_ALEN)) { | ||
| 1188 | val = 0; | ||
| 1189 | c = *bufp++; | ||
| 1190 | if (isdigit(c)) | ||
| 1191 | val = c - '0'; | ||
| 1192 | else if (c >= 'a' && c <= 'f') | ||
| 1193 | val = c - 'a' + 10; | ||
| 1194 | else if (c >= 'A' && c <= 'F') | ||
| 1195 | val = c - 'A' + 10; | ||
| 1196 | else { | ||
| 1197 | #ifdef DEBUG | ||
| 1198 | bb_error_msg("in_ether(%s): invalid ether address!\n", orig); | ||
| 1199 | #endif | ||
| 1200 | errno = EINVAL; | ||
| 1201 | return (-1); | ||
| 1202 | } | ||
| 1203 | val <<= 4; | ||
| 1204 | c = *bufp; | ||
| 1205 | if (isdigit(c)) | ||
| 1206 | val |= c - '0'; | ||
| 1207 | else if (c >= 'a' && c <= 'f') | ||
| 1208 | val |= c - 'a' + 10; | ||
| 1209 | else if (c >= 'A' && c <= 'F') | ||
| 1210 | val |= c - 'A' + 10; | ||
| 1211 | else if (c == ':' || c == 0) | ||
| 1212 | val >>= 4; | ||
| 1213 | else { | ||
| 1214 | #ifdef DEBUG | ||
| 1215 | bb_error_msg("in_ether(%s): invalid ether address!", orig); | ||
| 1216 | #endif | ||
| 1217 | errno = EINVAL; | ||
| 1218 | return (-1); | ||
| 1219 | } | ||
| 1220 | if (c != 0) | ||
| 1221 | bufp++; | ||
| 1222 | *ptr++ = (unsigned char) (val & 0377); | ||
| 1223 | i++; | ||
| 1224 | |||
| 1225 | /* We might get a semicolon here - not required. */ | ||
| 1226 | if (*bufp == ':') { | ||
| 1227 | #ifdef DEBUG | ||
| 1228 | if (i == ETH_ALEN) { | ||
| 1229 | bb_error_msg("in_ether(%s): trailing : ignored!", orig); | ||
| 1230 | } | ||
| 1231 | #endif | ||
| 1232 | bufp++; | ||
| 1233 | } | ||
| 1234 | } | ||
| 1235 | |||
| 1236 | #ifdef DEBUG | ||
| 1237 | /* That's it. Any trailing junk? */ | ||
| 1238 | if ((i == ETH_ALEN) && (*bufp != '\0')) { | ||
| 1239 | bb_error_msg("in_ether(%s): trailing junk!", orig); | ||
| 1240 | errno = EINVAL; | ||
| 1241 | return (-1); | ||
| 1242 | } | ||
| 1243 | bb_error_msg("in_ether(%s): %s", orig, pr_ether(sap->sa_data)); | ||
| 1244 | #endif | ||
| 1245 | |||
| 1246 | return (0); | ||
| 1247 | } | ||
| 1248 | #endif /* KEEP_UNUSED */ | ||
| 1249 | |||
| 1250 | |||
| 1251 | static const struct hwtype ether_hwtype = { | 820 | static const struct hwtype ether_hwtype = { |
| 1252 | "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN, | 821 | "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN, |
| 1253 | pr_ether, NULL /* UNUSED in_ether */ , NULL | 822 | pr_ether, NULL /* UNUSED in_ether */ , NULL |
| @@ -1261,15 +830,6 @@ static const struct hwtype ether_hwtype = { | |||
| 1261 | 830 | ||
| 1262 | #include <net/if_arp.h> | 831 | #include <net/if_arp.h> |
| 1263 | 832 | ||
| 1264 | #ifdef KEEP_UNUSED | ||
| 1265 | /* Start the PPP encapsulation on the file descriptor. */ | ||
| 1266 | static int do_ppp(int fd) | ||
| 1267 | { | ||
| 1268 | bb_error_msg("You cannot start PPP with this program."); | ||
| 1269 | return -1; | ||
| 1270 | } | ||
| 1271 | #endif /* KEEP_UNUSED */ | ||
| 1272 | |||
| 1273 | static const struct hwtype ppp_hwtype = { | 833 | static const struct hwtype ppp_hwtype = { |
| 1274 | "ppp", "Point-Point Protocol", ARPHRD_PPP, 0, | 834 | "ppp", "Point-Point Protocol", ARPHRD_PPP, 0, |
| 1275 | NULL, NULL, NULL /* UNUSED do_ppp */ , 0 | 835 | NULL, NULL, NULL /* UNUSED do_ppp */ , 0 |
| @@ -1298,40 +858,7 @@ static const struct hwtype * const hwtypes[] = { | |||
| 1298 | NULL | 858 | NULL |
| 1299 | }; | 859 | }; |
| 1300 | 860 | ||
| 1301 | #ifdef KEEP_UNUSED | ||
| 1302 | static short sVhwinit = 0; | ||
| 1303 | |||
| 1304 | static void hwinit() | ||
| 1305 | { | ||
| 1306 | loop_hwtype.title = "Local Loopback"; | ||
| 1307 | unspec_hwtype.title = "UNSPEC"; | ||
| 1308 | #if HAVE_HWETHER | ||
| 1309 | ether_hwtype.title = "Ethernet"; | ||
| 1310 | #endif | ||
| 1311 | #if HAVE_HWTUNNEL | ||
| 1312 | tunnel_hwtype.title = "IPIP Tunnel"; | ||
| 1313 | #endif | ||
| 1314 | #if HAVE_HWPPP | ||
| 1315 | ppp_hwtype.title = "Point-to-Point Protocol"; | ||
| 1316 | #endif | ||
| 1317 | sVhwinit = 1; | ||
| 1318 | } | ||
| 1319 | #endif /* KEEP_UNUSED */ | ||
| 1320 | |||
| 1321 | #ifdef IFF_PORTSEL | 861 | #ifdef IFF_PORTSEL |
| 1322 | #if 0 | ||
| 1323 | static const char * const if_port_text[][4] = { | ||
| 1324 | /* Keep in step with <linux/netdevice.h> */ | ||
| 1325 | {"unknown", NULL, NULL, NULL}, | ||
| 1326 | {"10base2", "bnc", "coax", NULL}, | ||
| 1327 | {"10baseT", "utp", "tpe", NULL}, | ||
| 1328 | {"AUI", "thick", "db15", NULL}, | ||
| 1329 | {"100baseT", NULL, NULL, NULL}, | ||
| 1330 | {"100baseTX", NULL, NULL, NULL}, | ||
| 1331 | {"100baseFX", NULL, NULL, NULL}, | ||
| 1332 | {NULL, NULL, NULL, NULL}, | ||
| 1333 | }; | ||
| 1334 | #else | ||
| 1335 | static const char * const if_port_text[] = { | 862 | static const char * const if_port_text[] = { |
| 1336 | /* Keep in step with <linux/netdevice.h> */ | 863 | /* Keep in step with <linux/netdevice.h> */ |
| 1337 | "unknown", | 864 | "unknown", |
| @@ -1344,18 +871,12 @@ static const char * const if_port_text[] = { | |||
| 1344 | NULL | 871 | NULL |
| 1345 | }; | 872 | }; |
| 1346 | #endif | 873 | #endif |
| 1347 | #endif | ||
| 1348 | 874 | ||
| 1349 | /* Check our hardware type table for this type. */ | 875 | /* Check our hardware type table for this type. */ |
| 1350 | static const struct hwtype *get_hwntype(int type) | 876 | static const struct hwtype *get_hwntype(int type) |
| 1351 | { | 877 | { |
| 1352 | const struct hwtype * const *hwp; | 878 | const struct hwtype * const *hwp; |
| 1353 | 879 | ||
| 1354 | #ifdef KEEP_UNUSED | ||
| 1355 | if (!sVhwinit) | ||
| 1356 | hwinit(); | ||
| 1357 | #endif /* KEEP_UNUSED */ | ||
| 1358 | |||
| 1359 | hwp = hwtypes; | 880 | hwp = hwtypes; |
| 1360 | while (*hwp != NULL) { | 881 | while (*hwp != NULL) { |
| 1361 | if ((*hwp)->type == type) | 882 | if ((*hwp)->type == type) |
| @@ -1391,24 +912,12 @@ static void print_bytes_scaled(unsigned long long ull, const char *end) | |||
| 1391 | int_part = ull; | 912 | int_part = ull; |
| 1392 | i = 4; | 913 | i = 4; |
| 1393 | do { | 914 | do { |
| 1394 | #if 0 | ||
| 1395 | /* This does correct rounding and is a little larger. But it | ||
| 1396 | * uses KiB as the smallest displayed unit. */ | ||
| 1397 | if ((int_part < (1024*1024 - 51)) || !--i) { | ||
| 1398 | i = 0; | ||
| 1399 | int_part += 51; /* 1024*.05 = 51.2 */ | ||
| 1400 | frac_part = ((((unsigned int) int_part) & (1024-1)) * 10) / 1024; | ||
| 1401 | } | ||
| 1402 | int_part /= 1024; | ||
| 1403 | ext += 3; /* KiB, MiB, GiB, TiB */ | ||
| 1404 | #else | ||
| 1405 | if (int_part >= 1024) { | 915 | if (int_part >= 1024) { |
| 1406 | frac_part = ((((unsigned int) int_part) & (1024-1)) * 10) / 1024; | 916 | frac_part = ((((unsigned int) int_part) & (1024-1)) * 10) / 1024; |
| 1407 | int_part /= 1024; | 917 | int_part /= 1024; |
| 1408 | ext += 3; /* KiB, MiB, GiB, TiB */ | 918 | ext += 3; /* KiB, MiB, GiB, TiB */ |
| 1409 | } | 919 | } |
| 1410 | --i; | 920 | --i; |
| 1411 | #endif | ||
| 1412 | } while (i); | 921 | } while (i); |
| 1413 | 922 | ||
| 1414 | printf("X bytes:%llu (%llu.%u %sB)%s", ull, int_part, frac_part, ext, end); | 923 | printf("X bytes:%llu (%llu.%u %sB)%s", ull, int_part, frac_part, ext, end); |
