[AGENT++] IpAddress: how to create a Hex-String instead a String?
Claus Klein
claus.klein at arcormail.de
Sun Nov 7 00:51:53 CET 2010
Hello Jochen,
thanks for your help, it works now fine.
IpAddress _ipAddr("::1");
row->get_nth(nNetSnmpHostAddress)-
>replace_value(_ipAddr.clone_as_hex());
I tried to do it as a new IpAddress class function:
== modified file 'snmp++/include/snmp_pp/address.h'
--- old/snmp++/include/snmp_pp/address.h 2010-10-31 08:30:19 +0000
+++ new/snmp++/include/snmp_pp/address.h 2010-11-06 22:11:06 +0000
@@ -73,6 +73,7 @@
#include "snmp_pp/smival.h"
#include "snmp_pp/collect.h"
#include "snmp_pp/reentrant.h"
+#include "snmp_pp/octet.h"
// include sockets header files
// for Windows16 and Windows32 include Winsock
@@ -437,6 +438,13 @@
virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_IPADDR; };
/**
+ * Return clone as binary string
+ *
+ * @return Pointer to the newly created OctetStr (allocated through
new).
+ */
+ virtual OctetStr *clone_as_hex() const;
+
+ /**
* Return the space needed for serialization.
*/
virtual int get_asn1_length() const
=== modified file 'snmp++/src/address.cpp'
--- old/snmp++/src/address.cpp 2010-10-31 08:30:19 +0000
+++ new/snmp++/src/address.cpp 2010-11-06 22:10:54 +0000
@@ -438,6 +438,19 @@
return iv_friendly_name;
}
+// Clone as OctetStr (binary string)
+OctetStr *IpAddress::clone_as_hex() const
+{
+ ADDRESS_TRACE;
+
+ OctetStr *hex = new OctetStr();
+ hex->set_len(get_length());
+ for (int i=0; i < get_length(); i++)
+ (*hex)[i] = address_buffer[i];
+
+ return hex;
+}
+
// parse a dotted string
int IpAddress::parse_dotted_ipstring(const char *inaddr)
{
---------------------------
What do you think to add something like that to the snmp++ library?
Regards,
Claus
On 06.11.2010, at 14:00, Jochen Katz wrote:
>
> The hex string could be created like this:
> OctetStr hex;
> hex.set_len(ip.get_length());
> for (int i=0; i < ip.get_length(); i++)
> hex[i] = ip[i];
>
More information about the AGENTPP
mailing list