int main(int argc, char **argv) { int i, lop, what; struct option longopts[] = { {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"all", 0, 0, 'a'}, {"delete", 0, 0, 'd'}, {"file", 0, 0, 'f'}, {"numeric", 0, 0, 'n'}, {"set", 0, 0, 's'}, {"protocol", 1, 0, 'A'}, {"hw-type", 1, 0, 'H'}, {"device", 1, 0, 'i'}, {"help", 0, 0, 'h'}, {"use-device", 0, 0, 'D'}, {"symbolic", 0, 0, 'N'}, {NULL, 0, 0, 0} }; #if I18N setlocale (LC_ALL, ""); bindtextdomain("net-tools", "/usr/share/locale"); textdomain("net-tools"); #endif /* Initialize variables... */ if ((hw = get_hwtype(DFLT_HW)) == NULL) { fprintf(stderr, _("%s: hardware type not supported!\n"), DFLT_HW); return (-1); } if ((ap = get_aftype(DFLT_AF)) == NULL) { fprintf(stderr, _("%s: address family not supported!\n"), DFLT_AF); return (-1); } what = 0; /* Fetch the command-line arguments. */ /* opterr = 0; */ while ((i = getopt_long(argc, argv, "A:H:adfp:nsei:t:vh?DNV", longopts, &lop)) != EOF) switch (i) { case 'a': what = 1; opt_a = 1; break; case 'f': what = 2; break; case 'd': what = 3; break; case 's': what = 4; break; case 'e': opt_e = 1; break; case 'n': opt_n = FLAG_NUM; break; case 'D': opt_D = 1; break; case 'N': opt_N = FLAG_SYM; fprintf(stderr, _("arp: -N not yet supported.\n")); break; case 'v': opt_v = 1; break; case 'A': case 'p': ap = get_aftype(optarg); if (ap == NULL) { fprintf(stderr, _("arp: %s: unknown address family.\n"), optarg); exit(-1); } break; case 'H': case 't': hw = get_hwtype(optarg); if (hw == NULL) { fprintf(stderr, _("arp: %s: unknown hardware type.\n"), optarg); exit(-1); } hw_set = 1; break; case 'i': safe_strncpy(device, optarg, sizeof(device)); break; case 'V': version(); case '?': case 'h': default: usage(); } if (ap->af != AF_INET) { fprintf(stderr, _("arp: %s: kernel only supports 'inet'.\n"), ap->name); exit(-1); } /* If not hw type specified get default */ if(hw_set==0) if ((hw = get_hwtype(DFLT_HW)) == NULL) { fprintf(stderr, _("%s: hardware type not supported!\n"), DFLT_HW); return (-1); } if (hw->alen <= 0) { fprintf(stderr, _("arp: %s: hardware type without ARP support.\n"), hw->name); exit(-1); } if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); exit(-1); } /* Now see what we have to do here... */ switch (what) { case 0: opt_e = 1; what = arp_show(argv[optind]); break; case 1: /* show an ARP entry in the cache */ what = arp_show(argv[optind]); break; case 2: /* process an EtherFile */ what = arp_file(argv[optind] ? argv[optind] : "/etc/ethers"); break; case 3: /* delete an ARP entry from the cache */ what = arp_del(&argv[optind]); break; case 4: /* set an ARP entry in the cache */ what = arp_set(&argv[optind]); break; default: usage(); } exit(what); }
int arp_main(int argc, char **argv) { int what, i; /* Initialize variables... */ if ((hw = get_hwtype(DFLT_HW)) == NULL) { bb_error_msg("%s: hardware type not supported!\n", DFLT_HW); return -1; } if ((ap = get_aftype(DFLT_AF)) == NULL) { bb_error_msg("%s: address family not supported!\n", DFLT_AF); return -1; } what = 0; /* Fetch the command-line arguments. */ while ((i = getopt(argc, argv, "A:H:adfp:nsei:t:vh?DNV")) != EOF) switch (i) { case 'a': what = 1; opt_a = 1; break; case 'f': what = 2; break; case 'd': what = 3; break; case 's': what = 4; break; case 'e': opt_e = 1; break; case 'n': opt_n = 1; break; case 'D': opt_D = 1; break; case 'v': opt_v = 1; break; case 'A': case 'p': ap = get_aftype(optarg); if (ap == NULL) { bb_error_msg("%s: unknown address family.\n", optarg); exit(-1); } break; case 'H': case 't': hw = get_hwtype(optarg); if (hw == NULL) { bb_error_msg("%s: unknown hardware type.\n", optarg); exit(-1); } hw_set = 1; break; case 'i': safe_strncpy(device, optarg, sizeof(device)); break; case '?': case 'h': default: bb_show_usage(); } if (ap->af != AF_INET) { bb_error_msg("%s: kernel only supports 'inet'.\n", ap->name); exit(-1); } /* If not hw type specified get default */ if (hw_set==0) { if ((hw = get_hwtype(DFLT_HW)) == NULL) { bb_error_msg("%s: hardware type not supported!\n", DFLT_HW); return (-1); } } if (hw->alen <= 0) { bb_error_msg("%s: hardware type without ARP support.\n", hw->name); exit(-1); } if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); return -1; } /* Now see what we have to do here... */ switch (what) { case 0: opt_e = 1; what = arp_show(argv[optind]); break; case 1: /* show an ARP entry in the cache */ what = arp_show(argv[optind]); break; case 2: /* process an EtherFile */ what = arp_file(argv[optind] ? argv[optind] : "/etc/ethers"); break; case 3: /* delete an ARP entry from the cache */ what = arp_del(&argv[optind]); break; case 4: /* set an ARP entry in the cache */ what = arp_set(&argv[optind]); break; default: bb_show_usage(); } return what; }