56 #ifndef _SNMP_ADDRESS_H_ 57 #define _SNMP_ADDRESS_H_ 71 #if defined (CPU) && CPU == PPC603 80 #include <sys/socket.h> 81 #include <netinet/in.h> 83 #include <arpa/inet.h> 88 #if !defined __CYGWIN32__ && !defined __hpux && !defined linux && !defined _AIX 93 #ifdef SNMP_PP_NAMESPACE 98 #define ADDRBUF 50 // worst case of address lens 99 #define OUTBUFF_UDP 80 // worst case of output lens 100 #define OUTBUFF_IP 55 // worst case of output lens 101 #define OUTBUFF_OTHER 80 // worst case of output lens 105 #define IP6LEN_NO_SCOPE 16 106 #define IP6LEN_WITH_SCOPE 20 107 #define UDPIP6LEN_NO_SCOPE 18 108 #define UDPIP6LEN_WITH_SCOPE 22 109 #define IS_IP6LEN(n) ((n==16) || (n==20)) 110 #define IS_UDPIP6LEN(n) ((n==18) || (n==22)) 112 #define IPXSOCKLEN 12 114 #define MAX_FRIENDLY_NAME 80 115 #define PP_MAC_HASH0 19 116 #define PP_MAC_HASH1 13 117 #define PP_MAC_HASH2 7 184 {
return !(lhs == rhs); }
191 {
if ((lhs > rhs) || (lhs == rhs))
return true;
return false; }
198 {
if ((lhs < rhs) || (lhs == rhs))
return true;
return false; }
205 {
return !(lhs == rhs); }
224 virtual operator const char *()
const = 0;
272 using SnmpSyntax::operator=;
357 using Address::operator=;
388 const char *friendly_name(
int &status);
396 {
if (addr_changed) format_output();
return output_buffer; }
403 virtual operator const char *()
const 404 {
if (addr_changed) format_output();
return output_buffer; }
419 int get_match_bits(
const IpAddress match_ip)
const;
425 {
return (ip_version == version_ipv4) ?
IPLEN :
432 {
return (ip_version == version_ipv4) ? e_ipv4 :
433 (have_ipv6_scope ? e_ipv6z : e_ipv6); }
454 virtual OctetStr *clone_as_hex()
const;
460 {
return get_length() + 2; }
474 virtual bool map_to_ipv6();
479 virtual unsigned int get_scope()
const;
484 virtual bool set_scope(
const unsigned int scope);
492 {
return (ip_version == version_ipv6) && have_ipv6_scope; }
503 virtual bool parse_address(
const char *inaddr);
507 virtual void format_output()
const;
510 int parse_dotted_ipstring(
const char *inaddr);
513 int parse_coloned_ipstring(
const char *inaddr);
517 int addr_to_friendly();
577 using IpAddress::operator=;
624 {
if (addr_changed) format_output();
return output_buffer; }
631 virtual operator const char *()
const 632 {
if (addr_changed) format_output();
return output_buffer; }
639 void set_port(
const unsigned short p);
646 unsigned short get_port()
const;
652 {
return (ip_version == version_ipv4) ?
UDPIPLEN :
667 virtual bool map_to_ipv6();
673 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
678 virtual bool set_scope(
const unsigned int scope);
686 virtual bool parse_address(
const char *inaddr);
690 virtual void format_output()
const;
704 MacAddress(
const char *inaddr);
707 MacAddress(
const MacAddress &macaddr);
725 virtual int get_asn1_length()
const {
return MACLEN + 2; }
727 using Address::operator=;
741 MacAddress& operator=(
const MacAddress &macaddress);
755 virtual const char *get_printable()
const 756 {
if (addr_changed) format_output();
return output_buffer; }
763 virtual operator const char *()
const 764 {
if (addr_changed) format_output();
return output_buffer; }
769 virtual int get_length()
const {
return MACLEN; }
776 virtual addr_type get_type()
const {
return type_mac; }
779 unsigned int hashFunction()
const;
785 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
791 virtual bool parse_address(
const char *inaddr);
794 virtual void format_output()
const;
796 #endif // _MAC_ADDRESS 809 IpxAddress(
const char *inaddr);
812 IpxAddress(
const IpxAddress &ipxaddr);
830 virtual int get_asn1_length()
const {
return IPXLEN + 2; }
832 using Address::operator=;
846 virtual IpxAddress& operator=(
const IpxAddress &ipxaddress);
850 int get_hostid(MacAddress& mac)
const;
865 virtual const char *get_printable()
const 866 {
if (addr_changed) format_output();
return output_buffer; }
873 virtual operator const char *()
const 874 {
if (addr_changed) format_output();
return output_buffer; }
879 virtual int get_length()
const {
return IPXLEN; }
886 virtual addr_type get_type()
const {
return type_ipx; }
892 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
900 virtual bool parse_address(
const char *inaddr);
904 virtual void format_output()
const;
913 class DLLOPT IpxSockAddress :
public IpxAddress {
920 IpxSockAddress(
const char *inaddr);
923 IpxSockAddress(
const IpxSockAddress &ipxaddr);
930 IpxSockAddress(
const IpxAddress &ipxaddr);
941 virtual int get_asn1_length()
const {
return IPXSOCKLEN + 2; }
943 using IpxAddress::operator=;
956 virtual IpxSockAddress& operator=(
const IpxSockAddress &ipxaddr);
966 void set_socket(
const unsigned short s);
969 unsigned short get_socket()
const;
976 virtual const char *get_printable()
const 977 {
if (addr_changed) format_output();
return output_buffer; }
984 virtual operator const char *()
const 985 {
if (addr_changed) format_output();
return output_buffer; }
990 virtual int get_length()
const {
return IPXSOCKLEN; }
997 virtual addr_type get_type()
const {
return type_ipxsock; }
1003 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
1009 virtual bool parse_address(
const char *inaddr);
1013 virtual void format_output()
const;
1015 #endif // _IPX_ADDRESS 1077 {
return address ? address->get_asn1_length() : 2; }
1086 using Address::operator=;
1108 {
return (address) ? address->get_printable() : output_buffer; }
1115 virtual operator const char *()
const 1116 {
return address ? (
const char *)*address : output_buffer; }
1122 {
return (address) ? address->get_length() : 0; }
1127 void clear() {
if (address) address->clear(); }
1136 {
return (valid()) ? address->get_type() : type_invalid; }
1158 const MacAddress &cast_macaddress()
const {
return (MacAddress&)*address; }
1167 const IpxAddress &cast_ipxaddress()
const {
return (IpxAddress&)*address; }
1174 const IpxSockAddress &cast_ipxsockaddress()
const 1175 {
return (IpxSockAddress&)*address; }
1181 char output_buffer[1];
1187 virtual bool parse_address(
const char *addr,
1203 #ifdef SNMP_PP_NAMESPACE 1207 #endif // _SNMP_ADDRESS_H_
SNMP_PP_MUTABLE bool addr_changed
SnmpSyntax * clone() const
Clone this object.
SnmpSyntax * clone() const
Clone this object.
~IpAddress()
Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
#define IP6LEN_WITH_SCOPE
unsigned char & operator[](const int position)
Access as an array (read and write).
SnmpSyntax * clone() const
Clone this object.
#define UDPIP6LEN_WITH_SCOPE
#define sNMP_SYNTAX_IPADDR
void clear()
Reset the object.
virtual addr_type get_type() const
Return the type of the address.
DLLOPT friend int operator!=(const Address &lhs, const Address &rhs)
overloaded not equivlence operator, are two addresses not equal?
virtual unsigned int hashFunction() const
InetAddressType
Type returned by Address::get_inet_address_type()
#define sNMP_SYNTAX_OCTETS
DLLOPT friend int operator<=(const Address &lhs, const Address &rhs)
overloaded <= operator, is a1 <= a2
unsigned char operator[](const int position) const
Access as an array (read only).
UdpAddress (IPv4 or IPv6)
virtual bool valid() const
Return if the object contains a valid address.
virtual int get_asn1_length() const
Return the space needed for serialization.
virtual version_type get_ip_version() const
Return the IP version of the address.
virtual addr_type get_type() const
Return the type of the address.
virtual bool is_gen_address() const
Is this a GenAddress object.
int iv_friendly_name_status
virtual GenAddress & operator=(const GenAddress &addr)
Overloaded assignment operator for a GenAddress.
SmiUINT32 get_syntax() const
Return the syntax.
void trim_white_space(char *ptr)
Trim of whitespaces at the start and the end of the string.
virtual int get_inet_address_type() const
Get the InetAddressType value for this address.
virtual SmiUINT32 get_syntax() const
Return the syntax.
DLLOPT friend int operator!=(const Address &lhs, const char *rhs)
overloaded not equivlence operator, are an address and string not equal?
bool has_ipv6_scope() const
const UdpAddress & cast_udpaddress() const
Access the protected address.
SnmpCollection< GenAddress > AddressCollection
Base class of all Address classes.
virtual int get_asn1_length() const
Return the space needed for serialization.
addr_type
Type returned by Address::get_type().
virtual bool is_gen_address() const
Is this a GenAddress object.
SnmpCollection< UdpAddress > UdpAddressCollection
virtual void format_output() const
Used by GenAddress::get_type() if address is not valid.
void clear()
Reset the object.
virtual ~Address()
Allow destruction of derived classes.
const IpAddress & cast_ipaddress() const
Access the protected address.
virtual Address & operator=(const char *str)
virtual int get_length() const
Get the length of the binary address (accessible through operator[]).
virtual const char * get_printable() const
Get a printable ASCII value of the address.
DLLOPT friend int operator>(const Address &lhs, const Address &rhs)
overloaded > operator, is a1 > a2
#define UDPIP6LEN_NO_SCOPE
SmiUINT32 get_syntax() const
Return the syntax.
std::string iv_friendly_name
virtual int get_length() const
Get the length of the binary address (accessible through operator[]).
unsigned char address_buffer[ADDRBUF]
DLLOPT friend int operator<(const Address &lhs, const Address &rhs)
overloaded < operator, is a1 < a2
struct sockaddr_in ipaddr
Address()
Default constructor, clears the buffer and sets valid flag to false.
DLLOPT friend int operator>=(const Address &lhs, const Address &rhs)
overloaded >= operator, is a1 >= a2
virtual const char * get_printable() const
Get a printable ASCII value of the address.
virtual bool parse_address(const char *addr)
An "abstract" (pure virtual) class that serves as the base class for all specific SNMP syntax types...
~GenAddress()
Destructor, free memory.
virtual const char * get_printable() const
Get a printable ASCII value of the address.
DLLOPT friend int operator==(const Address &lhs, const Address &rhs)
overloaded equivlence operator, are two addresses equal?
virtual int get_length() const
Get the length of the binary address (accessible through operator[]).
virtual addr_type get_type() const
Return the type of the address.
void clear()
Reset the object.
version_type
Type returned by IpAddress::get_ip_version() and UdpAddress::get_ip_version().
virtual int get_asn1_length() const
Return the space needed for serialization.
~UdpAddress()
Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).