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 80 // worst case of output lens 103 #define IP6LEN_NO_SCOPE 16 104 #define IP6LEN_WITH_SCOPE 20 105 #define UDPIP6LEN_NO_SCOPE 18 106 #define UDPIP6LEN_WITH_SCOPE 22 107 #define IS_IP6LEN(n) ((n==16) || (n==20)) 108 #define IS_UDPIP6LEN(n) ((n==18) || (n==22)) 110 #define IPXSOCKLEN 12 112 #define MAX_FRIENDLY_NAME 80 113 #define PP_MAC_HASH0 19 114 #define PP_MAC_HASH1 13 115 #define PP_MAC_HASH2 7 182 {
return !(lhs == rhs); }
189 {
if ((lhs > rhs) || (lhs == rhs))
return true;
return false; }
196 {
if ((lhs < rhs) || (lhs == rhs))
return true;
return false; }
203 {
return !(lhs == rhs); }
222 virtual operator const char *()
const = 0;
270 using SnmpSyntax::operator=;
355 using Address::operator=;
386 const char *friendly_name(
int &status);
394 {
if (addr_changed) format_output();
return output_buffer; }
401 virtual operator const char *()
const 402 {
if (addr_changed) format_output();
return output_buffer; }
417 int get_match_bits(
const IpAddress match_ip)
const;
423 {
return (ip_version == version_ipv4) ?
IPLEN :
430 {
return (ip_version == version_ipv4) ? e_ipv4 :
431 (have_ipv6_scope ? e_ipv6z : e_ipv6); }
452 virtual OctetStr *clone_as_hex()
const;
458 {
return get_length() + 2; }
472 virtual bool map_to_ipv6();
477 virtual unsigned int get_scope()
const;
482 virtual bool set_scope(
const unsigned int scope);
490 {
return (ip_version == version_ipv6) && have_ipv6_scope; }
501 virtual bool parse_address(
const char *inaddr);
505 virtual void format_output()
const;
508 int parse_dotted_ipstring(
const char *inaddr);
511 int parse_coloned_ipstring(
const char *inaddr);
515 int addr_to_friendly();
575 using IpAddress::operator=;
622 {
if (addr_changed) format_output();
return output_buffer; }
629 virtual operator const char *()
const 630 {
if (addr_changed) format_output();
return output_buffer; }
637 void set_port(
const unsigned short p);
644 unsigned short get_port()
const;
650 {
return (ip_version == version_ipv4) ?
UDPIPLEN :
665 virtual bool map_to_ipv6();
671 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
676 virtual bool set_scope(
const unsigned int scope);
684 virtual bool parse_address(
const char *inaddr);
688 virtual void format_output()
const;
702 MacAddress(
const char *inaddr);
705 MacAddress(
const MacAddress &macaddr);
723 virtual int get_asn1_length()
const {
return MACLEN + 2; }
725 using Address::operator=;
739 MacAddress& operator=(
const MacAddress &macaddress);
753 virtual const char *get_printable()
const 754 {
if (addr_changed) format_output();
return output_buffer; }
761 virtual operator const char *()
const 762 {
if (addr_changed) format_output();
return output_buffer; }
767 virtual int get_length()
const {
return MACLEN; }
774 virtual addr_type get_type()
const {
return type_mac; }
777 unsigned int hashFunction()
const;
783 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
789 virtual bool parse_address(
const char *inaddr);
792 virtual void format_output()
const;
794 #endif // _MAC_ADDRESS 807 IpxAddress(
const char *inaddr);
810 IpxAddress(
const IpxAddress &ipxaddr);
828 virtual int get_asn1_length()
const {
return IPXLEN + 2; }
830 using Address::operator=;
844 virtual IpxAddress& operator=(
const IpxAddress &ipxaddress);
848 int get_hostid(MacAddress& mac)
const;
863 virtual const char *get_printable()
const 864 {
if (addr_changed) format_output();
return output_buffer; }
871 virtual operator const char *()
const 872 {
if (addr_changed) format_output();
return output_buffer; }
877 virtual int get_length()
const {
return IPXLEN; }
884 virtual addr_type get_type()
const {
return type_ipx; }
890 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
898 virtual bool parse_address(
const char *inaddr);
902 virtual void format_output()
const;
911 class DLLOPT IpxSockAddress :
public IpxAddress {
918 IpxSockAddress(
const char *inaddr);
921 IpxSockAddress(
const IpxSockAddress &ipxaddr);
928 IpxSockAddress(
const IpxAddress &ipxaddr);
939 virtual int get_asn1_length()
const {
return IPXSOCKLEN + 2; }
941 using IpxAddress::operator=;
954 virtual IpxSockAddress& operator=(
const IpxSockAddress &ipxaddr);
964 void set_socket(
const unsigned short s);
967 unsigned short get_socket()
const;
974 virtual const char *get_printable()
const 975 {
if (addr_changed) format_output();
return output_buffer; }
982 virtual operator const char *()
const 983 {
if (addr_changed) format_output();
return output_buffer; }
988 virtual int get_length()
const {
return IPXSOCKLEN; }
995 virtual addr_type get_type()
const {
return type_ipxsock; }
1001 {
Address::clear(); memset(output_buffer, 0,
sizeof(output_buffer)); }
1007 virtual bool parse_address(
const char *inaddr);
1011 virtual void format_output()
const;
1013 #endif // _IPX_ADDRESS 1075 {
return address ? address->get_asn1_length() : 2; }
1084 using Address::operator=;
1106 {
return (address) ? address->get_printable() : output_buffer; }
1113 virtual operator const char *()
const 1114 {
return address ? (
const char *)*address : output_buffer; }
1120 {
return (address) ? address->get_length() : 0; }
1125 void clear() {
if (address) address->clear(); }
1134 {
return (valid()) ? address->get_type() : type_invalid; }
1156 const MacAddress &cast_macaddress()
const {
return (MacAddress&)*address; }
1165 const IpxAddress &cast_ipxaddress()
const {
return (IpxAddress&)*address; }
1172 const IpxSockAddress &cast_ipxsockaddress()
const 1173 {
return (IpxSockAddress&)*address; }
1179 char output_buffer[1];
1185 virtual bool parse_address(
const char *addr,
1201 #ifdef SNMP_PP_NAMESPACE 1205 #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).