int arp_main(int argc ATTRIBUTE_UNUSED, char **argv) { char *hw_type; char *protocol; /* Initialize variables... */ ap = get_aftype(DFLT_AF); if (!ap) bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, &hw_type, &hw_type, &device); argv += optind; if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { ap = get_aftype(protocol); if (ap == NULL) bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); } if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { hw = get_hwtype(hw_type); if (hw == NULL) bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); hw_set = 1; } //if (option_mask32 & ARP_OPT_i)... -i if (ap->af != AF_INET) { bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); } /* If no hw type specified get default */ if (!hw) { hw = get_hwtype(DFLT_HW); if (!hw) bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type"); } if (hw->alen <= 0) { bb_error_msg_and_die("%s: %s without ARP support", hw->name, "hardware type"); } sockfd = xsocket(AF_INET, SOCK_DGRAM, 0); /* Now see what we have to do here... */ if (option_mask32 & (ARP_OPT_d|ARP_OPT_s)) { if (argv[0] == NULL) bb_error_msg_and_die("need host name"); if (option_mask32 & ARP_OPT_s) return arp_set(argv); return arp_del(argv); } //if (option_mask32 & ARP_OPT_a) - default return arp_show(argv[0]); }
/* Process an EtherFile */ static int arp_file(char *name) { char buff[1024]; char *sp, *args[32]; int linenr, argc; FILE *fp; if ((fp = fopen(name, "r")) == NULL) { bb_error_msg("cannot open etherfile %s!\n", name); return -1; } /* Read the lines in the file. */ linenr = 0; while (fgets(buff, sizeof(buff), fp) != (char *) NULL) { linenr++; if (opt_v == 1) fprintf(stderr, ">> %s", buff); if ((sp = strchr(buff, '\n')) != (char *) NULL) *sp = '\0'; if (buff[0] == '#' || buff[0] == '\0') continue; argc = getargs(buff, args); if (argc < 2) { bb_error_msg("format error on line %u of etherfile %s!\n", linenr, name); continue; } if (strchr (args[0], ':') != NULL) { /* We have a correct ethers file, switch hw adress and hostname for arp */ char *cp; cp = args[1]; args[1] = args[0]; args[0] = cp; } if (arp_set(args) != 0) bb_error_msg("cannot set entry on line %u of etherfile %s!\n", linenr, name); } (void) fclose(fp); return 0; }
/* Process an EtherFile */ static int arp_file(char *name) { char buff[1024]; char *sp, *args[32]; int linenr, argc; FILE *fp; if ((fp = fopen(name, "r")) == NULL) { fprintf(stderr, _("arp: cannot open etherfile %s !\n"), name); return (-1); } /* Read the lines in the file. */ linenr = 0; while (fgets(buff, sizeof(buff), fp) != (char *) NULL) { linenr++; if (opt_v == 1) fprintf(stderr, ">> %s", buff); if ((sp = strchr(buff, '\n')) != (char *) NULL) *sp = '\0'; if (buff[0] == '#' || buff[0] == '\0') continue; argc = getargs(buff, args); if (argc < 2) { fprintf(stderr, _("arp: format error on line %u of etherfile %s !\n"), linenr, name); continue; } if (arp_set(args) != 0) fprintf(stderr, _("arp: cannot set entry on line %u of etherfile %s !\n"), linenr, name); } (void) fclose(fp); return (0); }
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; }
int arp_main(int argc, char **argv) { char *hw_type; char *protocol; unsigned int ulRet = 0; /* Initialize variables... */ ap = get_aftype(DFLT_AF); if (!ap) bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); getopt32(argv, "A:c:H:t:i:adnDsv", &protocol, &protocol, &hw_type, &hw_type, &device); argv += optind; /*start of atp add code for arp send mac by ourself by c00126165 2008-7-15*/ ulRet = atp_arp_send_packet_main(protocol,(char *)device); if (ulRet == 1) { return 0; } /*end of atp add code for arp send mac by ourself by c00126165 2008-7-15*/ if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { ap = get_aftype(protocol); if (ap == NULL) bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); } if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { hw = get_hwtype(hw_type); if (hw == NULL) bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); hw_set = 1; } //if (option_mask32 & ARP_OPT_i)... -i if (ap->af != AF_INET) { bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); } /* If no hw type specified get default */ if (!hw) { hw = get_hwtype(DFLT_HW); if (!hw) bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type"); } if (hw->alen <= 0) { bb_error_msg_and_die("%s: %s without ARP support", hw->name, "hardware type"); } sockfd = xsocket(AF_INET, SOCK_DGRAM, 0); /* Now see what we have to do here... */ if (option_mask32 & (ARP_OPT_d|ARP_OPT_s)) { if (argv[0] == NULL) bb_error_msg_and_die("need host name"); if (option_mask32 & ARP_OPT_s) return arp_set(argv); return arp_del(argv); } //if (option_mask32 & ARP_OPT_a) - default return arp_show(argv[0]); }