📄 wsrecv.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/winagent/wsrecv.c,v 1.2 2001/11/09 21:29:37 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: wsrecv.c,v $ * Revision 1.2 2001/11/09 21:29:37 josh * winagent path retooling * * Revision 1.1.1.1 2001/11/05 17:49:19 tneale * Tornado shuffle * * Revision 1.7 2001/01/19 22:25:13 paul * Update copyright. * * Revision 1.6 2000/03/17 00:15:56 meister * Update copyright message * * Revision 1.5 1998/02/25 04:58:37 sra * Update copyrights. * * Revision 1.4 1997/03/20 06:53:41 sra * DFARS-safe copyright text. Zap! * * Revision 1.3 1997/02/25 16:34:43 mrf * Added RCS log and copyright notice * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//*--------------------------------------------------------- WSRECV.C -- Receives packets and hands them on to Envoy's Process_Rcvd_SNMP_Packet_Async() routine for processing. Also includes definitions for I/O and Error completion routines and the SNMP_validate_community user exit routine (validate_SNMP_community()). ---------------------------------------------------------*/#include "wsagent.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>static unsigned char rcvbuff[SNMP_MAX_PACKET_SIZE];/*--------------------------------------------------------- agent_error_routine() and agent_io_routine() -- These are the completion routines. The I/O completion routine (agent_io_routine()) sends a response packet to the other side. The error competion routine does nothing, but could be modified to perform clean-up if needed. ---------------------------------------------------------*/void agent_error_routine(SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, int ecode, PTR_T cookie){#if DEBUG MsgBox (NULL, MB_OK, "Error processing packet, no response!");#endif /* DEBUG */ return;}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, rc;#if DEBUG SOCKERR serr;#endif /* DEBUG */#if (DEBUG > 1) SOCKADDR_IN *tmp;#endif /* DEBUG > 1 */ EBufferInitialize(&ebuff); szfrom = sizeof(struct sockaddr_in);#if DEBUG MsgBox (NULL, MB_OK, "Encoding and sending response packet!");#endif /* DEBUG */ if (rc = SNMP_Process_Finish((SNMP_PKT_T *)pktp, &ebuff, need) == 0) {#if (DEBUG > 1) tmp = (SOCKADDR_IN *)for_addr; MsgBox (NULL, MB_OK, "Sending packet to %s, Length = %d, Family = %d, Port = %d. ", inet_ntoa(tmp->sin_addr), need, tmp->sin_family, tmp->sin_port);#endif /* DEBUG > 1 */ rc = sendto(sSNMP, ebuff.start_bp, need, 0, (struct sockaddr *)for_addr, szfrom); EBufferClean(&ebuff);#if DEBUG if (rc != (int)need) { serr = WSAGetLastError(); MsgBox (NULL, MB_OK, "Error on sendto, %d: %s", serr, SockerrToString(serr)); }#endif /* DEBUG */ }#if DEBUG else { /* SNMP_Process_Finish() failed. Why? */ MsgBox (NULL, MB_OK, "SNMP_Process_Finish error, %d. No response sent.", rc); }#endif /* DEBUG */ return;}/*--------------------------------------------------------- WS_Receive() -- Receives an incoming packet and passes it to Envoy's Process_Rcvd_SNMP_Packet_Async() routine for processing. ---------------------------------------------------------*/void WS_Receive(SOCKET sock, SOCKERR serr, SOCKEVENT sevent){ SOCKADDR_IN addrLocal, addrRemote; int addrlen, rcvlen; if ((sock != sSNMP) || (sevent != FD_READ) || (serr != 0)) { /* unknown command/event or socket error, ignore. */#if DEBUG MsgBox (NULL, MB_OK, "Erroneous WS_Receive entry ???");#endif /* DEBUG */ return; }/* we've got something...so initialize everything */ (void)MEMSET(&addrLocal, 0, sizeof(addrLocal)); addrlen = sizeof(addrRemote); if ((rcvlen = recvfrom (sock, (char FAR *)rcvbuff, sizeof(rcvbuff), 0, (SOCKADDR FAR *)&addrRemote, &addrlen)) == -1) { /* recvfrom failed, return. */#if DEBUG serr = WSAGetLastError(); MsgBox (NULL, MB_OK, "Error on recvfrom, %d: %s", serr, SockerrToString(serr));#endif /* DEBUG */ return; }/* * recvfrom worked. we now have packet for processing. * hand the packet off to Process_Rcvd_SNMP_Packet_Async() * and we're done. response packet (if any) is sent from * agent_io_routine() above. */#if DEBUG MsgBox (NULL, MB_OK, "Received SNMP Packet! %d bytes.", rcvlen);#endif /* DEBUG */#if (DEBUG > 1) MsgBox (NULL, MB_OK, "Packet From: %s, Family = %d, Port = %d.", inet_ntoa(addrRemote.sin_addr), addrRemote.sin_family, addrRemote.sin_port);#endif /* DEBUG > 1 */ Process_Rcvd_SNMP_Packet_Async(rcvlen, rcvbuff, (SNMPADDR_T *)&addrRemote, (SNMPADDR_T *)&addrLocal, SNMP_MAX_PACKET_SIZE, agent_io_routine, agent_error_routine, 0); return;#if (DEBUG > 1) MsgBox (NULL, MB_OK, "Out of PRSNMPPA");#endif /* DEBUG > 1*/ return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -