/* FUNCTION: netdiag_gratarp() * * Send a gratuitous ARP request/reply. * * PARAM1: CLI_CTX CLI context * * RETURN: int 0 or error code */ STATIC int netdiag_gratarp(CLI_CTX ctx) { int idx; int arpreq; NET ifp; if (!CLI_HELP(ctx)) { if (!CLI_DEFINED(ctx, 'i')) return (CLI_ERR_MISSING); /* it is a gratuitous ARP request unless '-r' specified */ arpreq = (CLI_DEFINED(ctx, 'r')) ? 1 : 0; idx = (int)CLI_VALUE(ctx, 'i') - 1; if ((idx >= 0) && (idx < (int)ifNumber) && ((ifp = nets[idx]) != (NET)NULL)) { int err = grat_arp(ifp, arpreq); if (err != ENP_SEND_PENDING) return (err); } else return (CLI_ERR_PARAM); } return (0); }
int send_grat_arp(void * pio) { char * cp; struct net * ifp; int flag; ifp = (NET)(netlist.q_head); /* default to first net */ cp = nextarg(((GEN_IO)pio)->inbuf); /* get console arg */ if(cp && *cp) /* arg is present on command line */ { if (*cp == 'a') flag = 0; else if (*cp == 'r') flag = 1; else { ns_printf(pio,"USAGE: sendarp (a|r) [net]\n"); return 0; } } cp = nextarg(cp); /* get console arg */ if(cp && *cp) /* arg is present on command line */ { ifp = if_netbytext(pio, cp); if(ifp == NULL) /* error parsing iface name/number text? */ return -1; } grat_arp(ifp, flag); return 0; }