一、安装配置net-snmp
首先,确保安装好了net-snmp,我是安装在windows下,下载exe文件直接安装比较方便,包括环境变量和注册表需要修改的地方都已经帮我们设置好了。我们只关心如何使用net-snmp给我们提供的库。同时还要安装perl,目前还没有看到具体的作用在哪里,先安装着,以后在说明。
二、建立自己的net-snmp项目
我用的vs2010,为了方便起见,新建一个win32控制台的空项目。下载
http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application提供的snmpdemoapp.c源文件,并添加到你的项目源文件中,然后编译一下。我这里选择注释掉了使用snmpv3版本,直接使用v1来发送get Request,原因是:使用v3版本会提示“找不到符号:usmHMACMD5AuthProtocol”,需要自己下载gcc,且将上面的网页的makefile文件下载下来执行
#include <stdlib.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
#include "net-snmp/library/transform_oids.h"
/* change the word "define" to "undef" to try the (insecure) SNMPv1 version */
//#define DEMO_USE_SNMP_VERSION_3
#ifdef DEMO_USE_SNMP_VERSION_3
const char *our_v3_passphrase = "The Net-SNMP Demo Password";
#endif
int main(int argc, char ** argv)
{
netsnmp_session session, *ss;
netsnmp_pdu *pdu;
netsnmp_pdu *response;
oid anOID[MAX_OID_LEN];
size_t anOID_len;
netsnmp_variable_list *vars;
int status;
in