1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
14 _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
15 _## Permission to use, copy, modify, distribute and/or sell this software
16 _## and/or its documentation is hereby granted without fee. User agrees
17 _## to display the above copyright notice and this license notice in all
18 _## copies of the software and any documentation of the software. User
19 _## agrees to assume all liability for the use of the software;
20 _## Hewlett-Packard and Jochen Katz make no representations about the
21 _## suitability of this software for any purpose. It is provided
22 _## "AS-IS" without warranty of any kind, either express or implied. User
23 _## hereby grants a royalty-free license to any and all derivatives based
24 _## upon this software code base.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
31 Hewlett-Packard Company
33 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
34 Permission to use, copy, modify, distribute and/or sell this software
35 and/or its documentation is hereby granted without fee. User agrees
36 to display the above copyright notice and this license notice in all
37 copies of the software and any documentation of the software. User
38 agrees to assume all liability for the use of the software; Hewlett-Packard
39 makes no representations about the suitability of this software for any
40 purpose. It is provided "AS-IS without warranty of any kind,either express
41 or implied. User hereby grants a royalty-free license to any and all
42 derivatives based upon this software code base.
45 SNMP++ A D D R E S S . H
47 ADDRESS CLASS DEFINITION
49 DESIGN + AUTHOR: Peter E Mellquist
52 Address class definition. Encapsulates various network
53 addresses into easy to use, safe and portable classes.
55 =====================================================================*/
56 // $Id: address.h 307 2007-09-14 20:01:45Z katz $
62 //----[ includes ]-----------------------------------------------------
65 #if defined (CPU) && CPU == PPC603
72 #include "snmp_pp/config_snmp_pp.h" // for _IPX_ADDRESS and _MAC_ADDRESS
73 #include "snmp_pp/smival.h"
74 #include "snmp_pp/collect.h"
75 #include "snmp_pp/reentrant.h"
77 // include sockets header files
78 // for Windows16 and Windows32 include Winsock
79 // otherwise assume UNIX
80 #if defined (CPU) && CPU == PPC603
86 #if !defined(_AIX) && !defined(__QNX_NEUTRINO)
89 #include <sys/socket.h>
90 #include <netinet/in.h>
92 #include <arpa/inet.h>
94 #include <strings.h> // This is needed for FD_SET, bzero
97 #if !defined __CYGWIN32__ && !defined __hpux && !defined linux && !defined _AIX
98 extern int h_errno; // defined in WinSock header, but not for UX?!
102 #ifdef SNMP_PP_NAMESPACE
106 //----[ macros ]-------------------------------------------------------
107 #define ADDRBUF 50 // worst case of address lens
108 #define OUTBUFF 80 // worst case of output lens
112 #define IP6LEN_NO_SCOPE 16
113 #define IP6LEN_WITH_SCOPE 20
114 #define UDPIP6LEN_NO_SCOPE 18
115 #define UDPIP6LEN_WITH_SCOPE 22
116 #define IS_IP6LEN(n) ((n==16) || (n==20))
117 #define IS_UDPIP6LEN(n) ((n==18) || (n==22))
119 #define IPXSOCKLEN 12
121 #define MAX_FRIENDLY_NAME 80
126 //---[ forward declarations ]-----------------------------------------
129 //----[ Address class ]-----------------------------------------------
132 * Base class of all Address classes.
134 class DLLOPT Address : public SnmpSyntax
136 friend class GenAddress;
139 //----[ enumerated types for address types ]---------------------------
141 * Type returned by Address::get_type().
145 type_ip, ///< IpAddress (IPv4 or IPv6)
146 type_ipx, ///< IpxAddress
147 type_udp, ///< UdpAddress (IPv4 or IPv6)
148 type_ipxsock, ///< IpxSockAddress
149 type_mac, ///< MacAddress
150 type_invalid ///< Used by GenAddress::get_type() if address is not valid
154 * Type returned by IpAddress::get_ip_version() and
155 * UdpAddress::get_ip_version().
159 version_ipv4, ///< IPv4
160 version_ipv6 ///< IPv6
164 * Default constructor, clears the buffer and sets valid flag to false.
169 * Allow destruction of derived classes.
171 virtual ~Address() {};
173 /// overloaded equivlence operator, are two addresses equal?
174 DLLOPT friend int operator==(const Address &lhs,const Address &rhs);
176 /// overloaded not equivlence operator, are two addresses not equal?
177 DLLOPT friend int operator!=(const Address &lhs, const Address &rhs)
178 { return !(lhs == rhs); };
180 /// overloaded > operator, is a1 > a2
181 DLLOPT friend int operator>(const Address &lhs,const Address &rhs);
183 /// overloaded >= operator, is a1 >= a2
184 DLLOPT friend int operator>=(const Address &lhs,const Address &rhs)
185 { if ((lhs > rhs) || (lhs == rhs)) return true; return false; };
187 /// overloaded < operator, is a1 < a2
188 DLLOPT friend int operator<(const Address &lhs,const Address &rhs);
190 /// overloaded <= operator, is a1 <= a2
191 DLLOPT friend int operator<=(const Address &lhs, const Address &rhs)
192 { if ((lhs < rhs) || (lhs == rhs)) return true; return false; };
194 /// equivlence operator overloaded, are an address and a string equal?
195 DLLOPT friend int operator==(const Address &lhs,const char *rhs);
197 /// overloaded not equivlence operator, are an address and string not equal?
198 DLLOPT friend int operator!=(const Address &lhs,const char *rhs)
199 { return !(lhs == rhs); };
201 /// overloaded < , is an address greater than a string?
202 DLLOPT friend int operator>(const Address &lhs,const char *rhs);
204 /// overloaded >=, is an address greater than or equal to a string?
205 DLLOPT friend int operator>=(const Address &lhs,const char *rhs);
207 /// overloaded < , is an address less than a string?
208 DLLOPT friend int operator<(const Address &lhs,const char *rhs);
210 /// overloaded <=, is an address less than or equal to a string?
211 DLLOPT friend int operator<=(const Address &lhs,const char *rhs);
214 * Overloaded operator for streaming output.
216 * @return String containing the numerical address
218 virtual operator const char *() const = 0;
221 * Return if the object contains a valid address.
223 * @return true if the object is valid
225 virtual bool valid() const { return valid_flag; };
228 * Return the space needed for serialization.
230 virtual int get_asn1_length() const = 0;
233 * Access as an array (read and write).
234 * @note Only pass in values between 0 and get_length().
236 * @param position - pos to return
237 * @return reference to the byte at the given position
239 unsigned char& operator[](const int position)
240 { addr_changed = true; valid_flag = true;
241 return (position < ADDRBUF) ? address_buffer[position]
242 : address_buffer[0]; };
245 * Access as an array (read only).
246 * @note Only pass in values between 0 and get_length().
248 * @param position - pos to return
249 * @return the byte at the given position
251 unsigned char operator[](const int position) const
252 { return (position < ADDRBUF) ? address_buffer[ position] : 0; }
256 * Get the length of the binary address (accessible through operator[]).
258 virtual int get_length() const = 0;
261 * Get the type of the address.
262 * @see Address::addr_type
264 virtual addr_type get_type() const = 0;
267 * Overloaded assignment operator.
269 virtual SnmpSyntax& operator=(const SnmpSyntax &val) = 0;
272 virtual unsigned int hashFunction() const { return 0;};
275 SNMP_PP_MUTABLE bool addr_changed;
277 unsigned char address_buffer[ADDRBUF]; // internal representation
279 // parse the address string
280 // redefined for each specific address subclass
281 virtual bool parse_address(const char * inaddr) = 0;
284 // redefined for each specific address subclass
285 virtual void format_output() const = 0;
288 * Trim of whitespaces at the start and the end of the string.
290 * @param ptr - string to trim
292 void trim_white_space(char * ptr);
295 * Is this a GenAddress object.
297 virtual bool is_gen_address() const { return false; };
304 #if !defined HAVE_GETHOSTBYNAME_R || !defined HAVE_GETHOSTBYADDR_R || !defined HAVE_REENTRANT_GETHOSTBYNAME || !defined HAVE_REENTRANT_GETHOSTBYADDR
306 static SnmpSynchronized syscall_mutex;
313 //-----------------------------------------------------------------------
314 //---------[ IP Address Class ]------------------------------------------
315 //-----------------------------------------------------------------------
316 class DLLOPT IpAddress : public Address
320 * Construct an empty invalid IP address.
325 * Construct an IP address from a string.
327 * The following formats can be used:
328 * - hostname with or without domain ("www.agentpp.com", "printsrv")
329 * - Numerical IPv4 address ("192.168.17.1")
330 * - Numerical IPv6 address ("abcd:1234::a:b:1", "::abcd:1")
331 * - Numerical IPv6 address with scope ("abcd:1234::a:b:1%3", "::abcd:1%1")
333 * @param inaddr - Hostname or IP address
335 IpAddress(const char *inaddr);
338 * Construct an IP address from another IP address.
340 * @param ipaddr - address to copy
342 IpAddress(const IpAddress &ipaddr);
345 * Construct an IP address from a GenAddress.
347 * @param genaddr - address to copy
349 IpAddress(const GenAddress &genaddr);
352 * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
357 * Map other SnmpSyntax objects to IpAddress.
359 SnmpSyntax& operator=(const SnmpSyntax &val);
362 * Overloaded assignment operator for other IP addresses.
364 IpAddress& operator=(const IpAddress &ipaddress);
367 * Overloaded assignment operator for strings.
369 IpAddress& operator=(const char *inaddr);
374 * @return Pointer to the newly created object (allocated through new).
376 SnmpSyntax *clone() const { return (SnmpSyntax *) new IpAddress(*this); };
379 * Return the friendly name. Does a reverse DNS lookup for the IP address.
381 * @param status - The errno value for the lookup
383 * @return the friendly name or a zero length string (no null pointer)
385 char *friendly_name(int &status);
388 * Get a printable ASCII value of the address.
390 * @return String containing the numerical address
392 virtual const char *get_printable() const
393 { if (addr_changed) format_output(); return output_buffer; };
396 * Overloaded operator for streaming output.
398 * @return String containing the numerical address
400 virtual operator const char *() const
401 { if (addr_changed) format_output(); return output_buffer; };
404 * Logically AND the address with the param.
406 * @param ipaddr - address to use as mask
408 void mask(const IpAddress &ipaddr);
412 * Get the count of matching bits from the left.
414 * @param match_ip - address to match with
416 int get_match_bits(const IpAddress match_ip) const;
419 * Get the length of the binary address (accessible through operator[]).
421 virtual int get_length() const
422 { return (ip_version == version_ipv4) ? IPLEN :
423 (have_ipv6_scope ? IP6LEN_WITH_SCOPE : IP6LEN_NO_SCOPE); };
426 * Return the type of the address.
427 * @see Address::addr_type
428 * @return Always Address:type_ip
430 virtual addr_type get_type() const { return type_ip; };
435 * @return This method always returns sNMP_SYNTAX_IPADDR.
437 virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_IPADDR; };
440 * Return the space needed for serialization.
442 virtual int get_asn1_length() const
443 { return get_length() + 2; };
446 * Return the IP version of the address.
448 * @return one of Address::version_type
450 virtual version_type get_ip_version() const { return ip_version; };
453 * Map a IPv4 address to a IPv6 address.
455 * @return - TRUE if no error occured.
457 virtual int map_to_ipv6();
462 virtual unsigned int get_scope() const;
467 virtual bool set_scope(const unsigned int scope);
474 bool has_ipv6_scope() const
475 { return (ip_version == version_ipv6) && have_ipv6_scope; };
478 SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer
480 // friendly name storage
481 char iv_friendly_name[MAX_FRIENDLY_NAME];
482 int iv_friendly_name_status;
484 // redefined parse address
485 // specific to IP addresses
486 virtual bool parse_address(const char *inaddr);
488 // redefined format output
489 // specific to IP addresses
490 virtual void format_output() const;
492 // parse a dotted string
493 int parse_dotted_ipstring(const char *inaddr);
495 // parse a coloned string
496 int parse_coloned_ipstring(const char *inaddr);
498 // using the currently defined address, do a DNS
499 // and try to fill up the name
500 int addr_to_friendly();
502 // support both ipv4 and ipv6 addresses
503 version_type ip_version;
505 bool have_ipv6_scope;
508 //------------------------------------------------------------------------
509 //---------[ UDP Address Class ]------------------------------------------
510 //------------------------------------------------------------------------
511 class DLLOPT UdpAddress : public IpAddress
515 * Construct an empty invalid UDP address.
520 * Construct an UDP address from a string.
522 * The following formats can be used additional to those recognized by
524 * - Port added to IPv4 address with '/' or ':'
525 * ("192.168.17.1:161", "192.168.17.1/161", "printsrv/161")
526 * - Port added to IPv6 address with '/' or using '[...]:'
527 * ("::1/162", "[::1]/162", "[::1]:162")
529 * @param inaddr - Hostname or IP address
531 UdpAddress(const char *inaddr);
534 * Construct an UDP address from another UDP address.
536 * @param udpaddr - address to copy
538 UdpAddress(const UdpAddress &udpaddr);
541 * Construct an UDP address from a GenAddress.
543 * @param genaddr - address to copy
545 UdpAddress(const GenAddress &genaddr);
548 * Construct an UDP address from a IP address.
549 * The port will be set to 0.
551 * @param ipaddr - address to copy
553 UdpAddress(const IpAddress &ipaddr);
556 * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
561 * Map other SnmpSyntax objects to UdpAddress.
563 SnmpSyntax& operator=(const SnmpSyntax &val);
566 * Overloaded assignment operator for UdpAddress.
568 UdpAddress& operator=(const UdpAddress &udpaddr);
571 * Overloaded assignment operator for IpAddress.
573 UdpAddress& operator=(const IpAddress &ipaddr);
576 * Overloaded assignment operator for strings.
578 UdpAddress& operator=(const char *inaddr);
583 * @return This method always returns sNMP_SYNTAX_OCTETS.
585 SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
588 * Return the space needed for serialization.
590 virtual int get_asn1_length() const
591 { return get_length() + 2; };
596 * @return Pointer to the newly created object (allocated through new).
598 SnmpSyntax *clone() const { return (SnmpSyntax *) new UdpAddress(*this); };
601 * Get a printable ASCII value of the address.
603 * @return String containing the numerical address
605 virtual const char *get_printable() const
606 { if (addr_changed) format_output(); return output_buffer; };
609 * Overloaded operator for streaming output.
611 * @return String containing the numerical address
613 virtual operator const char *() const
614 { if (addr_changed) format_output(); return output_buffer; };
617 * Set the port number.
619 * @note If the object is not valid(), the port may not be set.
621 void set_port(const unsigned short p);
624 * Get the port number.
626 * @return The port number, or 0 is the object is not valid.
628 unsigned short get_port() const;
631 * Get the length of the binary address (accessible through operator[]).
633 virtual int get_length() const
634 { return (ip_version == version_ipv4) ? UDPIPLEN :
635 (have_ipv6_scope ? UDPIP6LEN_WITH_SCOPE : UDPIP6LEN_NO_SCOPE);};
638 * Return the type of the address.
639 * @see Address::addr_type
640 * @return Always Address:type_udp
642 virtual addr_type get_type() const { return type_udp; };
645 * Map a IPv4 UDP address to a IPv6 UDP address.
647 * @return - TRUE if no error occured.
649 virtual int map_to_ipv6();
655 { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
660 virtual bool set_scope(const unsigned int scope);
663 SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer
664 char sep; // separator
666 // redefined parse address
667 // specific to IP addresses
668 virtual bool parse_address(const char *inaddr);
670 // redefined format output
671 // specific to IP addresses
672 virtual void format_output() const;
676 //-------------------------------------------------------------------------
677 //---------[ 802.3 MAC Address Class ]-------------------------------------
678 //-------------------------------------------------------------------------
679 class DLLOPT MacAddress : public Address {
682 // constructor, no arguments
685 // constructor with a string argument
686 MacAddress(const char *inaddr);
688 // constructor with another MAC object
689 MacAddress(const MacAddress &macaddr);
691 // construct a MacAddress with a GenAddress
692 MacAddress(const GenAddress &genaddr);
700 * @return This method always returns sNMP_SYNTAX_OCTETS.
702 SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
705 * Return the space needed for serialization.
707 virtual int get_asn1_length() const { return MACLEN + 2; };
710 * Map other SnmpSyntax objects to MacAddress.
712 SnmpSyntax& operator=(const SnmpSyntax &val);
714 // assignment to another IpAddress object overloaded
715 MacAddress& operator=(const MacAddress &macaddress);
720 * @return Pointer to the newly created object (allocated through new).
722 SnmpSyntax *clone() const { return (SnmpSyntax *) new MacAddress(*this); };
725 * Get a printable ASCII value of the address.
727 * @return String containing the numerical address
729 virtual const char *get_printable() const
730 { if (addr_changed) format_output(); return output_buffer; };
733 * Overloaded operator for streaming output.
735 * @return String containing the numerical address
737 virtual operator const char *() const
738 { if (addr_changed) format_output(); return output_buffer; };
741 * Get the length of the binary address (accessible through operator[]).
743 virtual int get_length() const { return MACLEN; };
746 * Return the type of the address.
747 * @see Address::addr_type
748 * @return Always Address:type_mac
750 virtual addr_type get_type() const { return type_mac; };
753 unsigned int hashFunction() const;
759 { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
762 SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer
764 // redefined parse address for macs
765 virtual bool parse_address(const char *inaddr);
767 // redefined format output for MACs
768 virtual void format_output() const;
770 #endif // _MAC_ADDRESS
773 //------------------------------------------------------------------------
774 //---------[ IPX Address Class ]------------------------------------------
775 //------------------------------------------------------------------------
776 class DLLOPT IpxAddress : public Address {
779 // constructor no args
782 // constructor with a string arg
783 IpxAddress(const char *inaddr);
785 // constructor with another ipx object
786 IpxAddress(const IpxAddress &ipxaddr);
788 // construct with a GenAddress
789 IpxAddress(const GenAddress &genaddr);
797 * @return This method always returns sNMP_SYNTAX_OCTETS.
799 virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
802 * Return the space needed for serialization.
804 virtual int get_asn1_length() const { return IPXLEN + 2; };
807 * Map other SnmpSyntax objects to IpxAddress.
809 SnmpSyntax& operator=(const SnmpSyntax &val);
811 // assignment to another IpAddress object overloaded
812 IpxAddress& operator=(const IpxAddress &ipxaddress);
815 // get the host id portion of an ipx address
816 int get_hostid(MacAddress& mac) const;
822 * @return Pointer to the newly created object (allocated through new).
824 SnmpSyntax *clone() const { return (SnmpSyntax *) new IpxAddress(*this); };
827 * Get a printable ASCII value of the address.
829 * @return String containing the numerical address
831 virtual const char *get_printable() const
832 { if (addr_changed) format_output(); return output_buffer; };
835 * Overloaded operator for streaming output.
837 * @return String containing the numerical address
839 virtual operator const char *() const
840 { if (addr_changed) format_output(); return output_buffer; };
843 * Get the length of the binary address (accessible through operator[]).
845 virtual int get_length() const { return IPXLEN; };
848 * Return the type of the address.
849 * @see Address::addr_type
850 * @return Always Address:type_ipx
852 virtual addr_type get_type() const { return type_ipx; };
858 { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
861 // ipx format separator
863 SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer
865 // redefined parse address for ipx strings
866 virtual bool parse_address(const char *inaddr);
868 // redefined format output for ipx strings
869 // uses same separator as when constructed
870 virtual void format_output() const;
876 //------------------------------------------------------------------------
877 //---------[ IpxSock Address Class ]--------------------------------------
878 //------------------------------------------------------------------------
879 class DLLOPT IpxSockAddress : public IpxAddress {
882 // constructor, no args
885 // constructor with a dotted string
886 IpxSockAddress(const char *inaddr);
888 // construct an Udp address with another Udp address
889 IpxSockAddress(const IpxSockAddress &ipxaddr);
891 //constructor with a GenAddress
892 IpxSockAddress(const GenAddress &genaddr);
894 //constructor with a IpxAddress
895 // default socket # is 0
896 IpxSockAddress(const IpxAddress &ipxaddr);
899 ~IpxSockAddress() {};
902 //virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
905 * Return the space needed for serialization.
907 virtual int get_asn1_length() const { return IPXSOCKLEN + 2; };
910 * Map other SnmpSyntax objects to IpxSockAddress.
912 SnmpSyntax& operator=(const SnmpSyntax &val);
914 // assignment to another IpAddress object overloaded
915 IpxSockAddress& operator=(const IpxSockAddress &ipxaddr);
920 * @return Pointer to the newly created object (allocated through new).
922 SnmpSyntax *clone() const { return (SnmpSyntax *)new IpxSockAddress(*this); };
924 // set the socket number
925 void set_socket(const unsigned short s);
927 // get the socket number
928 unsigned short get_socket() const;
931 * Get a printable ASCII value of the address.
933 * @return String containing the numerical address
935 virtual const char *get_printable() const
936 { if (addr_changed) format_output(); return output_buffer; };
939 * Overloaded operator for streaming output.
941 * @return String containing the numerical address
943 virtual operator const char *() const
944 { if (addr_changed) format_output(); return output_buffer; };
947 * Get the length of the binary address (accessible through operator[]).
949 virtual int get_length() const { return IPXSOCKLEN; };
952 * Return the type of the address.
953 * @see Address::addr_type
954 * @return Always Address:type_ipxsock
956 virtual addr_type get_type() const { return type_ipxsock; };
962 { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
965 SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer
967 // redefined parse address for ipx strings
968 virtual bool parse_address(const char *inaddr);
970 // redefined format output
971 // specific to IP addresses
972 virtual void format_output() const;
974 #endif // _IPX_ADDRESS
979 //-------------------------------------------------------------------------
980 //--------[ Generic Address ]----------------------------------------------
981 //-------------------------------------------------------------------------
982 class DLLOPT GenAddress : public Address
986 * Construct an empty invalid generic address object.
991 * Construct a generic address from a string.
993 * To optimize the speed of the parsing method, use_type can be used
994 * to indicate that the address string is of the specified type.
996 * @param addr - address string
997 * @param use_type - if this value is set, the input string is only
998 * parsed for the given type
1000 GenAddress(const char *addr,
1001 const Address::addr_type use_type = Address::type_invalid);
1004 * Construct a generic address from an Address object.
1006 * @param addr - Any address object
1008 GenAddress(const Address &addr);
1011 * Construct a generic address from another generic address object.
1013 * @param addr - Generic address object to copy
1015 GenAddress(const GenAddress &addr);
1018 * Destructor, free memory.
1020 ~GenAddress() { if (address) delete address; };
1023 * Return the syntax.
1025 * @return This method returns sNMP_SYNTAX_IPADDR, sNMP_SYNTAX_OCTETS
1026 * or sNMP_SYNTAX_NULL if the generic address does not have
1027 * an address object.
1029 SmiUINT32 get_syntax() const
1030 { return address ? address->get_syntax() : sNMP_SYNTAX_NULL; };
1033 * Return the space needed for serialization.
1035 virtual int get_asn1_length() const
1036 { return address ? address->get_asn1_length() : 2; };
1039 * Clone this object.
1041 * @return Pointer to the newly created object (allocated through new).
1043 SnmpSyntax *clone() const { return (SnmpSyntax *)new GenAddress(*this); };
1046 * Overloaded assignment operator for a GenAddress.
1048 GenAddress& operator=(const GenAddress &addr);
1051 * Overloaded assignment operator for a Address.
1053 GenAddress& operator=(const Address &addr);
1056 * Map other SnmpSyntax objects to GenAddress.
1058 SnmpSyntax& operator=(const SnmpSyntax &val);
1061 * Get a printable ASCII value of the address.
1063 * @return String containing the numerical address
1065 virtual const char *get_printable() const
1066 { return (address) ? address->get_printable() : output_buffer; };
1069 * Overloaded operator for streaming output.
1071 * @return String containing the numerical address
1073 virtual operator const char *() const
1074 { return address ? (const char *)*address : output_buffer; };
1077 * Get the length of the binary address (accessible through operator[]).
1079 virtual int get_length() const
1080 { return (address) ? address->get_length() : 0; };
1085 void clear() { if (address) address->clear(); };
1088 * Return the type of the address.
1089 * @see Address::addr_type
1090 * @return Type of the contained address object or Address::type_invalid
1091 * if it is not valid().
1093 virtual addr_type get_type() const
1094 { return (valid()) ? address->get_type() : type_invalid; };
1097 * Access the protected address.
1098 * The caller must make sure that this GenAddress object ist valid()
1099 * and is of the right type (get_type()).
1101 const IpAddress &cast_ipaddress() const { return (IpAddress& )*address; };
1104 * Access the protected address.
1105 * The caller must make sure that this GenAddress object ist valid()
1106 * and is of the right type (get_type()).
1108 const UdpAddress &cast_udpaddress() const { return (UdpAddress&)*address; };
1112 * Access the protected address.
1113 * The caller must make sure that this GenAddress object ist valid()
1114 * and is of the right type (get_type()).
1116 const MacAddress &cast_macaddress() const { return (MacAddress&)*address; };
1121 * Access the protected address.
1122 * The caller must make sure that this GenAddress object ist valid()
1123 * and is of the right type (get_type()).
1125 const IpxAddress &cast_ipxaddress() const { return (IpxAddress&)*address; };
1128 * Access the protected address.
1129 * The caller must make sure that this GenAddress object ist valid()
1130 * and is of the right type (get_type()).
1132 const IpxSockAddress &cast_ipxsockaddress() const
1133 { return (IpxSockAddress&)*address; };
1137 // pointer to a concrete address
1139 char output_buffer[1]; // output buffer
1141 // redefined parse address for generic address
1142 virtual bool parse_address(const char *addr)
1143 { return parse_address(addr, Address::type_invalid); };
1145 virtual bool parse_address(const char *addr,
1146 const Address::addr_type use_type);
1148 // format output for a generic address
1149 virtual void format_output() const {};
1152 * Is this a GenAddress object.
1154 virtual bool is_gen_address() const { return true; };
1157 // create AddressCollection type
1158 typedef SnmpCollection <GenAddress> AddressCollection;
1159 typedef SnmpCollection <UdpAddress> UdpAddressCollection;
1161 #ifdef SNMP_PP_NAMESPACE
1162 } // end of namespace Snmp_pp