?? nrmenus.c
字號:
extern char * name;/* FUNCTION: showver() * * PARAM1: void * pio * * RETURNS: */intshowver(void * pio){ ns_printf(pio,"%s\n", name); return 0;}extern char * prompt;/* if we have to deal with Intel's 16 bit segmented architecture */#ifdef SEG16_16/* FUNCTION: dump_bytes() * * segment:offset version of dump_bytes() * * PARAM1: void * pio * * RETURNS: */intdump_bytes(void * pio){ char * cp; unshort seg, offset; int length; cp = nextarg(((GEN_IO)pio)->inbuf); /* see if user put addr on cmd line */ if (!*cp) goto db_prompt; seg = (unshort)atoh(cp);cp = strchr(cp, ':'); /* find colon in string */ if (!cp) goto db_prompt; cp++; offset = (unshort)atoh(cp); cp = nextarg(cp); /* see if user specified length to dump */ if (*cp) /* cp should point to end of args or length */ length = atoh(cp); else /* no length on command line, set a reasonable default */ length = 16; hexdump(pio,_MK_FP(seg, offset), length); return 0;db_prompt: /* prompt user for correct format */ ns_printf(pio,"enter memory location in hex seg:offset form, followed by optional length.\n"); return -1;}#else /* SEG16_16 *//* FUNCTION: dump_bytes() * * flat memory version of dump_bytes() * * PARAM1: void * pio * * RETURNS: */intdump_bytes(void * pio){ char * cp; unsigned int address; int length; cp = nextarg(((GEN_IO)pio)->inbuf); /* see if user put addr on cmd line */ if (!*cp) goto db_prompt; address = atoh(cp); cp = nextarg(cp); /* see if user specified length to dump */ if (*cp) /* cp should point to end of args or length */ length = atoh(cp); else /* no length on command line, set a reasonable default */ length = 16; hexdump(pio,(void *) address, length); return 0;db_prompt: /* prompt user for correct format */ ns_printf(pio,"enter memory location in hex, followed by optional length.\n"); return -1;}#endif /* SEG16_16 *//* FUNCTION: menu_exit() * * PARAM1: void * pio * * RETURNS: */intmenu_exit(void * pio){ USE_VOID(pio);#ifdef NTF appexit(0);#else /* NTF */ netexit(0); /* shut down hardware & exit to system */#endif /* NTF */ return 0; /* keeps compiler from whining */}#ifdef UDPSTEST/* FUNCTION: udpecho() * * PARAM1: void * pio * * RETURNS: */int udpecho(void * pio){ long times = 1; char * arg2; arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get iteration arg from cmd line */ if (arg2 && *arg2) times = atol(arg2); if (times < 1) { ns_printf(pio,"command line arg must be number of echos to send\n"); return -1; } if (activehost == 0L) { ns_printf(pio,"IP host to echo to must be set with \"host\" command\n"); return -1; } /* send echo - this prints it's own errors */ udp_sendecho(pio,activehost, deflength, times); return 0;}#endif /* UDPSTEST */#ifdef TCP_ECHOTEST/* FUNCTION: tcpecho() * * PARAM1: void * pio * * RETURNS: */int tcpecho(void * pio){ long times = 1; char * arg2; arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get iteration arg from cmd line */ if (arg2 && *arg2) times = atol(arg2); if (times < 1) { ns_printf(pio,"command line arg must be number of echos to send\n"); return -1; } if (activehost == 0L) { ns_printf(pio,"IP host to echo to must be set with \"host\" command\n"); return -1; } /* send echo - this prints it's own errors */ tcp_sendecho(pio,activehost, (long)deflength, times); return 0;}#endif /* TCP_ECHOTEST */#ifdef IP_ROUTINGchar * route_prots[] ={ "foo", "OTHER", "LOCAL", "NETMGT", "ICMP", "EGP", "GGP", "HELLO", "RIP",};#ifdef BTREE_ROUTES/* FUNCTION: btree_routes() * * Helper function for displaying routes in the binary tree. A pointer to * this is passed to avldepthfirst(); * * PARAM1: current RtMib * PARAM2: pointer to pio * PARAM3: depth in tree * * RETURNS: */static int brtcount;voidbtree_routes(struct avl_node * node, long param, int depth){ struct RtMib * rtp = (struct RtMib *)node; void * pio = (void*)param; brtcount++; /* if this is first entry then display heading */ if(brtcount == 1) ns_printf(pio,"..IPaddr.......mask.........nexthop...iface..type\n"); while(depth--) ns_printf(pio, " "); ns_printf(pio,"%u.%u.%u.%u %u.%u.%u.%u %u.%u.%u.%u %d %s\n", PUSH_IPADDR(rtp->ipRouteDest), PUSH_IPADDR(rtp->ipRouteMask), PUSH_IPADDR(rtp->ipRouteNextHop), (int)rtp->ipRouteIfIndex, route_prots[(int)rtp->ipRouteProto]);}#endif /* BTREE_ROUTES */#ifndef NTF/* FUNCTION: show_routes() * * PARAM1: void * pio * * RETURNS: */int show_routes(void * pio){ int rtcount = 0;#ifdef BTREE_ROUTES brtcount = 0; avldepthfirst((struct avl_node *)rt_mib, btree_routes, (long)pio, 0); rtcount = brtcount;#else /* not BTREE_ROUTES */ RTMIB rtp; if(!rt_mib) /* system not fully up yet */ return -1; for (rtp = rt_mib; rtp < rt_mib + ipRoutes; rtp++) { if (!rtp->ipRouteNextHop) /* empty slot */ continue; rtcount++; if (rtcount == 1) ns_printf(pio,"..IPaddr.......mask.........nexthop...iface..type\n"); ns_printf(pio,"%u.%u.%u.%u %u.%u.%u.%u %u.%u.%u.%u %d %s\n", PUSH_IPADDR(rtp->ipRouteDest), PUSH_IPADDR(rtp->ipRouteMask), PUSH_IPADDR(rtp->ipRouteNextHop), (int)rtp->ipRouteIfIndex, route_prots[(int)rtp->ipRouteProto]); }#endif /* BTREE_ROUTES */ if (rtcount == 0) ns_printf(pio,"no IP routes set\n"); return 0;}/* FUNCTION: mn_add_route() * * menu routine to manually add a route. format is target.ip * target.mask next.hop iface. * * * PARAM1: void * pio * * RETURNS: */int mn_add_route(void * pio){ char * cp; /* text for interface index */ int ifindex; /* value of interface index */ unsigned snbits; int i; char * errmsg; RTMIB rtp; NET ifp; struct ip_args { /* for reading in IP addresses from console buf */ char * text; ip_addr ipaddr; } ipargs[4]; cp = nextarg(((GEN_IO)pio)->inbuf); /* start of command line args */ for (i = 0; i <= 3; i++) /* read in 4 args */ { ipargs[i].text = cp; if (i == 3) /* last arg is not an IP address, so we're done */ break; /* null terminate IP address arg */ cp = strchr(ipargs[i].text, ' '); if (cp) { *cp++ = '\0'; /* terminate this arg */ while (*cp == ' ')cp++; /* find next arg */ } else /* no space after arg == bogus command line */ { ns_printf(pio,"usage: target.ip target.mask next.hop iface \n"); ns_printf(pio," where 1st 3 parms are in IP dot notation, last is digit 1-%d\n", ifNumber); return -1; } /* call parse_ipad to fill in IP address from text */ errmsg = parse_ipad(&ipargs[i].ipaddr, &snbits, ipargs[i].text); if (errmsg) { ns_printf(pio,"bad IP format \"%s\" in arg %d, \n problem: %s\n", ipargs[i].text, i, errmsg); return -1; } } ifp = if_netbytext(pio, ipargs[i].text); if (ifp == NULL) return -1; else ifindex = if_netnumber(ifp); rtp = add_route(ipargs[0].ipaddr, ipargs[1].ipaddr, ipargs[2].ipaddr, ifindex, IPRP_LOCAL); if (!rtp) { ns_printf(pio,"add_route failed, table full?\n"); return -1; } return 0;}#endif /* IP_ROUTING */#ifdef DNS_CLIENT#ifdef IP_V6/* FUNCTION: gethost2test() * * Resolve a host name to IP address via a call to gethostbyname2() * * PARAM1: void *pio * * RETURNS: */intgethost2test(void * pio){ char * cp; struct hostent * p; /* see if user put name on cmd line */ cp = nextarg(((GEN_IO)pio)->inbuf); if (!cp || !*cp) { ns_printf(pio, "usage: ns2lookup host_name\n"); return -1; } /* call gethostbyname() to resolve the passed name */ p = gethostbyname2(cp, AF_INET6); if (!p) { ns_printf(pio,"gethostbyname2() returned NULL\n"); return 0; } ns_printf(pio,"gethostbyname2() succeeded\n"); ns_printf(pio," h_name is %s\n",p->h_name ? p->h_name : "NULL"); ns_printf(pio," h_addrtype = %d\n",p->h_addrtype); ns_printf(pio," h_length = %d\n",p->h_length); ns_printf(pio," h_addr_list are\n"); if (!(p->h_addr_list)) ns_printf(pio,"\tno addresses\n"); else { char ** cpp; for(cpp = p->h_addr_list; *cpp; cpp++) { char ip6buf[40]; /* tmp buffer for ipv6 address text */ ns_printf(pio,"\t%s\n", print_ip6((struct in6_addr *)(*cpp), ip6buf)); } } return 0;}#endif /* IP_V6 *//* FUNCTION: gethostbynametest() * * Resolve a host name to IP address via a call to gethostbyname() * * PARAM1: void *pio * * RETURNS: */intgethostbynametest(void * pio){ char * cp; struct hostent * p; /* see if user put name on cmd line */ cp = nextarg(((GEN_IO)pio)->inbuf); if (!cp || !*cp) { ns_printf(pio, "usage: nslookup host_name\n"); return -1; } /* call gethostbyname() to resolve the passed name */ p = gethostbyname(cp); if (!p) { ns_printf(pio,"gethostbyname() returned NULL\n"); return 0; } ns_printf(pio,"gethostbyname() succeeded\n"); ns_printf(pio,"h_name is %s\n",p->h_name ? p->h_name : "NULL"); ns_printf(pio,"h_addrtype = %d\n",p->h_addrtype); ns_printf(pio,"h_length = %d\n",p->h_length); ns_printf(pio,"h_addr_list are\n"); if (!(p->h_addr_list)) ns_printf(pio,"\tno addresses\n"); else { char ** cpp; u_char * ucp; for(cpp = p->h_addr_list; *cpp; cpp++) { ucp = (unsigned char *) (*cpp); ns_printf(pio,"\t%d.%d.%d.%d\n", *ucp, *(ucp + 1), *(ucp + 2), *(ucp + 3)); } } return 0;}/* FUNCTION: setdnssvr() * * Allows console user to set a DNS Server's IP address. Useful for testing * the DNS Client. * * PARAM1: void * pio * * RETURNS: 0 on success, or an error code of -1. */int setdnssvr(void * pio){ char * cp; char * iptext; unsigned int subnet; /* dummy for passing to parse_ipad() */ int svr_num; cp = nextarg(((GEN_IO)pio)->inbuf); /* see if user put addr on cmd line */ if (!*cp) { ns_printf(pio, "usage: setdnssvr X.X.X.X [Server No. (1-%d)]\n", MAXDNSSERVERS); return -1; } iptext = cp; /* save pointer to IP spec */ cp = nextarg(cp); /* see if user specified server number */ if (*cp) { svr_num = atoi(cp); if (svr_num < 1 || svr_num > MAXDNSSERVERS) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -