SNMP ++ Development Instance 1

Source: Internet
Author: User
Tags snmp snmp object
1. to download SNMP development from the official website, you must first install the SNMP service on the machine. This information is complete on the Internet. During installation, you can download only one file on the Internet, in this way, you can create a package for future use. As long as the SNMP service is enabled, you can use the SNMP service (the trap service may not be enabled at the beginning. After the preparation is complete, we aim to generate two required lib library files. 2. compile and generate libdes. Lib 2.1 create a Win32 project in vs2010, select static library, empty project, and do not need to compile header 2.2 Add all required header files and source files as follows:2.3 generate a solution. A lib file will appear in the DEBUG directory under the project directory, which is exactly what we need 3. Generate snmplib. 3.1 and then create a new Win32 project, static library, empty project, do not need to compile the header 3.2 will decompress the SNMP ++/src directory and all under the libdes-l-4.01a. CPP is added to the source file, and all. you can directly use the project properties-C/C ++ -- General-Add the include directory to add the directory of the header file.
3.3 next, a solution is generated, and the corresponding lib library is also generated. 4. copy snmplib. lib, libdes. lib and ws2_32.lib copy the two generated lib files and the downloaded ws2_32.lib files to the Lib folder in the vs2010 installation directory. For future SNMP Development 5. create test project 5.1 create a project and select the Win32 console application testcip. 5.2 import the header file. Because SNMP is used, you also need to add the header file required by SNMP to the additional inclusion directory. For convenience, you can copy several libdes header files to the include directory of SNMP ++, And the snmp_pp folder under the include directory is a separate header file of SNMP, so you only need to introduce the header file once.


5.3 Add the Lib library.Add the following content to the project attributes in the linker/input.
5.4 compile a test program
#include <iostream>#include "snmp_pp/snmp_pp.h"using namespace std;#define SYSDESCR "1.3.6.1.2.1.1.1.0" // Object ID for System Descriptorvoid get_system_descriptor(){int status;//return statusCTarget ctarget((IpAddress)"192.168.1.111");Vb vb(SYSDESCR);//SNMP++ variable BindingPdu pdu;//SNMP ++ pdu//--------[Construct a SNMP++ SNMP Object--------------Snmp snmp(status);//create a snmp  sessionif (status != SNMP_CLASS_SUCCESS){cout << snmp.error_msg(status);//if fail,print error stringreturn;}//---------[Invoke a SNMP++ Get]------------------------pdu += vb;//add the variable bindingif ((status = snmp.get(pdu,ctarget)) != SNMP_CLASS_SUCCESS){cout << snmp.error_msg(status);}else {pdu.get_vb(vb,0);//extract the variable bindingcout << "System Descriptor = " << vb.get_printable_value();}}
The main function is not written here. If you call this function directly, the running result is ok6.

SNMP ++ Development Instance 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.