menulib.c
来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 357 行
C
357 行
/*
* FILENAME: menulib.c
*
* Copyright 2000 By InterNiche Technologies Inc. All rights reserved
*
* Misc utility routines for Interniche menuing system
*
* MODULE: MISCLIB
*
* ROUTINES: setdebug(), set_upc(), snmp_stat(), iface_stats(),
* ROUTINES: ifstats(), linkstats(), settrapsize(), if_configbyname()
* ROUTINES: if_netbytext
*
* PORTABLE: yes
*/
/* Additional Copyrights: */
/* Portions Copyright 1993 by NetPort software */
#include "ipport.h"
#include "in_utils.h"
#include "q.h"
#include "netbuf.h"
#include "net.h"
#include "ip.h"
#include "icmp.h"
#include "ether.h"
#include "arp.h"
#include "menu.h"
#include "nvparms.h"
#include "minip.h" /* (yaxon add) */
int ifstats(void * pio, struct net * ifp);
char * print_uptime(unsigned long timetick);
unsigned atoh(char *);
/* FUNCTION: setdebug()
*
* setdebug() - toggle NDEBUG protocol stack debugging options
*
* PARAM1: void * pio
*
* RETURNS: 0
*/
int
setdebug(void * pio)
{
#ifdef NPDEBUG
char * cp;
/* get an optional parameter */
cp = nextarg(((GEN_IO)pio)->inbuf);
/* if no parameter was entered */
if (!*cp)
{
if (NDEBUG)
{ NDEBUG &= UPCTRACE;
ns_printf(pio,"IP stack debug tracing off\n");
}
else
{ NDEBUG |= INFOMSG|IPTRACE|PROTERR|TPTRACE;
ns_printf(pio,"IP stack debug tracing on\n");
}
}
else
{
/* '?' means display NDEBUG value, else set NDEBUG flag to parameter value */
if (*cp != '?')
{
#ifdef IN_MENUS
NDEBUG = atoh(cp);
#endif
}
ns_printf(pio,"NDEBUG is now 0x%x\n",NDEBUG);
}
#else
ns_printf(pio,"not a DEBUG compile.\n");
#endif
return 0;
}
/* FUNCTION: set_upc()
*
* toggle state of upcall variable
*
* PARAM1: void * pio
*
* RETURNS: 0
*/
int
set_upc(void * pio)
{
if (NDEBUG & UPCTRACE)
NDEBUG &= ~UPCTRACE;
else
NDEBUG |= UPCTRACE;
ns_printf(pio,"Upcall debugging %sabled\n",
(NDEBUG&UPCTRACE)?"en":"dis");
return 0;
}
/* FUNCTION: if_configbyname(NET ifp)
*
* Configure the passed net interface from a set of NV parameters with
* same name. This allows the NV system to specify parameters for
* dynamic interfaces, and also frees the NV file from having to
* specifiy the nets in the order they come up.
*
*
* PARAM1: NET to configure - should have ifp->name set up.
*
* RETURNS: Returns 0 if OK, -1 if name not found
*/
#ifdef INCLUDE_NVPARMS /* only if using NV parms */
int
if_configbyname(NET ifp)
{
int i;
/* search the NV parameters "nets" array for for our name */
for(i = 0; i < MAXNETS; i++)
{
if(strncmp(inet_nvparms.ifs[i].name, ifp->name, IF_NAMELEN - 1) == 0)
{
/* found a matching name, set our IP congif from NV entry */
ifp->n_ipaddr = inet_nvparms.ifs[i].ipaddr;
ifp->snmask = inet_nvparms.ifs[i].subnet;
ifp->n_defgw = inet_nvparms.ifs[i].gateway;
return 0;
}
}
return -1;
}
#endif /* INCLUDE_NVPARMS */
/* FUNCTION: if_netbytext()
*
* get a net pointer based on a user text string. The string may be a ones
* based number index (eg "1", "2") or an iface name ("pp0"). Prints error
* message to passed output device if text does not map to an interface.
*
*
* PARAM1: void * pio - output stream for error reporting
* PARAM2: char * iftext - text of interface.
*
* RETURNS: pointer to iface if OK, else NULL.
*/
NET
if_netbytext(void * pio, char * iftext)
{
unsigned iface;
NET ifp;
if((strlen(iftext) == 1) && (isdigit(*iftext)))
{
iface = (unsigned)(*iftext - '0') - 1;
if((iface >= ifNumber) ||
((ifp = if_getbynum((int)iface)) == NULL))
{
ns_printf(pio,"interface number must be 1 to %d.\n", ifNumber);
return NULL;
}
else
return (ifp);
}
else /* not a single digit, look up as name */
{
for(ifp = (NET)(netlist.q_head); ifp; ifp = ifp->n_next)
{
if(strcmp(iftext, ifp->name) == 0)
return ifp;
}
if(!ifp)
ns_printf(pio,"no interface named \"%s\".\n", iftext);
}
return NULL;
}
/* FUNCTION: iface_stats()
*
* menu routine to get iface number and invoke stats
*
* PARAM1: void * pio - output stream
*
* RETURNS: 0
*/
int
iface_stats(void * pio)
{
char * cp;
struct net * ifp;
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 */
{
ifp = if_netbytext(pio, cp);
if(ifp == NULL) /* error parsing iface name/number text? */
return -1;
}
ifstats(pio, ifp);
return 0;
}
/* FUNCTION: ifstats()
*
* per-iface portion of iface_stats()
*
* PARAM1: void * pio - output stream
* PARAM2: int ifc - interface to dump
*
* RETURNS: 0
*/
int
ifstats(void * pio, struct net * ifp)
{
#ifdef IP_MULTICAST
int idx = 0;
struct in_multi * inm;
struct in_multistep step;
#endif /* IP_MULTICAST */
ns_printf(pio, "Interface %s - %s \n",
ifp->name, ifp->n_mib->ifDescr);
ns_printf(pio,"IP address: %s, " , print_ipad(ifp->n_ipaddr));
ns_printf(pio,"subnet mask: %s, ", print_ipad(ifp->snmask));
ns_printf(pio,"gateway: %s\n" , print_ipad(ifp->n_defgw));
ns_printf(pio,"Status; Admin:%s Oper:%s for: %s\n",
ifp->n_mib->ifAdminStatus==1?"up":"down",
ifp->n_mib->ifOperStatus==1?"up":"down",
print_uptime(sysuptime() - (ifp->n_mib->ifLastChange)));
ns_printf(pio,"rcvd: errors:%lu dropped:%lu station:%lu bcast:%lu bytes:%lu\n",
ifp->n_mib->ifInErrors, ifp->n_mib->ifInDiscards,
ifp->n_mib->ifInUcastPkts, ifp->n_mib->ifInNUcastPkts,
ifp->n_mib->ifInOctets);
ns_printf(pio,"sent: errors:%lu dropped:%lu station:%lu bcast:%lu bytes:%lu\n",
ifp->n_mib->ifOutErrors, ifp->n_mib->ifOutDiscards,
ifp->n_mib->ifOutUcastPkts, ifp->n_mib->ifOutNUcastPkts,
ifp->n_mib->ifOutOctets);
ns_printf(pio,"MAC address: ");
hexdump(pio,ifp->n_mib->ifPhysAddress, 6);
ns_printf(pio," \n");
#ifdef IP_MULTICAST
/*
* Print the multicast addresses that have been
* joined on this interface.
*/
IN_FIRST_MULTI(step, inm, idx);
while ((inm != NULL) && (inm->inm_netp == ifp))
{
ns_printf(pio, " Multicast address: %s\n",print_ipad(inm->inm_addr));
IN_NEXT_MULTI(step, inm, idx);
}
#endif /* IP_MULTICAST */
return 0;
}
/* FUNCTION: linkstats()
*
* printf stats for link interface. default to iface 1
*
* PARAM1: void * pio - output stream
*
* RETURNS: 0 if OK, else -1 if arg is bad.
*/
int
linkstats(void * pio)
{
int iface = 1;
char * cp;
cp = nextarg(((GEN_IO)pio)->inbuf);
if (*cp)
{
iface = atoi(cp);
if (iface < 1 || iface > (int)ifNumber)
{
ns_printf(pio,"interface number must be 1 to %d.\n", ifNumber);
return -1;
}
}
iface--;
if (nets[iface]->n_stats)
nets[iface]->n_stats(pio,iface); /* actually call the stats */
else
ns_printf(pio,"no stats routine for interface %d\n", iface+1);
return 0;
}
/* FUNCTION: settrapsize()
*
* settrapsize() - This sets a value which will cause the memory
* managment monitoring code to trap to a debugger if a malloc is
* attempted for this size. This is usefull when a memory leak is
* occuring of memory buffers on an unusual size, as often happens
* with networking code. It has nothing to do with SNMP traps.
* Returns no meaningfull value; declared as int to make compiler
* happy.
*
*
* PARAM1: void * pio - output stream
*
* RETURNS: 0
*/
/* (yaxon modify) */
/*extern int memtrapsize; in memman.c or user heap code */
extern unsigned memtrapsize; /* in memman.c or user heap code */
int
settrapsize(void * pio)
{
char * cp;
cp = nextarg(((GEN_IO)pio)->inbuf);
memtrapsize = atoi(cp);
ns_printf(pio,"malloc trap size set to %d\n", memtrapsize);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?