📄 snmpv3io.c
字号:
/* * Copyright 1984-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. */#include <copyright_wrs.h>/* * $Log: snmpv3io.c,v $ * Revision 1.5 2002/05/31 20:58:41 josh * some preliminary changes to allow the vxWorks SNMP agent to run * over a standard IPv6 sockets layer * * Revision 1.4 2001/11/08 22:18:37 meister * rework pathnames * * Revision 1.3 2001/11/07 22:15:40 meister * rework pathnames again * * Revision 1.2 2001/11/06 21:20:41 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:50 tneale * Tornado shuffle * * Revision 1.1.2.2 2001/10/16 20:48:06 meister * removed some unnecessary include files * * Revision 1.1.2.1 2001/09/27 01:05:23 meister * Split out coexistence support into v3 component files * *//* [clearcase]modification history-------------------01b,19apr05,job update copyright notices01a,24nov03,job update copyright information*//*DESCRIPTIONThis module implements the SNMP v3 transport-dependent routines.*/#include <vxWorks.h>#include <sys/socket.h>#include <sockLib.h>#include <sys/types.h>#include <netinet/in.h>#include <wrn/wm/snmp/engine/view.h>#include <wrn/wm/snmp/engine/snmpstat.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/buildpkt.h>#include <wrn/wm/snmp/engine/objectid.h>#if (INSTALL_ENVOY_SNMP_VERSION_3 || INSTALL_ENVOY_SNMP_RFC2275_VIEWS)#include <wrn/wm/demo/nvutils.h>#endif#if (INSTALL_ENVOY_SNMP_VERSION_3 && INSTALL_ENVOY_SNMP_V3_NOTIFY)#include <wrn/wm/snmp/engine/v3_ntfy.h>#include <wrn/wm/snmp/engine/sendntfy.h>#include <wrn/wm/snmp/engine/wkobj.h>#endifvoid send_v3_notify (void);IMPORT void snmpIoWrite(void *, char *, int, void *, void *);IMPORT int snmpSocket;#if INSTALL_SNMP_VXWORKS_IPV6IMPORT int snmpSocketV6;#endif /* #if INSTALL_SNMP_VXWORKS_IPV6 */#if (INSTALL_ENVOY_SNMP_V3_NOTIFY)/******************************************************************************** This section is primarily a demonstration of the new API for sending* SNMPv3 Traps. It's not intended to ever be used as production code, * and as such it composes traps of surpassing bogosity. Be warned.** NOMANUAL*//* envoy completion routine. send the response back where the request * came from */static void notify_complete(SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, PTR_T pktp, ALENGTH_T need, PTR_T cookie){EBUFFER_T ebuff;void *pSocket = 0;EBufferInitialize(&ebuff);if (SNMP_Encode_Packet(pktp, &ebuff) == -1) return;#if INSTALL_SNMP_VXWORKS_IPV6if (((struct sockaddr *)for_addr)->sa_family == AF_INET6) pSocket = (void *)snmpSocketV6;else#endif pSocket = (void *)snmpSocket;snmpIoWrite(pSocket, (char*) ebuff.start_bp, need, for_addr, loc_addr);EBufferClean(&ebuff);}static void notify_err_complete(SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, int error_code, PTR_T cookie){ return;}/* routine to handle notifies for v3 */voidsend_v3_notify(void){OIDC_T csoidc[] = {SNMP_COLDSTART};OIDC_T sysupoidc[] = {1, 3, 6, 1, 2, 1, 1, 3, 0};OIDC_T stoidc[] = {SNMP_SNMPTRAPOID, 0};OBJ_ID_T trapoid;VBL_T *vblp;SNMP_NOTIFY_T *notify = 0;bits8_t context[] = "";unsigned long cur_secs;struct sockaddr_in send_from;int socklen = sizeof(struct sockaddr_in);cur_secs = ENVOY_NOW();if (getsockname(snmpSocket, (struct sockaddr *)&send_from, &socklen)) return;trapoid.component_list = csoidc;trapoid.num_components = sizeof(csoidc)/sizeof(OIDC_T);if ((vblp = VBList_Allocate(2)) == 0) return;VBL_Bind_Timeticks(vblp, 0, sizeof(sysupoidc)/sizeof(OIDC_T), sysupoidc, (cur_secs * 100));VBL_Bind_Object_ID(vblp, 1, sizeof(stoidc)/sizeof(OIDC_T), stoidc, trapoid.num_components, trapoid.component_list);/* This function scrolls through the list of Notifies and sends using * each Notify. A real trap-sending program probably won't do * this. */for (notify = SNMP_Notify_Next_Notify(0); notify; notify = SNMP_Notify_Next_Notify(notify)) { SNMP_Send_Notify(notify, vblp, (SNMPADDR_T *)&send_from, context, 0, notify_complete, notify_err_complete, 0, 0); }VBList_Free(vblp);return;}#endif /* INSTALL_ENVOY_SNMP_V3_NOTIFY */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -