⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nrmenus.c

📁 internich公司实现的一个非常非常小的OS
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * FILENAME: nrmenus.c * * Copyright 1997- 2004 By InterNiche Technologies Inc. All rights reserved * Portions Copyright 1990-1996 by NetPort * * Software Menus for InterNiche sample/demo TTY console.  * * MODULE: NTF * * ROUTINES: atohl(), atoh(), btree_routes(), change_pwd(), do_dtrap(),  * ROUTINES: dumpbufs(), dump_bytes(), dumpqueues(), get1ch(), gethost2test(),  * ROUTINES: gethostbynametest(), hex2bin(), hexnibble(), ishexdigit(),  * ROUTINES: menu_exit(), mini_ping(), mn_add_route(), nsupdatetest(),  * ROUTINES: nummenus(), ping_setdelay(), ping_sethost(), ping_setlength(),  * ROUTINES: setdnssvr(), setlossy(), show_routes(), showver(), tcpecho(),  * ROUTINES: tk_awaken(), tk_killit(), tk_susp(), udpecho(),  * * PORTABLE: yes */#include "license.h"#include "ipport.h"#include "menu.h"#ifdef IN_MENUS#include "in_utils.h"#define  t_time   unsigned longextern   int   station_state(void * pio);extern   int   mh_stats(void * pio);extern   int   set_upc(void * pio);extern   int   iface_stats(void * pio);extern   int   linkstats(void * pio);extern   int   dumpbufs(void * pio);extern   int   dumpqueues(void * pio);extern   int   showver (void * pio);extern   int   dns_state (void * pio);extern   int   set_nv_params (void * pio);extern   int   edit_nv_params(void * pio);extern   int   tk_stats(void * pio);extern   int   tk_susp(void * pio);extern   int   tk_awaken(void * pio);extern   int   tk_killit(void * pio);int   menu_exit (void * pio);int   do_dtrap (void * pio);int   defaulttype(void * pio);int   dump_bytes(void * pio);int   set_ipaddr(void * pio);extern   int   settrapsize(void * pio); /* array of menu options, see menu.h */struct menu_op mainmenu[]  = {   "general",  stooges,          "main menu",      /* menu ID */   "help",     help,             "help with menus",   "state",    station_state,    "show current station setup",#ifdef UDPSTEST   "uesend",   udpecho, "open UDP echo client, send UDP echo packet",   "uesinit",  udp_secho_init,   "start UDP echo server",   "uechalt",  udp_cecho_close,  "close UDP echo client",   "ueshalt",  udp_secho_close,  "close UDP echo server",   "uestats",  udp_echo_stats,   "UDP echo statistics",#endif#ifdef TCP_ECHOTEST   "tesend",   tcpecho, "open TCP echo client, send TCP echo packet",   "tesinit",  tcp_secho_init,   "start TCP echo server",   "teshalt",  tcp_secho_close,  "close TCP echo server",   "techalt",  tcp_cecho_close,  "close TCP echo client",   "testats",  tcp_echo_stats,   "TCP echo statistics",#endif   /* the parameters set by three are used outside of ping, so these    * routines should always be included even if PING_APP is not    */#ifndef NTF   "delay",    ping_setdelay,  "set milliseconds to wait between pings",   "host",     ping_sethost,   "set default active IP host",   "length",   ping_setlength, "set default ping packet length",#endif /* !NTF */   "quit",     menu_exit,        "quit station program",#ifdef   MINI_PING   "ping",     mini_ping,        "send a ping",#endif   /* MINI_PING */#ifdef INCLUDE_NVPARMS   "nvset",    set_nv_params,    "set non-volatile parameters",   "nvedit",   edit_nv_params,   "edit non-volatile parameters",#endif#ifndef NTF   "setip",    set_ipaddr,       "set interface IP address",#endif /* !NTF */   "version",  showver,          "display version information",   "!command", NULL,             "pass command to OS shell",   NULL,};/* array of menu options, see menu.h */struct menu_op diagmenu[]  = {   "diagnostic",stooges,      "diagnostic aid menu",#if defined(NET_STATS) && defined(INCLUDE_ARP)   "arps",     arp_stats,     "display ARP stats and table",#endif   /* INCLUDE_ARP && NET_STATS */#ifndef NTF   "buffers",  dumpbufs,      "display free q buffer stats",   "queues",   dumpqueues,    "dump packet buffer queues",   "dbytes",   dump_bytes,    "dump block of memory",   "debug",    setdebug,      "set IP stack debug tracing",#endif /* !NTF */   "dtrap",    do_dtrap,      "try to hook debugger",#ifdef VFS_FILES   "dir",      vfs_dir,       "directory of VFS files",#endif   /* VFS_FILES */#ifdef  LOSSY_IO   "lossy",    setlossy,      "set lossy packet IO options",#endif#ifdef NET_STATS#ifndef NTF   "iface",    iface_stats,   "display net interface stats",#endif /* !NTF */#endif#ifndef NTF   "linkstats",linkstats,     "display link layer specific stats",#endif /* !NTF */#ifdef HEAP_STATS    /* statistics keeping npalloc() and npfree() */   "memory",   mh_stats,      "list currently alloced memory",#endif   /* HEAP_STATS */#ifdef DNS_CLIENT   "nsdatabase", dnc_database,   "dump DNS client database",   "nslookup", gethostbynametest,"do DNS gethostbyname()",   "setdnssvr", setdnssvr,       "set up DNS Servers",#ifdef IP_V6   "ns2lookup",   gethost2test,  "do DNS gethostbyname2( AF_INET6)",#endif   /* IP_V6 */#ifdef  DNS_CLIENT_UPDT    "nsupdate", nsupdatetest,  "do Dynamic DNS update",#endif  /* DNS_CLIENT_UPDT */#ifdef NET_STATS   "dnsstats", dns_state,     "DNS setup & statistics",#endif#endif   /* DNS_CLIENT */#ifdef INCLUDE_TCP#ifdef NET_STATS#ifndef MINI_TCP   "mbuf",     mbuf_stat,      "display mbuf stats",   "mlist",    mbuf_list,      "display mbufs in use",#endif   /* MINI_TCP */   "tcp",      tcp_stat,       "display TCP stats",   "sockets",  sock_list,      "display socket list",    "tbconn",   tcp_bsdconnstat,"tcp BSD connection stats",   "tbsend",   tcp_bsdsendstat,"tcp BSD send stats",   "tbrcv",    tcp_bsdrcvstat, "tcp BSD receive stats",#endif   /* NET_STATS */#endif   /* INCLUDE_TCP */#ifdef IP_ROUTING   "routes",   show_routes,    "display IP route table",   "rtadd",    mn_add_route,   "manually add IP route to table",#endif   /* IP_ROUTING */   "allocsize",settrapsize,    "set size for alloc() breakpoint",#ifdef NET_STATS#ifndef NTF   "ipstat",   ip_stats,       "display IP layer stats",   "icmpstat", icmp_stats,     "display ICMP layer stats",   "udp",      udp_stats,      "display UDP layer stats",#endif /* !NTF */#endif#ifndef NTF   "upcall",   set_upc,        "trace received packets",#endif /* !NTF */#if defined(INICHE_TASKS) || defined(CHRONOS)   "tkstats",  tk_stats,       "tasking system status",   "tksuspend",tk_susp,        "tasking system task suspend",   "tkwake",   tk_awaken,      "tasking system task awaken",   "tkkill",   tk_killit,      "tasking system task kill",#endif#ifdef DHCP_CLIENT#ifdef NET_STATS   "dcstats",  dhc_stats,      "DHCP Client statistics",#endif#endif#ifdef IP_PMTU#ifdef NET_STATS   "pmtu",     pmtu_stats,     "Path MTU cache statistics",#endif#endif#ifdef CHANGE_PWD   "changepwd",change_pwd,    "change user password",#endif   NULL,};struct menu_op *  menus[] =      /* array of ptrs to menu groups */{   &mainmenu[0],  /* general menu should come 1st */   &diagmenu[0],  /* Diagnostic menu              */#ifdef ROUTE_TEST   &rt_menu[0],#endif   /* ROUTE_TEST */#ifdef USE_PROFILER   &profmenu[0],#endif   /* add new menus here */   NULL,          /* spare slot(s) for dymanic menu additions */   NULL,          /* Eg., RIP , NATRT, TELNET, PING install dynamic menus */   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,          /* NULL slot at end - end of menus marker */};int      nummenus = (sizeof(menus)/sizeof(void*)); /* number of menus *//* FUNCTION: do_dtrap() *  * PARAM1: void * pio * * RETURNS:  */int do_dtrap(void * pio){   USE_VOID(pio);   dtrap();   return 0;}/* FUNCTION: ishexdigit() * * some hex digit manipulation routines: *  * PARAM1: char digit * * RETURNS:  */int   /* boolean */ishexdigit(char digit)  /* return TRUE is char is hex digit */{   if (isdigit(digit))      return TRUE;   digit |= 0x20;       /* mask letters to lowercase */   if ((digit >= 'a') && (digit <= 'f'))      return TRUE;   else      return FALSE;}/* FUNCTION: hexnibble() *  * PARAM1: char digit * * RETURNS:  */unsigned hexnibble(char digit){   if (digit <= '9')      return (digit-'0'    );   digit &= ~0x20;   /* letter make uppercase */   return (digit-'A')+10 ;}/* FUNCTION: atoh() * * atoh() - convert hex ascii string to unsigned. number may be preceeded * by whitspace or "0x". Halts at first non hex digit character. * *  * PARAM1: char * buf * * RETURNS:  */unsignedatoh(char * buf){   unsigned retval = 0;   char *   cp;   char  digit;   cp = buf;   /* skip past spaces and tabs */   while (*cp == ' ' || *cp == 9)      cp++;   /* while we see digits and the optional 'x' */   while (ishexdigit(digit = *cp++) || (digit == 'x'))   {      /* its questionable what we should do with input like '1x234',        * or for that matter '1x2x3', what this does is ignore all        */      if (digit == 'x')         retval = 0;      else         retval = (retval << 4) + hexnibble(digit);   }   return retval;}/* FUNCTION: atohl() * * atohl() - same as atoh() above, except returns a long *  * PARAM1: char * buf * * RETURNS:  */unsigned longatohl(char * buf){   unsigned long retval = 0;   char *   cp;   char  digit;   cp = buf;   /* skip past spaces and tabs */   while (*cp == ' ' || *cp == 9)      cp++;   /* while we see digits and the optional 'x' */   while (ishexdigit(digit = *cp++) || (digit == 'x'))   {      /* its questionable what we should do with input like '1x234',        * or for that matter '1x2x3', what this does is ignore all        */      if (digit == 'x')         retval = 0;      else         retval = (retval << 4) + hexnibble(digit);   }   return retval;}/* FUNCTION: hex2bin() * * hex2bin() - convert hexadecimal text into binary. Returns 0 if OK  * else error code in invalid hex char encountered in input string.  * *  * PARAM1: char * inbuf * PARAM2: unsigned char * outbuf * PARAM3: int bcount * * RETURNS:  */inthex2bin(char * inbuf, unsigned char * outbuf, int bcount){   int   i;   char *   cp =  inbuf;   for (i = 0; i < bcount; i++)   {      if (ishexdigit(*cp))         outbuf[i] = (unsigned char)(hexnibble(*cp) << 4);      else         return -1;      cp++;      if (ishexdigit(*cp))         outbuf[i] |= (unsigned char)hexnibble(*cp);      else         return -1;      cp++;   }   return 0;}#ifdef  LOSSY_IOextern int  in_lossrate;intsetlossy(void * pio){   char *   cp =  nextarg( ((GEN_IO)pio)->inbuf );   if(*cp == 'r')   {      NDEBUG |= LOSSY_RX;   }   else if(*cp == 't')   {      NDEBUG |=  LOSSY_TX;   }   else if(*cp == 'o')   {      NDEBUG &= ~(LOSSY_TX|LOSSY_RX);   }   else if(isdigit(*cp))   {      in_lossrate = atoi(cp);   }   else   {      ns_printf(pio, "usage: lossrate <'rx'|'tx'|'off'|rate>\n");   }   if(in_lossrate && ((NDEBUG & (LOSSY_RX|LOSSY_TX)) == 0))      ns_printf(pio, "lossy data is disabled\n");   else   {      ns_printf(pio, "pkt loss rate currently 1 in %d ", in_lossrate);      if(NDEBUG & LOSSY_RX)         ns_printf(pio, "RX ");      if(NDEBUG & LOSSY_TX)         ns_printf(pio, "TX");      ns_printf(pio, "\n");   }      return 0;}#endif   /* LOSSY_IO *//* FUNCTION: dumpqueues() *  * PARAM1: void * pio * * RETURNS:  */intdumpqueues(void * pio){   USE_ARG(pio);   return 0;}#ifdef NPDEBUGextern   PACKET   pktlog[MAXPACKETS];#endif/* FUNCTION: dumpbufs() * * dumpbufs() - dump packet free queues *  * PARAM1: void * pio * * RETURNS:  */intdumpbufs(void * pio){#ifdef NPDEBUG   int   i;   PACKET pkt;   int   lines =  1; /* output line count for paging */   char *   cp;   int   offset   =  0;   /* optional parameter is how far into the each buffer to start display */   cp = nextarg(((GEN_IO)pio)->inbuf);   if (cp && *cp)   {      offset = atoi(cp);   }   ns_printf(pio,"PACKET    len  buffer    que data offset %d\n",offset);   for (i = 0; i < (int)(lilbufs+bigbufs); i++ )   {      pkt = pktlog[i];      ns_printf(pio,"%p,%4d,%p,%s:",       pkt, pkt->nb_blen, pkt->nb_buff, qname(pkt));      hexdump(pio,pkt->nb_buff + offset, 12);      lines++;      if ( con_page(pio,lines) )         return 0 ;   }#else   ns_printf(pio,"Not debug build\n");#endif   return 0;}#ifdef INCLUDE_TCP#ifdef NET_STATSchar * socket_queue_name(PACKET pkt);#endif   /* NET_STATS */#endif   /* INCLUDE_TCP */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -