📄 agent.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/sun/agent.c,v 1.5 2003/01/15 14:04:59 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: agent.c,v $ * Revision 1.5 2003/01/15 14:04:59 josh * directory structure shifting * * Revision 1.4 2002/05/31 20:57:46 josh * fix a small typo in select loop * * Revision 1.3 2002/03/06 20:02:38 josh * the unxagent will now listen on an IPv6 socket, if IPv6 is * available * * Revision 1.2 2001/11/09 21:49:00 josh * unxagent demo path adjustment, first pass * * Revision 1.1.1.1 2001/11/05 17:49:16 tneale * Tornado shuffle * * Revision 7.15 2001/06/25 17:06:45 josh * Let's make snark/unxagent build on Solaris * * Revision 7.14 2001/01/19 22:24:59 paul * Update copyright. * * Revision 7.13 2000/07/10 15:55:16 mrf * Add configuration for Cygnus NT environment with associated changes. * * Revision 7.12 2000/03/17 00:15:11 meister * Update copyright message * * Revision 7.11 1998/06/28 21:56:46 sar * Use ENVOY_TIMER_32_T * * Revision 7.10 1998/06/23 22:07:30 sar * Add some include files to keep compilers happy * * Revision 7.9 1998/06/23 21:05:12 sar * Update call to SNMP_NV_Config * * Revision 7.8 1998/06/07 03:04:43 sar * Moved the global variables for the non-volatile configuration stuff * and the community strings to the snark library. * Also changed the names of the configuration variables * * Revision 7.7 1998/06/03 22:06:09 sar * Updated code to use common string macros * In agent.c only init the ip stack methods if we are on sunos * * Revision 7.6 1998/02/25 04:58:15 sra * Update copyrights. * * Revision 7.5 1997/10/22 02:57:15 sar * Renamed ENVOY_MASTER_AGENT to ENVOY_EPI_MASTER to make things clearer, * also added envoy_init * * Revision 7.4 1997/03/20 06:54:02 sra * DFARS-safe copyright text. Zap! * * Revision 7.3 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 7.2 1997/01/08 23:01:49 sar * Updated copyright and modified include files to use envoy/h as * appropriate * * Revision 7.1 1997/01/06 22:42:23 sar * Removed BSD_RELEASE definition and use * * Revision 7.0 1996/03/15 22:07:57 sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.4 1996/03/12 16:01:19 sar * Fixed up type mismatch with master_cleanup * * Revision 6.3 1995/11/14 22:46:31 sar * Removed the proxy and object resources code, some * of the proxy stuff went to libfuncs.c. * * Revision 6.2 1995/11/11 00:12:33 sar * made rfc1445_view_routines be rfc1445_views * * Revision 6.1 1995/11/01 01:03:00 sar * added pp style argument list * ifdefed out some proxy & or stuff that may need to be redone * * Revision 6.0 1995/05/31 21:49:38 sra * Release 6.0. * * Revision 5.9 1995/05/27 01:18:57 sar * removed reqid from master_query_reply handler's args * * Revision 5.8 1995/05/02 23:25:51 sar * Check the async switch to decide which routine to use to call the * master handler. * * Revision 5.7 1995/04/28 22:32:22 sar * Updated the agent code to use the newer Masater_Handler_Async * calling sequence, this includes building the completion routine. * * Revision 5.6 1995/04/18 21:25:06 sar * Added a new ipc send routine for use with async sub agents, remvoed * the sub agent is async ifdefs - if the master agent is installed * we included the async options. * * Revision 5.5 1995/03/22 18:44:37 sar * Fixed up the use of timvals, we were treating the micro second field * as a millisecond field. Added a test during the select call to * determine if the timer is already overdue and therefore should be run * before doing the select. * * Revision 5.4 1995/03/21 19:34:36 sar * Added timer code, call to set up proxy for udp domain, async * completion routines, idfef to allow for async sub agents and switch * to call either the sync or async packet processing routines. * * Revision 5.3 1994/10/25 20:12:01 sar * #ifdef the master and master_query defs and change a %u to %lu. * * Revision 5.2 1994/10/14 19:35:06 sar * tided up some size options * * Revision 5.1 1994/09/23 19:32:44 sar * Changed the non volatile scheme, and added some new options to the * config file. * * Revision 5.0 1994/05/16 16:20:43 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.6 1994/05/13 22:03:45 sar * added a type cast to keep the compiler happy * * Revision 4.5 1994/05/10 20:20:17 sar * Added #if to allow string2oid and oid2string to be compiled for use * with nvutils in all cases. * * Revision 4.4 1994/05/09 20:58:21 sar * Added SNMPTalk_snmp_version variable to keep nvutils happy, if nvutils * is modifed to eliminate the need for this variable it should be removed. * * Revision 4.3 1994/05/06 20:28:32 sar * Fixed up some memory leaks. * * Revision 4.2 1994/05/04 22:32:03 sar * added netinet/in_systm.h for use on netbsd systems. * * Revision 4.1 1994/05/02 21:11:02 sar * Added sub agent code, ipc routines and waiting on master agent socket * to pass messages to master_handler. * * Revision 4.0 1993/06/24 17:31:48 sar * Updated rev to 4.0 copyright to 93 * and made the if defined(install..) checks be if install * * Revision 3.19 1993/06/13 02:55:00 sar * added a cast in the SNMP_OR_Create call to keep compilers happy * * Revision 3.18 1993/05/31 19:10:34 sar * added oid2string and string2oid routines for use with nvutils.c * (they are simple versions of the ones in mibutils.c * * Revision 3.17 1993/05/28 17:58:16 sar * added a object resource entry for test purposes. * * Revision 3.16 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.15 1993/04/26 20:20:12 sar * Added ifdefs to allow clean version 1 and version 2 makes. * * Revision 3.14 1993/04/23 23:39:32 sar * Collected objectid defines into wkobj.h to make life easier. * * Revision 3.13 1993/04/22 20:23:42 sar * Updated macros and defines to use the naming scheme. * For example we now use INSTALL_ENVOY_SNMP_VERSION_1 or _2. * * Revision 3.12 1993/04/19 18:30:24 sar * made some defs static * * Revision 3.11 1993/04/17 01:11:22 sar * made the oidc we were giving to the transport build routine static as * required. * * Revision 3.10 1993/04/07 21:49:06 sar * added transport domain. * * Revision 3.9 1993/03/24 20:03:29 sar * created some entries in the object resource table. * * Revision 3.8 1993/03/24 01:00:29 sar * changed a view. * * Revision 3.7 1993/03/17 22:59:46 sar * Added use of views, creation, and integration with other init stuff. * * Revision 3.6 1993/03/04 18:24:43 sar * added new contexts and acls to use the view stuff. * * Revision 3.5 1993/02/24 23:37:45 sar * Updated use of (party, context, create)_calls and setting of the appropriate * fields to have the creates gnereate basically the defval information. * * Revision 3.4 1993/02/24 00:57:19 sar * Updates to reflects changes to SNMP_(Party, Context, ACL)_* operations * mostly this is changing from an OBJ_ID_T to a OIDC_T/length in the call. * * Revision 3.3 1993/02/22 18:56:48 sar * Added new method routines for acl and contexts, modified agent.c to * use the new access routines. * * Revision 3.2 1993/02/17 20:40:51 sar * Hardwire the initialization of some parties for test purposes. * Eventually we should use the standard initial parties and should use * configuration files for some information and for other parties. * * Revision 3.1 92/09/01 11:33:57 dab * Fixed up header files for Mach386. * * Revision 3.0 92/04/03 19:53:44 dab * Release 3.0 * * Revision 2.101 92/02/04 10:46:19 dab * Updated for release 3.0 of SNMP. * * Revision 2.100 92/02/03 16:45:36 dab * Generic unix SNMP agent. * * * Rev 2.1 09 Apr 1990 14:23:08 * Cast the address of inet_ntoa() so that it works on a Sun 4. * * Rev 2.0 31 Mar 1990 15:34:16 * Initial revision. * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*/#include <wrn/wm/common/config.h>#include <stdio.h>#include <string.h>#include <sys/param.h>#include <sys/types.h>#include <sys/time.h>#include <sys/socket.h>#include <sys/un.h>#include <ctype.h>#include <net/if.h>#if !INSTALL_on_ntgcc#include <net/route.h>#endif#include <netinet/in_systm.h>#include <netinet/in.h>#include <netinet/ip.h>/*#include <netinet/in_pcb.h>*/#include <netdb.h>#if !INSTALL_on_solaris#include <a.out.h>#endif#include <fcntl.h>#include <sys/time.h>#if !INSTALL_on_ntgcc#include <netinet/if_ether.h>#endif#include <errno.h>#include <unistd.h>#include <arpa/inet.h>#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/buildpkt.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/wkobj.h>#include "snmpvars.h"#include "general.h"#include "../agent.h"#include <wrn/wm/demo/snmpfunc.h>#include <wrn/wm/common/glue.h>#if INSTALL_ENVOY_EPI_MASTER#include <wrn/wm/snmp/engine/subagent.h>#include <wrn/wm/snmp/engine/etimer.h>#define MASTER_AGENT "/tmp/M_AGENT"#define MASTER_QUERY "/tmp/M_QUERY"static int master_socket;static int query_socket;#endifextern int errno;static bits32_t calltime;static void (*callee)(void);#define TBSIZE 2048unsigned char rcvbuff[TBSIZE];OIDC_T mysnmpUDPDomainoidc[] = {SNMP_UDPDOMAIN};int mysnmpUDPDomainlen = sizeof(mysnmpUDPDomainoidc)/sizeof(OIDC_T);/* version number for use in nvutils */#if INSTALL_ENVOY_SNMP_VERSION_2int SNMPTalk_SNMP_Version = 2;#elseint SNMPTalk_SNMP_Version = 1;#endifbits32_t envoy_now(void){struct timeval tp;gettimeofday(&tp, 0);return((tp.tv_sec * 1000) + ((tp.tv_usec/1000) % 1000));}void envoy_call_timer (bits32_t when, void (*what)(void)){calltime = when + envoy_now();callee = what;}/* async completion routines *//****************************************************************************NAME: agent_error_routinePURPOSE: An error completion routine for use with the aysnc version of envoy.PARAMETERS: SNMPADDR_T * Foreign address of packet SNMPADDR_T * Local address of packet int ignored PTR_T ignoredRETURNS: void****************************************************************************/void agent_error_routine(SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, int ecode, PTR_T cookie){return;}/****************************************************************************NAME: agent_io_routinePURPOSE: An io completion routine for use with the the async version of envoyPARAMETERS: SNMPADDR_T * Foreign address of packet SNMPADDR_T * Local address of packet PTR_T Pointer to the packet structure ALENGTH_T Max space the packet will require PTR_T ignoredRETURNS: void****************************************************************************/void agent_io_routine(SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, PTR_T pktp, ALENGTH_T need, PTR_T cookie){EBUFFER_T ebuff;int szfrom;#if INSTALL_SNMP_DEMO_AGENT_IPV6struct sockaddr *for_sock = (struct sockaddr *)for_addr;#endifint send_sock; EBufferInitialize(&ebuff);#if INSTALL_SNMP_DEMO_AGENT_IPV6if (for_sock->sa_family == AF_INET6) { szfrom = sizeof(struct sockaddr_in6); send_sock = snmp_ipv6_socket; }else { szfrom = sizeof(struct sockaddr_in); send_sock = snmp_socket; }#elseszfrom = sizeof(struct sockaddr_in);send_sock = snmp_socket;#endif if (SNMP_Process_Finish((SNMP_PKT_T *)pktp, &ebuff, need) == 0) { (void) sendto(send_sock, ebuff.start_bp, need, 0, (struct sockaddr *)for_addr, szfrom); EBufferClean(&ebuff); }}/* ipc routines for use with the master agent */#if INSTALL_ENVOY_EPI_MASTERtypedef struct IPCADDR_S { int size; struct sockaddr_un from; } IPCADDR_T;void ipccomp(OCTET_T opcode, EBUFFER_T *ebuf, VBL_T *vblist, PTR_T addr){IPCADDR_T *iaddr = (IPCADDR_T *)addr;if (opcode != 0) { if (trace_level > 2) printf("Subagent sending reply...\n"); sendto(master_socket, EBufferStart(ebuf), EBufferUsed(ebuf), 0, (struct sockaddr *)(&iaddr->from), iaddr->size); }if (opcode <= 0) { if (trace_level > 0) printf("Subagent Decode failure\n"); SNMP_memory_free(iaddr); }fflush(stdout);return;}INT_32_T ipcsend(EBUFFER_T *ebuf, PTR_T addr){IPCADDR_T *iaddr;iaddr = (IPCADDR_T *)addr;sendto(query_socket, EBufferStart(ebuf), EBufferUsed(ebuf), 0, (struct sockaddr *)(&iaddr->from), iaddr->size);EBufferClean(ebuf);return(0);}INT_32_T ipcrcv(EBUFFER_T *rbuf, PTR_T addr)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -