当前位置:文档之家› SNMP++的使用

SNMP++的使用

SNMP++的使用
SNMP++的使用

一、下载SNMP++的

使用的版本是3.2.21a,下载的网址如下:

https://www.doczj.com/doc/171852656.html,/snmp_pp3_x/download_snmp_ppv3/download_snm

p_ppv3.html,建议大家把网页的这几句话先看一下:

Please note that the SNMPv3 support in SNMP++ can be disabled by undefining _SNMPv3 in config.h. In that case the DES library is optional. SNMP++v3.x comes with an IDEA implementation which is disabled by default since v3.2.6b but can be enabled by defining the compiler flag _USE_IDEA. For commercial use of the IDEA algorithm, a license needs to be obtained from MediaCrypt AG.

AES encryption can be used if the LibTomCrypt API is used instead of libDES. Generally, the latest version of LibTomCrypt can be used used with SNMP++ even if not listed below.

SNMP++v3.1.5 and later version pass the tests provided wiht the CERT/CC SNMPv1 Advisory https://www.doczj.com/doc/171852656.html,/advisories/CA-2002-03.html.

总之就是现在SNMP++现在支持SNMPV3版本了,而且支持DES加密算法。

我们要把网页上列出的那几个文件都下载下来,文件列表如下:

LIBDES-l-4.01a

LibTomCrypt v1.02

SNMP++v3.2.21a

SNMP++v3.2 CHANGES

MS VC++7.0 Project Files

建议用FLASHGET下载到同一个目录,比如SNMP++目录

下面就是安装了,或者说是生成LIB文件,我是买了一本书《Visual C++开发基于SNMP

的网络管理软件》,照着书上做的,没有书,从哪儿获得操作指导呢?遗憾的是,我在它的

网站上还有下载的文件中都没有找到很明确的说明。还是要看书。

经过一系列的解压缩后,我们要形成一个文件夹,名为snmp++,里面至少要包括以上目录include、src、libdes,目录的结构如下:

一级目录

二级目录

文件类型

snmp++

include

h头文件

src

cpp文件

libdes

h和cpp文件

其中include目录包括以下内容

address.h

Address classes definitions

asn1.h

interfaces for ASN1 libraries

collect.h

Collection class definitions

counter.h

Counter32 class definitions

ctr64.h

Counter64 class definitions

eventlist.h

UX internal implementation support class gauge.h

Gauge32 class definition

integer.h

Integer32 class definition

ipresolv.h

UX internal implementation support class

msec.h

UX internal implementation support class

msgqueue.h

UX internal implementation support class

notifyqueue.h

UX internal implementation support class

octet.h

Octet String class definition

oid.h

Oid class definition

oid_def.h

UX internal implementation support class

pdu.h

Pdu class definitions

smi.h

SMI definitions

smival.h

SnmpSyntax class definitions

snmp_pp.h

SNMP++ main header file ( all one needs to include is this ) snmperrs.h

SNMP++ error messages

snmpmsg.h

SNMP Message class definition

target.h

SnmpTarget class

timetick.h

TimeTicks class

userdefined.h

UX internal implementation support class

usertimeout.h

UX internal implementation support class

vb.h

Variable Binding class definition

src目录包括以下内容

Makefile

make file for HPUX build

address.cpp

Address class source

asn1.cpp

ASN1 encoding and decoding code. Based on CMU code. collect.cpp

Collection class source

counter.cpp

Counter32 class source

ctr64.cpp

Counter64 class source

eventlist.cpp

UX event handler source

gauge.cpp

Gauge32 class source

integer.cpp

Integer32 class source

ipresolv.cpp

UX Ip address resolver source

msec.cpp

UX internal implementation support class

msgqueue.cpp

UX internal implementation support class notifyqueue.cpp

UX internal implementation support class

octet.cpp

Octet String class source

oid.cpp

Oid class source

oidname.cpp

UX internal implementation support class

pdu.cpp

Pdu class source

snmpmsg.cpp

SNMP Message class source

target.cpp

SnmpTarget class source

test_app.cpp

test application source

timetick.cpp

TimeTicks class source

userdefined.cpp

UX internal implementation support class

usertimeout.cpp

UX internal implementation support class

uxsnmp.cpp

UX internal implementation support class

vb.cpp

Variable Binding class source

下面我们要在VC6中编辑生成snmp_pp.lib文件,操作步骤如下:

(1)在开发环境下,选择“File”->“New…”项,在弹出的窗口中选择“Win32 Static Library”,工程名为“snmp_pp”,如图1所示。

图1

(2)单击“OK”按钮,进入下一步,使用缺省选项,如图2所示,点击“Finish”完成,建立一个没有文件的静态链接库工程。

图2

(3)在工作区内,为工程添加解压缩后的所有源文件(即snmp++目录下的src目录下的所有后缀为CPP的文件,如图3所示)

图3

为了让编译的链接库支持SNMPV3,要把snmp++目录下的libdes目录下的c文件包含进来,如图4所示

图4

用同样的方法,添加所有的头文件,如图5,图6所示

图5

图6

(4)文件添加完后,设置工程编译环境。主菜单选“Project”->“Settings…”项,弹出的窗口中,选“C/C++”页,按照下表进行设置,如图7所示

Category

Code Generation

Use run-time library

Debug Multithreaded

图7

(5)目录设置。主菜单“Tools”->“Options…”项,弹出的窗口中,选“Directories”页,添加SNMP++头文件所在的目录(要强调一点,我们要做一点改动,即把

snmp++\include目录下的所有H文件拷贝到snmp++目录),不只头文件所在的目录,还有包括CPP和C文件所在的目录及LIBDES这个目录),如图8所示

图8

(6)选择“Build”->“Build snmp_pp.lib”项,生成静态链接库文件snmp_pp.lib。(7)将生成的静态链接库文件直接复制到VC安装目录:\VC98\Lib中去,就可以像使用VC自带的其他库文件一样使用它了。

下面就是SNMP++的使用了,以一个例子来说明,源代码如下:

#include

#include

void main()

{

IpAddress ip("127.0.0.1");

cout<<"ip address is:"<

UdpAddress udp("127.0.0.1:8888");

cout<<"udp address is:"<

cout<<"udp address port is:"<<

udp="127.0.0.1";

udp.set_port(9999);

cout<

ip="258.0.0.1";

if(!ip.valid())

cout<<"bad ip:258.0.0.1"<

else

cout<<"good ip:258.0.0.1"<

ip="255.0.0.1";

if(!ip.valid())

cout<<"error ip:255.0.0.1"<

else

cout<<"good ip:255.0.0.1"<

ip="0.0.0.0";

if(!ip.valid())

cout<<"error ip:0.0.0.0"<

else

cout<<"good ip:0.0.0.0"<

ip="255.255.255.255";

if(!ip.valid())

cout<<"error ip:255.255.255.255"<

else

cout<<"good ip:255.255.255.255"<< FONT>

}

但是它在VC6中的编译还是有一些技巧的,我按顺序说一下:

(1)在VC中新建一个Win32 Application的程序,命名为Cip,如图9所示

图9

(2)新建一个C++源文件,名为Cip,如图10所示

(3)把源代码贴进去

(4)试编译一次

会出一大堆这些的错:

--------------------Configuration: Cip - Win32

Debug--------------------

Compiling...

Cip.cpp

Linking...

Cip.obj : error LNK2001: unresolved external symbol "public: class IpAddress & __thiscall IpAddress::operator=(char const *)"

