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

📄 udp.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/sun/udp.c,v 1.2 2001/11/09 21:49:04 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: udp.c,v $ * Revision 1.2  2001/11/09 21:49:04  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:04  paul * Update copyright. * * Revision 7.5  2000/03/17 00:15:36  meister * Update copyright message * * Revision 7.4  1998/02/25 04:58:27  sra * Update copyrights. * * Revision 7.3  1997/03/20 06:54:17  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:53  sra * Release 6.0. * * Revision 5.3  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.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/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:38:37  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:47:33  dab * Updated for release 3.0 of SNMP. *  * Revision 2.100  92/02/03  16:46:19  dab * Generic unix SNMP agent. *  *  *    Rev 2.0   31 Mar 1990 15:34:26 * Initial revision. * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <stdio.h>#include <time.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/route.h>#include  <netinet/in.h>#include  <net/if.h>#include  <netinet/if_ether.h>#include  <netinet/in_systm.h>#include  <netinet/ip.h>#include  <netinet/ip_var.h>#include  <netinet/in_pcb.h>#include  <netinet/udp.h>#include  <netinet/udp_var.h>#include "snmpvars.h"#include "general.h"#define LM_udpInDatagrams	1#define LM_udpNoPorts		2#define LM_udpInErrors		3#define LM_udpOutDatagrams	4#define LM_udpLocalAddress	1#define LM_udpLocalPort		2#define CACHE_LIFETIME 4#define INSTANCE_LEN 5#define LOCAL_ADDR 0#define LOCAL_PORT 4static struct kernel_symbol udpstat = { "_udpstat", 0, 0};static struct udpstat udps;static struct kernel_symbol udp_cons = { "_udb", 0, 0 };static struct inpcb *udb = 0;static time_t udp_cache_time = 0;/****************************************************************************NAME:  udpinfo_getPURPOSE:  Find the appropriate entry in the udp struct 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  udpinfo_get(OIDC_T		 last_match,	      int		 tcount,	      OIDC_T		*tlist,	      SNMP_PKT_T	*pktp,	      VB_T		*vbp){/* Test the instance information to see if it is well formed,   there must be exactly 1 unused component and its value must be 0 */if ((tcount != 1) || (tlist[0] != 0)) {    getproc_nosuchins(pktp, vbp);    return;    }switch (last_match) {    case LM_udpInDatagrams:    case LM_udpNoPorts:    case LM_udpOutDatagrams:	getproc_got_uint32(pktp, vbp, 0, VT_COUNTER);	break;    case LM_udpInErrors:	/* see if we can find the udpstat structure */	if (find_loc(&udpstat) != 0) {	    read_bytes((off_t)udpstat.offset, (char *)&udps,		       sizeof(struct udpstat));	    getproc_got_uint32(pktp, vbp, (UINT_32_T)(udps.udps_hdrops +						      udps.udps_badsum +						      udps.udps_badlen),			       VT_COUNTER);	    }	else {	    getproc_error(pktp, vbp, GEN_ERR);	    break;	    }	break;    }return;}/****************************************************************************NAME:  udptable_getPURPOSE:  Find the appropriate entry in the udp 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  udptable_get(OIDC_T		 last_match,	       int		 tcount,	       OIDC_T		*tlist,	       SNMP_PKT_T	*pktp,	       VB_T		*vbp){struct in_addr	localip;unsigned int	localport;time_t		now;struct inpcb *	pcb;/* Test the instance information to see if it is well formed,   there must be exactly 5 unused components    which should be a valid IP address and UDP port # */if ((tcount != 5) || oid_to_ip(4, tlist + LOCAL_ADDR, &localip.s_addr)) {    getproc_nosuchins(pktp, vbp);    return;    }localport = (unsigned int)tlist[LOCAL_PORT];if ((udb == 0) || ((time(&now) - udp_cache_time) > CACHE_LIFETIME)) {    udp_cache_time = now;    if (find_loc(&udp_cons) == 0) {	getproc_error(pktp, vbp, GEN_ERR);	return;        }    (void) read_ct(&udb, udp_cons.offset);    }for (pcb = udb; pcb; pcb = pcb->inp_next)    if ((localport == pcb->inp_lport) &&	(localip.s_addr == pcb->inp_laddr.s_addr)) {	switch(last_match) {	    case LM_udpLocalAddress:		getproc_got_ip_address(pktp, vbp, localip.s_addr);		break;	    case LM_udpLocalPort:		getproc_got_int32(pktp, vbp, (INT_32_T)localport);		break;	    }	return;	}getproc_nosuchins(pktp, vbp);return;}/****************************************************************************NAME:  udptable_nextPURPOSE:  Locate the "next" object in the UDP tablePARAMETERS:	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  udptable_next(OIDC_T		 last_match,		int		 tcount,		OIDC_T		*tlist,		SNMP_PKT_T	*pktp,		VB_T		*vbp){time_t		now;struct inpcb	*pcb, *best = 0;OIDC_T		bra[INSTANCE_LEN], pra[INSTANCE_LEN];int		i;if ((udb == 0) || ((time(&now) - udp_cache_time) > CACHE_LIFETIME)) {    udp_cache_time = now;    if (find_loc(&udp_cons) == 0) {	nextproc_error(pktp, vbp, GEN_ERR);	return;	}    (void) read_ct(&udb, udp_cons.offset);    }/* Now find the lowest value larger than localip and localport. */for (pcb = udb; pcb; pcb = pcb->inp_next) {    ip_to_rlist(pcb->inp_laddr.s_addr, pra+LOCAL_ADDR);    pra[LOCAL_PORT] = pcb->inp_lport;    if (oidcmp2(INSTANCE_LEN, pra, tcount, tlist) <= 0)	continue;    if (!best || (oidorder(pra, bra, INSTANCE_LEN) < 0)) {	best = pcb;	for (i = 0; i < INSTANCE_LEN; i++)	    bra[i] = pra[i];	}    }if (best) {    switch(last_match) {	case LM_udpLocalAddress:	    getproc_got_ip_address(pktp, vbp, best->inp_laddr.s_addr);	    break;	case LM_udpLocalPort:	    getproc_got_int32(pktp, vbp, (INT_32_T)best->inp_lport);	    break;	}    nextproc_next_instance(pktp, vbp, INSTANCE_LEN, bra);    }else    nextproc_no_next(pktp, vbp);return;}intudp_init(){if (find_loc(&udpstat) == 0) return -1;if (find_loc(&udp_cons) == 0) return -1;return 0;}

⌨️ 快捷键说明

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