?? nrmenus.c
字號:
ns_printf(pio, "DNS server number must be 1-%d\n", MAXDNSSERVERS); return -1; } } else /* no server number given, default to first server */ { svr_num = 1; } for (cp = iptext; *cp > ' '; cp++) /* find end of IP text */ ; *cp = 0; /* null terminate iptext */ cp = parse_ipad(&dns_servers[svr_num-1], &subnet, iptext); if (cp) { ns_printf(pio, "IP address error: %s\n", cp); return -1; }#ifdef INCLUDE_NVPARMS MEMCPY(inet_nvparms.dns_servers, dns_servers, sizeof(dns_servers)); ns_printf(pio, "Use \"nvset\" to back up to flash or disk\n");#endif return 0;}#ifdef DNS_CLIENT_UPDT/* FUNCTION: nsupdatetest() * * Allows the user to add the ip address of a domain name using the * Dynamic DNS update protocol as specified in rfc 2136. * * PARAM1: void *pio * * RETURNS: */int nsupdatetest(void * pio){ char * cp; char * ucp; char dnbuf[1025]; /* buffer for domain name */ unsigned snbits; /* output of parse_ipaddr- subnet value */ ip_addr ipout; /* output of parse_ipaddr- ip address */ unsigned long r_ttl; int p; /* Return code from sending update packet */ unshort del_flag = 0; /* see if user put ADD on cmd line */ cp = nextarg(((GEN_IO)pio)->inbuf); if (!strncmp(cp, "add",3) && (!strncmp(cp, "delete",6))) { ns_printf(pio,"usage: nsupdate add <domain name> <ttl> A <ip addr>\n"); ns_printf(pio,"usage: nsupdate delete <domain name>\n"); return -1; } if (strncmp(cp, "delete",6) == 0) del_flag = 1; /* get next parameter. This must be the domain name.*/ cp = nextarg(cp); if (!*cp) { ns_printf(pio, "usage: nsupdate add <domain name> <ttl> A <ip addr>\n"); ns_printf(pio,"usage: nsupdate delete <domain name>\n"); return -1; } strcpy(dnbuf,cp); ucp = &dnbuf[0]; while (*ucp != ' ') ucp++; *ucp = '\0'; /* If this is a delete operation, call dns_update with zero values for */ /* ttl and ip_addr */ if (del_flag == 1) { r_ttl = 0; /* ttl is 0 */ ipout = 0; /* ip address is 0 */ p = dns_update(soa_mname, dnbuf, ipout, r_ttl, pio); if (p >= 0) ns_printf(pio, "Update function returned the following response: %d\n",p); else ns_printf(pio, "Authoritative name server not found\n"); return 0; } /* Next parameter must be ttl */ cp = nextarg(cp); if (!(isdigit(*cp))) { ns_printf(pio, "usage: nsupdate add <domain name> <ttl> A <ip addr>\n"); ns_printf(pio,"usage: nsupdate delete <domain name>\n"); return -1; } else r_ttl = atol(cp); /* Next parameter must be class- in this case an A */ cp = nextarg(cp); if (*cp != 'A') { ns_printf(pio, "usage: nsupdate add <domain name> <ttl> A <ip addr>\n"); ns_printf(pio,"usage: nsupdate delete <domain name>\n"); return -1; } /* Final parameter is an ip address */ cp = nextarg(cp); if (parse_ipad(&ipout, &snbits, cp)) { ns_printf(pio, "usage: nsupdate add <domain name> <ttl> A <ip addr>\n"); ns_printf(pio,"usage: nsupdate delete <domain name>\n"); return -1; } p = dns_update(soa_mname, dnbuf, ipout, r_ttl, pio); if (p >= 0) { ns_printf(pio, "Update function returned the following error: %d\n",p); } else ns_printf(pio, "Authoritative name server not found\n"); return 0;}#endif /* DNS_CLIENT_UPDT */#endif /* DNS_CLIENT *//* FUNCTION: ping_setdelay() * * Set the default value of delay (between pings). This value affects all sessions * * PARAM1: GEN_IO pio - device for console output * * RETURNS: 0 on success, or one of the PING error codes */intping_setdelay(void * pio){ u_long newdelay; char * arg = nextarg(((GEN_IO)pio)->inbuf); unsigned num_bits,num_dec_digits; if (*arg < '0' || *arg > '9') { ns_printf(pio,"current ping delay is %ld\n", (pingdelay*TIMEFOR1TICK) ); ns_printf(pio,"to set, enter number of milliseconds on command line.\n"); return PING_DELAY_BAD_ARG; } num_bits = sizeof(long) * 8 ; num_dec_digits = ((num_bits*3)/10) + 1 ; if ( num_dec_digits <= (unsigned)strlen(arg) ) { ns_printf(pio,"Delay value is too large. Max value allowed is 2^%d\n", num_bits); return PING_DELAY_BAD_ARG; } newdelay = atol(arg); pingdelay = newdelay/TIMEFOR1TICK; /* save in PC ticks */ ns_printf(pio,"set inter-ping delay to (approx) %ld ms.\n", pingdelay*TIMEFOR1TICK); return SUCCESS;}/* FUNCTION: ping_setlength() * * Set the default value of length of ping packets. * This value affects all sessions * * PARAM1: GEN_IO pio - device for console output * * RETURNS: 0 on success, or one of the PING error codes */intping_setlength(void * pio) /* menu routine to set default ping size */{ char * cp = nextarg(((GEN_IO)pio)->inbuf); int newlen; if (!*cp) /* no arg given */ { ns_printf(pio,"default ping length is %d\n", deflength); ns_printf(pio,"To change it, put new number on command line\n"); return PING_LEN_BAD_ARG; } newlen = atoi(cp); if (newlen < 60 || newlen > 1500) ns_printf(pio,"CAUTION: %d is unusual length\n", newlen); deflength = newlen; return SUCCESS;}/* FUNCTION: ping_sethost() * * Set the default host to be pinged. * This value affects all sessions. * * PARAM1: GEN_IO pio - device for console output * PARAM2: char * host = nextarg(((GEN_IO * * RETURNS: 0 on success, or one of the PING error codes */intping_sethost(void * pio) /* set default host for pings, et.al. */{ int e; char * host = nextarg(((GEN_IO)pio)->inbuf); ip_addr oldhost = activehost; /* save old host in case it breaks */ e = in_reshost(host, &activehost, RH_VERBOSE | RH_BLOCK); if (e) activehost = oldhost; return e;}#ifdef MINI_PINGintmini_ping(void * pio){ int err; if(!activehost) { ns_printf(pio,"set host first\n"); return 1; } err = icmpEcho(activehost, NULL, deflength, 88); if(err == 0) ns_printf(pio,"ping sent, check icmp for reply\n"); else ns_printf(pio,"ping send error %d\n", err); return err; }#endif /* MINI_PING */#ifdef CHANGE_PWD /* allow user to change password *//* FUNCTION: get1ch() * * Get 1 char from input device of pio. * * PARAM1: void * vio - device for console input/output * * RETURNS: received char, else -1. */#include "userpass.h"int get1ch(void *vio){ int ch=-1; GEN_IO pio = (GEN_IO)vio; /* convert void* to our IO device type */ if ( pio && pio->getch ) /*if i/p func is supplied*/ { do { ch = (pio->getch)(pio->id); if ( ch == 0 ) tk_yield(); /* Give timeslice to other processes */ } while ( ch == 0 ) ; } return ch;}/* FUNCTION: change_pwd() * * Change the password of a user. * * PARAM1: void * vio - device for console input/output * * RETURNS: 0 on success, else -1. */intchange_pwd(void * pio){ char * user; char * cp = nextarg(((GEN_IO)pio)->inbuf); char oldpwd[MAX_USERLENGTH]; char newpwd[MAX_USERLENGTH]; int i; int ch; if (!*cp) /* no arg given */ { ns_printf(pio,"Error - User name not specfied\n"); ns_printf(pio,"Usage: changepwd <username>\n"); return -1; } user = cp; /* point to start of user name */ while ((*cp != ' ') && (*cp != '\n') && (*cp != '\r') && (*cp != '\t')) cp++; *cp = 0; /* null terminate user name */ /* get the current password */ ns_printf(pio,"Enter old password> "); i=0; do { ch = get1ch(pio); if ((ch != ' ') && (ch != '\n') && (ch != '\r') && (ch != '\t')) { oldpwd[i++] = ch; ns_printf(pio,"*"); } else { oldpwd[i]=0; /* overwrite linefeed with null, to null-terminate */ ns_printf(pio,"\n"); break; } } while (ch != -1); ns_printf(pio,"Enter new password> "); i=0; do { ch = get1ch(pio); if ((ch != ' ') && (ch != '\n') && (ch != '\r') && (ch != '\t')) { newpwd[i++] = ch; ns_printf(pio,"*"); } else { newpwd[i]=0; /* overwrite linefeed with null, to null-terminate */ ns_printf(pio,"\n"); break; } } while (ch != -1); if (add_user(user,oldpwd,newpwd) == TRUE) ns_printf(pio,"Password successfully changed.\n"); else { ns_printf(pio,"Error - couldn't change password.\n"); return -1; } return 0;}#endif /* CHANGE_PWD */#endif /* !NTF */#endif /* IN_MENUS *//* FUNCTION: tk_susp() * * tk_susp() - suspend a task by CLI command * * PARAM1: void * pio * * RETURNS: */int tk_susp(void * pio){#ifdef NET_STATS task * tk; char * arg2; int tid = 0; arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get task index from cmd line */ if (arg2 && *arg2) tid = atoi(arg2); if (tid < 1) { ns_printf(pio,"task id must be > 0\n"); return -1; } tk = tk_cur; do { tk = tk->tk_next; if ( tk->tk_tid == tid ) {#ifdef DEBUG ns_printf(pio,"found task %s: %s\n", arg2, tk->tk_name );#endif /* DEBUG */ tk->tk_flags &= ~TF_AWAKE; tk->tk_waketick = 0; /* clear wakeup tick flag */ break; } } while ( tk != tk_cur );#ifdef DEBUG if ( tk == tk_cur ) ns_printf(pio,"Task %s NOT found\n", arg2); tk_stats(pio);#endif /* DEBUG */#else USE_ARG(pio);#endif return 0;}/* FUNCTION: tk_awaken() * * tk_awaken() - awaken a task by CLI command * * PARAM1: void * pio * * RETURNS: */int tk_awaken(void * pio){#ifdef NET_STATS task * tk; char * arg2; int tid = 0; arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get task index from cmd line */ if (arg2 && *arg2) tid = atoi(arg2); if (tid < 1) { ns_printf(pio,"task id must be > 0\n"); return -1; } tk = tk_cur; do { tk = tk->tk_next; if ( tk->tk_tid == tid ) {#ifdef DEBUG ns_printf(pio,"found task %s: %s\n", arg2, tk->tk_name );#endif /* DEBUG */ tk_wake(tk); break; } } while ( tk != tk_cur );#ifdef DEBUG if ( tk == tk_cur ) ns_printf(pio,"Task %s NOT found\n", arg2); tk_stats(pio);#endif /* DEBUG */#else USE_ARG(pio);#endif return 0;}/* FUNCTION: tk_killit() * * tk_killit() - kill a task by CLI command * * PARAM1: void * pio * * RETURNS: */int tk_killit(void * pio){#ifdef NET_STATS task * tk; char * arg2; int tid = 0; arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get task index from cmd line */ if (arg2 && *arg2) tid = atoi(arg2); if (tid < 1) { ns_printf(pio,"task id must be > 0\n"); return -1; } if (tid == tk_cur->tk_tid ) { ns_printf(pio,"no CLI suicide\n"); return -1; } tk = tk_cur; do { tk = tk->tk_next; if ( tk->tk_tid == tid ) {#ifdef DEBUG ns_printf(pio,"found task %s: %s\n", arg2, tk->tk_name );#endif /* DEBUG */ tk_kill(tk); break; } } while ( tk != tk_cur );#ifdef DEBUG if ( tk == tk_cur ) ns_printf(pio,"Task %s NOT found\n", arg2); tk_stats(pio);#endif /* DEBUG */#else USE_ARG(pio);#endif return 0;}/* end of file nrmenus.c */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -