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

📄 if.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/sun/if.c,v 1.2 2001/11/09 21:49:01 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1988-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: if.c,v $ * Revision 1.2  2001/11/09 21:49:01  josh * unxagent demo path adjustment, first pass * * Revision 1.1.1.1  2001/11/05 17:49:16  tneale * Tornado shuffle * * Revision 7.6  2001/01/19 22:25:01  paul * Update copyright. * * Revision 7.5  2000/03/17 00:15:20  meister * Update copyright message * * Revision 7.4  1998/02/25 04:58:19  sra * Update copyrights. * * Revision 7.3  1997/03/20 06:54:09  sra * DFARS-safe copyright text.  Zap! * * Revision 7.2  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 7.1  1997/01/08 23:01:49  sar * Updated copyright and modified include files to use envoy/h as * appropriate * * Revision 7.0  1996/03/15  22:07:57  sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.0  1995/05/31  21:49:44  sra * Release 6.0. * * Revision 5.3  1995/05/02  23:25:51  sar * Minor cleanup to make compilers happier. * * Revision 5.2  1995/04/28  22:24:48  sar * Dropped the static/dymanic flag from the nextproc_no_instance call * * Revision 5.1  1995/03/21  19:36:16  sar * Updated method routines to use new api & scheme * * Revision 5.0  1994/05/16  16:20:43  sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0  1993/06/24  17:34:02  sar * Updated rev to 4.0 copyright to 93 * * Revision 3.2  1993/06/13  02:53:35  sar * Removed sysent.h and libc.h and moved them into envoy.h * for mach386. * * Revision 3.1  1993/05/13  22:20:00  sar * Added defines, includes (<sysent.h>, <errno.h>, <libc.h>) and casts * (struct sockaddr *) as well as changed memfoo to MEMFOO and objidcmp * to llist_cmp to get rid of warnings. * * Revision 3.0  1992/04/03  19:53:44  dab * Release 3.0 * * Revision 2.101  92/02/04  10:46:46  dab * Updated for release 3.0 of SNMP. *  * Revision 2.100  92/02/03  16:46:09  dab * Generic unix SNMP agent. *  *  *    Rev 2.0   31 Mar 1990 15:34:22 * Initial revision. * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <stdio.h>#include <string.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include  <sys/param.h>#include  <sys/time.h>#include  <sys/types.h>#include  <sys/protosw.h>#include  <sys/socket.h>#include  <net/route.h>#include  <netinet/in.h>#include  <netinet/in_systm.h>#include  <netinet/ip.h>#include  <netinet/in_pcb.h>#include  <net/if.h>#include  <netinet/if_ether.h>#include  <sys/ioctl.h>#include "snmpvars.h"#include "general.h"#define LM_ifIndex		 1#define LM_ifDescr		 2#define LM_ifType		 3#define LM_ifMTU		 4#define LM_ifSpeed		 5#define LM_ifPhysAddress	 6#define LM_ifAdminStatus	 7#define LM_ifOperStatus		 8#define LM_ifLastChange		 9#define LM_ifInOctets		10#define LM_ifInUcastPkts	11#define LM_ifInNUcastPkts	12#define LM_ifInDiscards		13#define LM_ifInErrors		14#define LM_ifInUnknownProtos	15#define LM_ifOutOctets		16#define LM_ifOutUcastPkts	17#define LM_ifOutNUcastPkts	18#define LM_ifOutDiscards	19#define LM_ifOutErrors		20#define LM_ifOutQLen		21#define LM_ifSpecific		22#define CACHE_LIFETIME		8#define invalidate_ifcache_entry(L) ((struct lif *)(L)->time = (time_t)0)struct lif *lif;		/* Local interface list */int ifnumber;			/* Number of interfaces *//* Do the initial read of the interface table and makeup local table. */int  if_init(){static struct kernel_symbol ifnet = { "_ifnet", 0, 0 };struct ifnet *kifp;struct lif *lp;if (find_loc(&ifnet) == 0)    return -1;lif = 0;ifnumber = 0;read_bytes((off_t)ifnet.offset, (char *)&kifp, sizeof(kifp));while (kifp) {    char inum_buf[16];    if ((lp = (struct lif *)malloc(sizeof(struct lif))) == 0)	return -1;    MEMSET(lp, 0, sizeof(struct lif));    lp->next = lif;    lif = lp;    lp->koff = (off_t)kifp;    if ((lp->ifp = (struct ifnet *)malloc(sizeof(struct ifnet))) == 0)	return -1;    MEMSET(lp->ifp, 0, sizeof(struct ifnet));    read_bytes((off_t)lp->koff, (char *)(lp->ifp), sizeof(struct ifnet));    lp->ifp->if_addrlist = 0;    read_bytes((off_t)(lp->ifp->if_name), lp->name, IFNAMSIZ);    /* Not everybody has itoa(), oh well, gotta use sprintf() */    sprintf(inum_buf, "%u", lp->ifp->if_unit);    (void)strcat(lp->name, inum_buf);    read_if(lp);	/* Read the stuff that changes */    if ((lp->ifp->if_flags) & IFF_LOOPBACK) {	lp->type = 24;		/* software loopback */	lp->speed = 10000000;	}    else if ((strncmp(lp->name, "ie", 2) == 0) || /* Intel 82586 */	     (strncmp(lp->name, "le", 2) == 0) || /* AMD LANCE */	     (strncmp(lp->name, "ec", 2) == 0))   /* 3-COM */	{	struct arpcom arpcom;	lp->type = 6;		/* ethernet */	lp->speed = 10000000;	lp->flags |= LIF_HAS_PHYSADDR;	/* The following gets the Ethernet address.		*/	read_bytes((off_t)(lp->koff) +		   (off_t)((char *)&arpcom.ac_enaddr - (char *)&arpcom),		   (char *)&(lp->ac_enaddr),		   sizeof(struct ether_addr));	}    else {	lp->type = 1;		/* other */	lp->speed = 9600;	}    kifp = lp->ifp->if_next;    ifnumber++;    }return 0;}/* Update an interface's information if it's too old. */void  read_if(struct lif *lp){time_t now;struct ifaddr *ap;struct ifaddr *kap;struct ifaddr **aptr;struct ifreq  if_req;time(&now);if (now - lp->time <= CACHE_LIFETIME)    return;lp->time = now;/* Clean up any old list of addresses */for (ap = lp->ifp->if_addrlist; ap != 0; ) {    struct ifaddr *next_ap;    next_ap = ap->ifa_next;    (void) free((char *)ap);    ap = next_ap;    }read_bytes((off_t)lp->koff, (char *)(lp->ifp), sizeof(struct ifnet));lp->status = ((lp->ifp->if_flags) & IFF_UP) ? 1 : 2;/* Get the current subnet mask */(void)strncpy(if_req.ifr_name, lp->name, IFNAMSIZ);(void)ioctl(snmp_socket, SIOCGIFNETMASK, &if_req);lp->netmask.s_addr = ((struct sockaddr_in *)&if_req.ifr_addr)->sin_addr.s_addr;/* Build the address list */for (aptr = &(lp->ifp->if_addrlist), kap = lp->ifp->if_addrlist; kap != 0; ) {    off_t kernap;    ap = (struct ifaddr *)malloc(sizeof(struct ifaddr));    *aptr = ap;	/* Update the link in the previous entry */    aptr = &(ap->ifa_next);    kernap = (off_t)kap;    read_bytes((off_t)kernap, (char *)ap, sizeof(struct ifaddr));#ifdef DEBUG    printf("Address %s, dst addr %s, ifp=%8.8X nxt=%8.8X\n",	   (char *)inet_ntoa(((struct sockaddr_in *)&(ap->ifa_addr))->sin_addr.s_addr),	   (char *)inet_ntoa(((struct sockaddr_in *)&(ap->ifa_ifu.ifu_dstaddr))->sin_addr.s_addr),	   ap->ifa_ifp, ap->ifa_next);    fflush(stdout);#endif    kap = ap->ifa_next;    ap->ifa_next = 0;    }}int  get_interface_number(off_t kifp){struct lif *lifp;int i;for (lifp = lif, i = 1; lifp; i++, lifp = lifp->next) {    if (lifp->koff == kifp)	return i;    }#define IFDEBUG#if defined(IFDEBUG)    {    struct lif *dlifp;    printf("Can not find interface number: looking for %8.8X\n", kifp);    printf("Known values are:\n");    for (dlifp = lif; dlifp; dlifp = dlifp->next)	printf("     %8.8X\n", dlifp->koff);    fflush(stdout);    }#endif /* IFDEBUG */return 2; /* If we can't find it, then say it's the 1st LAN */}    /****************************************************************************NAME:  get_ifNumberPURPOSE:  Find the appropriate entry in the if table and attach information	  from it to the vbp using the getproc_got_* functions.	  If we can't find an entry indicate that by calling getproc_nosuchins.PARAMETERS:	OIDC_T		Last component of the object id leading to			the leaf node in the MIB.  This is usually			the identifier for the particular attribute			in the table.	int		Number of components in the unused part of the			object identifier	OIDC_T *	Unused part of the object identifier	SNMP_PKT_T *	SNMP packet currently being processed.	VB_T *		Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void

⌨️ 快捷键说明

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