nrmenus.c

来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 1,653 行 · 第 1/3 页

C
1,653
字号

   for (cp = iptext; *cp > ' '; cp++)  /* find end of IP text */
      ;

   *cp = 0;    /* null terminate iptext */ 
   cp = parse_ipad(&ipaddr, &snbits, iptext);
   if (cp)
   {
      ns_printf(pio, "IP address error: %s\n", cp);
      return -1;
   }

   ns_printf(pio, "replacing net %s IP address ", ifp->name);
   ns_printf(pio, "%u.%u.%u.%u", PUSH_IPADDR(ifp->n_ipaddr) );

   /* replace IP adress in nets[] structure */
   ifp->n_ipaddr = ipaddr;

   /* make default subnet mask */
   mask = (ip_addr) ~0;    /* all 1s */
   while (snbits--)
      mask = mask >> 1;

   ifp->snmask = htonl(~mask);

   ns_printf(pio, " with %u.%u.%u.%u in RAM variables\n", 
    PUSH_IPADDR(ifp->n_ipaddr) );

#ifdef INCLUDE_NVPARMS
   inet_nvparms.ifs[iface].ipaddr = ipaddr;
   inet_nvparms.ifs[iface].subnet = htonl(~mask);

   ns_printf(pio, "Use \"nvset\" to back up to flash or disk\n");
#else
   USE_ARG(iface);
#endif

#ifdef NATRT
   nat_re_init();    /* refresh NAT router's parameters */
#endif

   return 0;
}

#ifdef DNS_CLIENT

/* FUNCTION: gethostbynametest()
 * 
 * PARAM1: void *pio
 *
 * RETURNS: 
 */

int gethostbynametest(void * pio)
{
   char *   cp;
   struct hostent *  p;
   unsigned char *ucp;

   /* 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() with the specified parameter */
#ifdef DNS_CLIENT_UPDT
   p = gethostbyname(cp, 1);
#else
   p = gethostbyname(cp);
#endif /* DNS_CLIENT_UPDT */

   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
   {
      while (*(p->h_addr_list))
      {
         ucp = (unsigned char *) *(p->h_addr_list);
         ns_printf(pio,"\t%d.%d.%d.%d\n",
          *ucp, *(ucp + 1), *(ucp + 2), *(ucp + 3));
         p->h_addr_list++;
      }
   }

   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)
      {
         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
 */

int
ping_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
 */

int
ping_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;
}

/* (yaxon add) */
#include "includes.h"
#include "message.h"
#include "public.h"
#include "tools.h"
#include "gsmtask.h"
/* (yaxon add) */


/* 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
 */

int
ping_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 */
   
/* char * temp;      yaxon add */

   e = in_reshost(host, &activehost, RH_VERBOSE | RH_BLOCK);
   if (e)
      activehost = oldhost;
/* (yaxon add) */
   else {
      HostIP.ip = activehost;
      StorePubPara(HOSTIP_);
      
/*    temp = print_ipad(activehost);
      if (strlen(temp) < sizeof(SockIP.ipstr)) {
          memcpy(SockIP.ipstr, (INT8U *)temp, strlen(temp));
          SockIP.ipstr[strlen(temp)] = 0;
          StorePubPara(SOCKIP_);
      }*/
   }
/* (yaxon add) */
   return e;
}

/* (yaxon add) */
int
set_tel(void *pio)
{
    char *p;
    
    p = nextarg(((GEN_IO)pio)->inbuf);
    if (strlen(p) > sizeof(MyTel.tel)) {
        dprintf("sorry, telephone is too long\n");
    } else {
        MyTel.len = strlen(p);
        MovStr(MyTel.tel, p);
        StorePubPara(MYTEL_);
        dprintf("my telephone is %s\n", p);
    }
    return 0;
}

void RequestResetGSM(void);

int reset_gsm(void *pio)
{
    pio = pio;
    RequestResetGSM();
    return 0;
}
/* (yaxon add) */


#ifdef   MINI_PING
int
mini_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.
 */

int
change_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   /* IN_MENUS */

/* end of file nrmenus.c */


⌨️ 快捷键说明

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