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

📄 iprte.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/iprte.c,v 1.2 2001/11/09 21:49:02 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: iprte.c,v $ * Revision 1.2  2001/11/09 21:49:02  josh * unxagent demo path adjustment, first pass * * Revision 1.1.1.1  2001/11/05 17:49:17  tneale * Tornado shuffle * * Revision 7.6  2001/01/19 22:25:02  paul * Update copyright. * * Revision 7.5  2000/03/17 00:15:24  meister * Update copyright message * * Revision 7.4  1998/02/25 04:58:20  sra * Update copyrights. * * Revision 7.3  1997/03/20 06:54:11  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.1  1995/11/01  01:03:00  sar * removed no_pp stuff * commented out define of debug * * Revision 6.0  1995/05/31  21:49:45  sra * Release 6.0. * * Revision 5.5  1995/05/09  17:47:51  sar * Modified the next routine to use OIDC_T's internally and to get rid of * the use of -1 as a tag value allowing us to use the entire 4g range. * * Revision 5.4  1995/05/02  23:25:51  sar * Minor cleanup to make compilers happier. * * Revision 5.3  1995/04/28  22:24:48  sar * Dropped the static/dymanic flag from the nextproc_no_instance call * * Revision 5.2  1995/03/21  21:29:14  sar * Set up an ifdef so that RENTRY may be modified by defining it elsewhere. * * Revision 5.1  1995/03/21  19:40:54  sar * Updated method routines to use new api & scheme * Created RTENTRY macro to deal with rtentry (on mach386) vs ortentry * (on netbsd). * * 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.3  1993/06/13  02:53:35  sar * Removed sysent.h and libc.h and moved them into envoy.h * for mach386. * * Revision 3.2  1993/05/13  22:22:28  sar * Added some defines, includes (<sysent.h> <errno.h> <libc.h>), casts * (struct sockaddr *) and changed memfoo to MEMFOO and objidcmp to * llist_cmp to get rid of warnings from the compiler. * * Revision 3.1  1992/09/01  11:37:55  dab * Fixed up for Mach386 * * Revision 3.0  92/04/03  19:53:44  dab * Release 3.0 *  * Revision 2.101  92/02/04  10:46:49  dab * Updated for release 3.0 of SNMP. *  * Revision 2.100  92/02/03  16:46:11  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*//*#define DEBUG*/#include <stdio.h>#include <time.h>#include <memory.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/types.h>#include  <sys/socket.h>#include  <net/if.h>#define KERNEL#include  <net/route.h>#undef KERNEL#include  <netinet/in_systm.h>#include  <netinet/in.h>#include  <netinet/ip.h>#include  <netinet/in_pcb.h>#include  <netinet/if_ether.h>#include  <sys/ioctl.h>#include  <sys/mbuf.h>#include  <netdb.h>#include  <ctype.h>#include  <errno.h>#include "snmpvars.h"#include "general.h"#define LM_ipRouteDest		 1#define LM_ipRouteIfIndex	 2#define LM_ipRouteMetric1	 3#define LM_ipRouteMetric2	 4#define LM_ipRouteMetric3	 5#define LM_ipRouteMetric4	 6#define LM_ipRouteNextHop	 7#define LM_ipRouteType		 8#define LM_ipRouteProto		 9#define LM_ipRouteAge		10#define LM_ipRouteMask		11#define LM_ipRouteMetric5	12#define LM_ipRouteInfo		13#define CACHE_LIFETIME 4#define INSTANCE_LEN 4static OIDC_T iprte_route_info_compl[] = { 0, 0 };OBJ_ID_T iprte_route_info = { sizeof(iprte_route_info_compl)/sizeof(OIDC_T),				iprte_route_info_compl };static struct kernel_symbol rthost_sym = { "_rthost", 0, 0};static struct kernel_symbol rtnet_sym = { "_rtnet", 0, 0 };static struct kernel_symbol rthash_sym = { "_rthashsize", 0, 0 };static int rthashsize = 8;	/* We'll get the real value from the kernel */static int mbuflistsize = 16;	/* We'll get the real value from the kernel */#ifndef RENTRY#define RENTRY rtentry#endifstruct	rte	{	struct rte	*rte_next;	struct RENTRY	 rt_ent;	};struct	rte *rt_list = 0;int	rt_count = 0;	/* Number of entries in rt_list */struct	mbuf **rt_mbuf_list;int	rth_half_bytes;static time_t route_cache_time = 0;#define invalidate_iprte() route_cache_time = 0static void read_routing();extern int	errno;#if defined(DEBUG)static void  pr_iprte(){  struct rte *rtep;    printf("%15s  %15s  %8s  %8s\n",	 "Destination", "Gateway", "Flags", "Interface");  for (rtep = rt_list; rtep != 0; rtep = rtep->rte_next) {    printf("%15s  ",(char *)inet_ntoa(((struct sockaddr_in *)&(rtep->rt_ent.rt_dst))->sin_addr));    printf("%15s  %8X  %8.8X\n",(char *)inet_ntoa(((struct sockaddr_in *)&(rtep->rt_ent.rt_gateway))->sin_addr),	   rtep->rt_ent.rt_flags, rtep->rt_ent.rt_ifp);  }  fflush(stdout);}#endif /* DEBUG */int  iprte_init(){  if (find_loc(&rthost_sym) == 0)    return -1;  if (find_loc(&rtnet_sym) == 0)    return -1;  if (find_loc(&rthash_sym) == 0)    return -1;  rthashsize = read_int((off_t)rthash_sym.offset);#ifdef DEBUG  printf("Kernel rthashsize = %d\n", rthashsize);#endif  mbuflistsize = rthashsize << 1;    rth_half_bytes = rthashsize * sizeof(struct mbuf *);    if ((rt_mbuf_list = (struct mbuf **)malloc(rth_half_bytes * 2)) == 0)    return -1;    read_routing();#if defined(DEBUG)  pr_iprte();#endif    return 0;}static void  read_routing(){  time_t now;  struct rte	*rtep;  struct rte	*next_rtep;  struct mbuf	mbuf;  int i;    time(&now);    if ((time(&now) - route_cache_time) <= CACHE_LIFETIME)    return;    route_cache_time = now;    /* Free old routes */  for (rtep = rt_list; rtep != 0; ) {    next_rtep = rtep->rte_next;    free(rtep);    rtep = next_rtep;  }  rt_list = 0;    /* Read new routes  -- merge the host and gateway lists */  read_bytes((off_t)rthost_sym.offset, (char *)rt_mbuf_list,	     rth_half_bytes);  read_bytes((off_t)rtnet_sym.offset, (char *)&rt_mbuf_list[rthashsize],	     rth_half_bytes);    for (rtep = 0, rt_count = 0, i = 0; i < mbuflistsize; i++) {    struct RENTRY * rtp;    int cnt;        if (rt_mbuf_list[i] == 0)      continue;    read_bytes((off_t)(rt_mbuf_list[i]), (char *)&mbuf, sizeof(struct mbuf));    rtp = (struct RENTRY *)mbuf.m_dat;    cnt = mbuf.m_len / sizeof(struct RENTRY);        for (; cnt; --cnt) {      if (rtep == 0) { /* need to create new list */	if ((rt_list = (struct rte *)malloc(sizeof(struct rte))) == 0)	  break;	rtep = rt_list;      }      else { /* Can append to existing list */	if ((next_rtep = (struct rte *)malloc(sizeof(struct rte)))  == 0) 	  break;	rtep->rte_next = next_rtep;	rtep = next_rtep;      }      rtep->rte_next = 0;      read_bytes((off_t)rtp, (char *)&(rtep->rt_ent), sizeof(struct RENTRY));      if (rtep->rt_ent.rt_flags == 0)	continue;      rt_count++;      rtp++;    }  }}/*ARGSUSED*/static int  zap_route(struct in_addr  ipaddr,	    struct rte     *rtep){  struct RENTRY drte;  (void)MEMSET(&drte, 0, sizeof(struct RENTRY));  (void)MEMCPY(&drte.rt_dst, &(rtep->rt_ent.rt_dst),	       sizeof(struct sockaddr_in));  (void)MEMCPY(&drte.rt_gateway, &(rtep->rt_ent.rt_gateway),	       sizeof(struct sockaddr_in));  drte.rt_flags = (rtep->rt_ent.rt_flags) & (RTF_UP | RTF_GATEWAY | RTF_HOST);  invalidate_iprte();  (void)ioctl(snmp_socket, SIOCDELRT, &drte);  return(0);}static unsigned long  ip_net_mask(struct in_addr ia){  union {    unsigned long long_addr;    unsigned char byte_addr[4];  } address_bytes;  static unsigned long masks[] = {#if 0 /* defined(BIG_ENDIAN) */    0xff000000L,		/* Class A */    0xff000000L,		/* Class A */    0xff000000L,		/* Class A */    0xff000000L,		/* Class A */    0xffff0000L,		/* Class B */    0xffff0000L,		/* Class B */    0xffffff00L,		/* Class C */    0xffffffffL,		/* Class D */#else    0x000000ffL,		/* Class A */    0x000000ffL,		/* Class A */    0x000000ffL,		/* Class A */    0x000000ffL,		/* Class A */    0x0000ffffL,		/* Class B */    0x0000ffffL,		/* Class B */    0x00ffffffL,		/* Class C */

⌨️ 快捷键说明

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