资源简介
用net-snmp的c apis实现trap的接收,类似于snmptrapd工具的实现,但是更为简单。
代码片段和文件信息
#include
#include
#include
#include
int netsnmp_running = 1;
/************************************************************************
**
**
************************************************************************/
int snmp_input(int op netsnmp_session *session int reqid netsnmp_pdu *pdu void *magic)
{
printf(“We got a trap:\n“);
struct variable_list *vars;
for(vars = pdu->variables; vars; vars = vars->next_variable)
{
print_variable(vars->name vars->name_length vars);
}
return 1;
}
static int pre_parse(netsnmp_session * session netsnmp_transport *transport
void *transport_data int transport_data_length)
{
return 1;
}
static netsnmp_session *snmptrapd_add_session(netsnmp_transport *t)
{
netsnmp_session sess *session = &sess *rc = NULL;
snmp_sess_init(session);
session->peername = SNMP_DEFAULT_PEERNAME; /* Original code had NULL here */
session->version = SNMP_DEFAULT_VERSION;
session->community_len = SNMP_DEFAULT_COMMUNITY_LEN;
session->retries = SNMP_DEFAULT_RETRIES;
session->timeout = SNMP_DEFAULT_TIMEOUT;
session->callback = snmp_input;
session->callback_magic = (void *) t;
session->authenticator = NULL;
sess.isAuthoritative = SNMP_SESS_UNKNOWNAUTH;
rc = snmp_add(session t pre_parse NULL);
if (rc == NULL)
{
snmp_sess_perror(“snmptrapd“ session);
}
return rc;
}
static void snmptrapd_close_sessions(netsnmp_session * sess_list)
{
netsnmp_session *s = NULL *next = NULL;
for (s = sess_list; s != NULL; s = next)
{
next = s->next;
snmp_close(s);
}
}
static void snmptrapd_main_loop(void)
{
int count numfds block;
fd_set readfdswritefdsexceptfds;
struct timeval timeout *tvp;
printf(“snmptrapd_main_loop\n“);
while (netsnmp_running)
{
numfds = 0;
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
block = 0;
tvp = &timeout;
timerclear(tvp);
tvp->tv_sec = 5;
snmp_select_info(&numfds &readfds tvp &block);
if (block == 1)
{
tvp = NULL; /* block without timeout */
}
#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
netsnmp_external_event_info(&numfds &readfds &writefds &exceptfds);
#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */
count = select(numfds &readfds &writefds &exceptfds tvp);
printf(“count = %d\n“ count);
if (count > 0)
{
#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
netsnmp_dispatch_external_events(&count &readfds &writefds &exceptfds);
#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */
/* If there are any more events after external events then try SNMP events. */
if (count > 0)
{
snmp_read(&readfds);
}
}
else
{
switch (count)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6725 2013-06-06 10:57 snmptrapd\snmptrapd-linux.c
文件 7178 2013-06-06 10:49 snmptrapd\snmptrapd-windows.cpp
目录 0 2013-06-09 10:44 snmptrapd
----------- --------- ---------- ----- ----
13903 3
- 上一篇:Excel上机操作题
- 下一篇:用友春招最新资料
相关资源
- net-snmp开始教程
- bootstrap-step
- bootstrap离线文档
- 用bootstrap 搭建响应式手机软件交谈聊
- Bootstrap响应式开场动画登录界面模板
- bootstrap3.0实用组件插件完整版demo
- bootstrap3中文离线手册
- Charge polarization and quantum trapping in Ag
-
Atomic-la
yer and Crystal-Orientation Resolv - mib2中节点的详细中文描述
-
thermal conductivity of me
tallic nanofilms: - bootstrap table +spring boot 实现分页加载
- Bootstrap4 官方模板 ( Hyper - Responsive
- SumatraPDF(pdf阅读器)v3.2.10593中文便携
- SumatraPDF超小超快PDF阅读编辑器
- 基于bootstrap3后台模板(含登陆页面)
- INSPINIA.2.9.2最新后台模板源码,boots
- Bootstrap4中文整理版文本
- bootstrap3.3.7(2018最新版)
- Bootstrap3.3.7离线中文文档
- bootstrap-table-fixed-columns冻结列,并完善
- Bootstrap4 for Axure RP8 and 9
- Axure RP8 元件库之bootstrap3工具
- bootStrap风格的Axure原件
- Axure RP8 bootstrap3 样式库,亲测有效!
- Axure RP8 bootstrap4 样式库,亲测有效!
- snmp4j中文版阅读文档
- 用snmp4j获取本地所有oid
- bootstrap fileinput完整插件
- hAdmin后台UI中文模板bootstrap3.3.6
评论
共有 条评论