Add SNMP ++ to vc6.0

Source: Internet
Author: User
Tags snmp

With the successful compilation of the last snmp_pp.lib file, I learned more about SNMP ++. This is to learn various types of SNMP ++ software packages, they are OID, IPaddress, udpaddress, VB, PDU, and SNMP, in the end, we can use SNMP ++ to perform SNMP operations (such as get) on network devices that support SNMP management (such as Cisco switches ).
I. Self-entertainment OID, IPaddress, and udpaddress
In this case, because there is no network communication operation for these two types of operations, the main function of the oId class is to construct the oId object. We can use the examples in the snmp_pp.docfile to learn the usage of this class (what is snmp_pp.doc), which is the official user manual. We can find the Chinese translation version from Baidu and the original English version from www.yahoo.com. I have downloaded both versions, as you can see ). The example provided in snmp_pp.doc is too long.Source codeI want to divide this example into two parts: one is the most basic OID example and the other is a complete example.
1. Basic OID example
Here I also give a brief description of the operations in VC ++ 6.0.
1) create a Win32 consoleapplicationProgram, Named snmpoid1, as shown in 1:

Figure 1
2) create a C ++ source program named snmpoid1 and add it to the snmpoid1 project, as shown in Figure 2:

Figure 2
3) To avoid a lot of errors during translation, we need to make some necessary settings in "project"-"Settings"-"Link". First, in "Object/librarymodules: "Add snmp_pp.lib and ws2_32.lib, and add/nodefaultlib: libcmtd in" projectoptions ", as shown in 3:


Figure 3
4) The source program and running result 4 are shown below:

Figure 4
2. Complete OID example
With the above foundation, we can confirm that we have the ability to use the SNMP ++ OID class in VC ++ 6.0, so we may wish to have a comprehensive understanding of the oId class. The source code is as follows (note that I did not debug the last part of the source code, so I commented it out. If anyone knows how to use the sprintf statement, please let me know ):
# Include "snmp_pp.h"
# Include "oid. H"
# Include
// # Include
// # Include
// # Include
// # Include
Void main ()
{
// Construct an oId with adotted string and print it out
// Define an oId by and output it
Oido1 ("1.2.3.4.5.6.7.8.9.1 ");
Cout <"O1 =" <o1.get _ printable () <
// Construct an oId withanother OID and print it out
// Define another OID with one OID and output it
Oid O2 (O1 );
Cout <"O2 =" <o2.get _ printable () <
// Trim O2's last value andprint it out
// Trim is used to delete n sub-units on the rightmost side of the oId. The default value is 1. The output result shows that 1 on the rightmost side is deleted.
O2.trim (1 );
Cout <"O2 =" <o2.get _ printable () <

// Add a 2 value to the end ofO2 and print it out
// Add 2 to O2 and output it
O2 + = 2;
Cout <"O2 =" <o2.get _ printable () <

// Create a new OID, O3
// Define a new OID, O3
Oid O3;
// Assign O3 a value and printit out
// Define the O3 value and output it
O3 = "1.2.3.4.5.6.7.8.9.3 ";
Cout <"O3 =" <o3.get _ printable () <

// Create O4
// Create an oId, O4
Oid O4;

// Assign O4 O1's Value
// Define the O4 value with O1
O4 = O1;

// Trim off O4 by 1
// Delete the rightmost value of O4
O4.trim (1 );

// Concat A 4 onto O4 andprint it out
// Add ". 4" after O4 and Output
O4 + = ". 4 ";
Cout <"O4 =" <o4.get _ printable () <

// Make O5 from O1 and printit out
// Define and output it with O1
Oid O5 (O1 );
Cout <"O5 =" <o5.get _ printable () <
// Compare two not equaloids
// Compare the two OID values to see if they are equal. Because the last of O1 is 1 and the last of O2 is 2, they are not equal.
If (O1 = O2) Cout <"o1equals O2" <
Else Cout <"O1 not equal to O2" <

// Print out a piece ofo1
// Output one piece of O1. The role of strval is get string value of avariable. In this example, 1-3 is used.
Cout <"strval (3) of O1 =" <o1.get _ printable (3) <

// Print out a piece ofo1
// The output ranges from 1 to 3 on the left.
Cout <"strval (1, 3) ofo1 =" <o1.get _ printable (1, 3) <

// Set O1's last subid
O1 [o1.len ()-1] = 49;
Cout <"O1 modified =" <o1.get _ printable () <

// Set O1's 3rd subid
O1 [2] = 49;
Cout <"O1 modified =" <o1.get _ printable () <

// Get the last subid of02
Cout <"Last of O2 =" <O2 [o2.len ()-1] <

// Get the 3rd subid of02
Cout <"3rd of O2 =" <O2 [2] <

// Ncompare
// Ncompare is used to compare the first n sub-units of the oId from left to right. In this example, O1 and O2 have the same three units, so the output is "="
If (o1.ncompare (3, O2 ))
Cout <"ncompare O1, O2, 3 =" <
Else
Cout <"ncompare O1, O2, 3! = "<

// Make an array of oids
Oid oids [30]; int W;
For (W = 0; W <30; W ++)
{
Oids [w] = "300.301.302.303.304.305.306.307 ";
Oids [w] + = (W + 1 );
}
/* For (W = 0; W <25; W ++)
{
Sprintf (MSG, "oids [% d] = % s", W, oids [w]. get_printable ());
Printf ("% s", MSG, strlen (MSG ));
}*/
}
3. IPaddress and udpaddress classes
1) The first source program Code :
# Include "snmp_pp.h"
# Include
Void main ()
{
Genaddressaddress1 ("10.4.8.5 "); // Make an IP genaddress to generate a genaddress IP Address
Cout <
Genaddressaddress2 ("01020304-10111213141516 "); // Make an IPX genaddress
Cout <
Genaddressaddress3 ("01: 02: 03: 04: 05: 06 "); // Make a Mac genaddress to generate a genaddress MAC address

Cout <address3.get _ printable () <

If (! Address1.valid ()) // Check validity
Cout <"address1! Valid ";
}
Result 5:

Figure 5
2) source code of the second program
// Address class examples
# Include
# Include "snmp_pp.h"
# Include "address. H"
Void main ()
{
// -------------- [Ipaddressconstruction] ------------------------------------------------------
Ipaddressip1 (""); // Makes an invalid IPaddress object. If it is written as ipaddressip1 (), it cannot be assigned to IP1,
// If ipaddressip1 ("");, you can assign a value to IP1.
Ipaddressip2 ("10.4.8.5 "); // Makes a IPaddress verifies dotted format
// IPaddress ip2 is defined in dotted decimal format
Ipaddressip3 (ip2 ); // Makes an IPaddress using another IPaddress
// Define IP3 with ip2
Ipaddressip4 ("trout.rose.hp.com "); // Makes an IPaddress does DNS on string
Cout <"ip2 =" <
Cout <"IP3 =" <
Cout <"ip4 =" <
// -------------- [Mac addressconstruction] -----------------------------------------------------
Macaddressmac1 (""); // Makes an invalid MAC address. Add "" to the brackets to assign a value to mac1.
Macaddressmac2 ("08: 09: 12: 34: 52: 12 "); // Makes and verifies a MAC address
// Define macaddress mac2
Macaddressmac3 (mac2 ); // Makes a Mac fromanother Mac
// Define mac3 with mac2
Cout <"mac2 =" <
Cout <"mac3 =" <
// From the output result, mac2 and mac3 are the same.
// --------------- [Gen address construction] -------------------------------------------------------
Genaddress addr1 ("10.4.8.5"); // defines genaddressaddr1
Genaddress addr2 ("01020304: 050607080900"); // defines genaddress addr2
Cout <"addr1 =" <
Cout <"addr2 =" <
// --------------- [Assigning addresses] --------------------------------------------------------------
IP1 = "15.29.33.10 ";
Cout <"IP1 =" <
// Ipx1 = "00000001-080912345212 ";
Mac1 = "08: 09: 12: 34: 52: 12 ";
Cout <"mac1 =" <
}
Output result 6:

 

Figure 6

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.