(??4IpAddress@@QAEAAV0@PBD@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: void __thiscall UdpAddress::set_port(unsigned short)"

(?set_port@UdpAddress@@QAEXG@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: class UdpAddress & __thiscall UdpAddress::operator=(char const *)"

(??4UdpAddress@@QAEAAV0@PBD@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: unsigned short __thiscall UdpAddress::get_port(void)const "

(?get_port@UdpAddress@@QBEGXZ)

Cip.obj : error LNK2001: unresolved external symbol "public:

__thiscall UdpAddress::UdpAddress(char const *)"

(??0UdpAddress@@QAE@PBD@Z)

Cip.obj : error LNK2001: unresolved external symbol "public:

__thiscall IpAddress::IpAddress(char const *)"

(??0IpAddress@@QAE@PBD@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall IpAddress::map_to_ipv6(void)"

(?map_to_ipv6@IpAddress@@UAEHXZ)

Cip.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall IpAddress::format_output(void)const "

(?format_output@IpAddress@@MBEXXZ)

Cip.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall IpAddress::parse_address(char const *)" (?parse_address@IpAddress@@MAE_NPBD@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall IpAddress::clear(void)" (?clear@IpAddress@@UAEXXZ) Cip.obj : error LNK2001: unresolved external symbol "public: virtual class SnmpSyntax & __thiscall IpAddress::operator=(class SnmpSyntax const &)" (??4IpAddress@@UAEAAVSnmpSyntax@@ABV1@@Z)

Cip.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall Address::clear(void)"

(?clear@Address@@MAEXXZ)

Cip.obj : error LNK2001: unresolved external symbol "public:

__thiscall IpAddress::IpAddress(class IpAddress const &)"

(??0IpAddress@@QAE@ABV0@@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall UdpAddress::map_to_ipv6(void)"

(?map_to_ipv6@UdpAddress@@UAEHXZ)

Cip.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall UdpAddress::format_output(void)const "

(?format_output@UdpAddress@@MBEXXZ)

Cip.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall UdpAddress::parse_address(char const *)" (?parse_address@UdpAddress@@MAE_NPBD@Z)

Cip.obj : error LNK2001: unresolved external symbol "public: virtual class SnmpSyntax & __thiscall UdpAddress::operator=(class SnmpSyntax const &)" (??4UdpAddress@@UAEAAVSnmpSyntax@@ABV1@@Z)

Cip.obj : error LNK2001: unresolved external symbol "public:

__thiscall UdpAddress::UdpAddress(class UdpAddress const &)"

(??0UdpAddress@@QAE@ABV0@@Z)

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16

Debug/Cip.exe : fatal error LNK1120: 19 unresolved externals

Error executing link.exe.

Cip.exe - 20 error(s), 0 warning(s)

其实是因为没有把snmp_pp.lib包括进去,把它加进去即可,如图11所示

这样执行“Rebuild All”命令后,只有9个错误了,如下所示:

Deleting intermediate files and output files for project 'Cip - Win32 Debug'.

--------------------Configuration: Cip - Win32

Debug--------------------

Compiling...

Cip.cpp

Linking...

LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _inet_ntoa@4

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _gethostbyname@4

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol

_gethostbyaddr@12

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _inet_addr@4

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _htons@4

snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _ntohs@4

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16

Debug/Cip.exe : fatal error LNK1120: 8 unresolved externals

Error executing link.exe.

Cip.exe - 9 error(s), 1 warning(s)

我们再一一解决,把WS2_32.LIB文件包括进来,如图12所示

执行“Rebuild All”命令后,只有2个错误了,如下所示

Deleting intermediate files and output files for project 'Cip - Win32 Debug'.

--------------------Configuration: Cip - Win32

Debug--------------------

Compiling...

Cip.cpp

Linking...

LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16

Debug/Cip.exe : fatal error LNK1120: 1 unresolved externals

Error executing link.exe.

Cip.exe - 2 error(s), 1 warning(s)

再改一下,如图13所示

图13

有两处改动,一是添加了一条/nodefaultlib:”libcmtd”,二是把

/subsystem:window改成了/subsystem:console。

程序最后的运行结果,如图所示

图14

以上就是整个的SNMP++在VC6下的编译和使用过程,写的很罗嗦,但主要是我在学习的过程中遇到很多困难,但是解决问题的过程也是能力提高的过程,所以记录下来与大家分享。

相关主题
文本预览
相关文档 最新文档