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

📄 snmpd.c

📁 在freescale 的ne64上开发的源代码
💻 C
字号:
#include "datatypes.h"
#if 0
#include "snmptype.h"
#include "snmpdef.h"
#include "snmpfunc.h"
#include "debug.h"
#endif
#include "system.h"
#include "timers.h"
#include "tcp_ip.h"
#include "mBuf.h"

UINT8 snmp_app_init = 0; /**< Defines whether snmp_init has already been invoked or not */
extern MBUF *pCurrentMBuf;

/* SNMP states          */

#define SNMP_STATE_ENABLED		1
#define SNMP_STATE_CONNECTED	2
#define SNMP_TRAP_PORT	162	/**< Local SNMP client port that will	be used for sending requests */
#define SNMP_SERVERPORT	161	/**< SNMP server's port */

typedef struct{
	UINT8 state;
	INT8 sochandle;
	UINT32 remip;
	UINT16 remport;
}snmp_t;
static snmp_t snmp;
INT32 snmp_eventlistener(INT8 cbhandle, UINT8 event, UINT32 remip, UINT16 remport,
						UINT16 bufindex,UINT16 dlen)
{
	event++;
	if(snmp_app_init == 0)
		return (-1);
	if(cbhandle != snmp.sochandle)
		return (-1);
	/* If we are on other state than enabled, check that we are talking with the same gyu   */
	if(snmp.state != SNMP_STATE_ENABLED)
	{
		if(remip != snmp.remip)
			return (-1);
		if(remport != snmp.remport)
			return (-1);
	}
	if(dlen < 2)
		return (-1);
	/* Bind socket  */
	snmp.remip = remip;
	snmp.remport = remport;
	/* Get information  */
	NETWORK_RECEIVE_INITIALIZE(bufindex);
	Process_Rcvd_SNMP_Packet(pCurrentMBuf->working_ptr,dlen, 0, 0, 0);
}

/*  Initializes SNMP agent
 *  This function should be called before the SNMP Server application
 *  is used to set the operating parameters of it
 */
INT8 snmp_init(void)
{
	if(snmp_app_init)
		return (1);
	/* Get socket handle        */
	snmp.sochandle = udp_getsocket(0, snmp_eventlistener, UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
	if(snmp.sochandle < 0)
		return (-1);
	/* Put it to listening mode */
	if(udp_open(snmp.sochandle, SNMP_SERVERPORT) < 0)
		return (-1);
	snmp.remip = 0;
	snmp.remport = 0;
	snmp.state = SNMP_STATE_ENABLED;
	snmp_app_init = 1;
	return (1);
}
void snmpAgentOutput(void * rp, UINT16 bufsize)
{
	if(SNMP_Process_Finish(rp, net_buf,bufsize) == TRUE)
	{
		(void) udp_send(snmp.sochandle, snmp.remip, snmp.remport, net_buf, bufsize,bufsize);
	}
}

⌨️ 快捷键说明

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