SNMP++  3.3.4
IpAddress Class Reference

#include <address.h>

Inheritance diagram for IpAddress:
Collaboration diagram for IpAddress:

Public Member Functions

 IpAddress ()
 Construct an empty invalid IP address. More...
 
 IpAddress (const char *inaddr)
 Construct an IP address from a string. More...
 
 IpAddress (const IpAddress &ipaddr)
 Construct an IP address from another IP address. More...
 
 IpAddress (const GenAddress &genaddr)
 Construct an IP address from a GenAddress. More...
 
 ~IpAddress ()
 Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden). More...
 
virtual SnmpSyntaxoperator= (const SnmpSyntax &val)
 Map other SnmpSyntax objects to IpAddress. More...
 
virtual Addressoperator= (const Address &val)
 Map other Address objects to IpAddress. More...
 
virtual IpAddressoperator= (const IpAddress &ipaddress)
 Overloaded assignment operator for other IP addresses. More...
 
SnmpSyntaxclone () const
 Clone this object. More...
 
char * friendly_name (int &status)
 Return the friendly name. More...
 
virtual const char * get_printable () const
 Get a printable ASCII value of the address. More...
 
virtual operator const char * () const
 Overloaded operator for streaming output. More...
 
void mask (const IpAddress &ipaddr)
 Logically AND the address with the param. More...
 
int get_match_bits (const IpAddress match_ip) const
 Get the count of matching bits from the left. More...
 
virtual int get_length () const
 Get the length of the binary address (accessible through operator[]). More...
 
virtual addr_type get_type () const
 Return the type of the address. More...
 
virtual SmiUINT32 get_syntax () const
 Return the syntax. More...
 
virtual int get_asn1_length () const
 Return the space needed for serialization. More...
 
virtual version_type get_ip_version () const
 Return the IP version of the address. More...
 
virtual bool map_to_ipv6 ()
 Map a IPv4 address to a IPv6 address. More...
 
virtual unsigned int get_scope () const
 Get the IPv6 scope. More...
 
virtual bool set_scope (const unsigned int scope)
 Set the IPv6 scope. More...
 
void clear ()
 Reset the object. More...
 
bool has_ipv6_scope () const
 
- Public Member Functions inherited from Address
 Address ()
 Default constructor, clears the buffer and sets valid flag to false. More...
 
virtual ~Address ()
 Allow destruction of derived classes. More...
 
virtual bool valid () const
 Return if the object contains a valid address. More...
 
unsigned char & operator[] (const int position)
 Access as an array (read and write). More...
 
unsigned char operator[] (const int position) const
 Access as an array (read only). More...
 
virtual Addressoperator= (const char *str)
 
virtual unsigned int hashFunction () const
 
- Public Member Functions inherited from SnmpSyntax
virtual ~SnmpSyntax ()
 Virtual destructor to ensure deletion of derived classes... More...
 

Protected Member Functions

virtual bool parse_address (const char *inaddr)
 
virtual void format_output () const
 
int parse_dotted_ipstring (const char *inaddr)
 
int parse_coloned_ipstring (const char *inaddr)
 
int addr_to_friendly ()
 
- Protected Member Functions inherited from Address
void trim_white_space (char *ptr)
 Trim of whitespaces at the start and the end of the string. More...
 
virtual bool is_gen_address () const
 Is this a GenAddress object. More...
 
- Protected Member Functions inherited from SnmpSyntax
 SnmpSyntax ()
 

Protected Attributes

SNMP_PP_MUTABLE char output_buffer [OUTBUFF]
 
char iv_friendly_name [MAX_FRIENDLY_NAME]
 
int iv_friendly_name_status
 
version_type ip_version
 
bool have_ipv6_scope
 
- Protected Attributes inherited from Address
SNMP_PP_MUTABLE bool addr_changed
 
bool valid_flag
 
unsigned char address_buffer [ADDRBUF]
 
- Protected Attributes inherited from SnmpSyntax
SmiVALUE smival
 

Additional Inherited Members

- Public Types inherited from Address
enum  addr_type {
  type_ip, type_ipx, type_udp, type_ipxsock,
  type_mac, type_invalid
}
 Type returned by Address::get_type(). More...
 
enum  version_type { version_ipv4, version_ipv6 }
 Type returned by IpAddress::get_ip_version() and UdpAddress::get_ip_version(). More...
 

Detailed Description

Definition at line 302 of file address.h.

Constructor & Destructor Documentation

IpAddress::IpAddress ( )

Construct an empty invalid IP address.

IpAddress::IpAddress ( const char *  inaddr)

Construct an IP address from a string.

The following formats can be used:

  • hostname with or without domain ("www.agentpp.com", "printsrv")
  • Numerical IPv4 address ("192.168.17.1")
  • Numerical IPv6 address ("abcd:1234::a:b:1", "::abcd:1")
  • Numerical IPv6 address with scope ("abcd:1234::a:b:1%3", "::abcd:1%1")
Parameters
inaddr- Hostname or IP address
IpAddress::IpAddress ( const IpAddress ipaddr)

Construct an IP address from another IP address.

Parameters
ipaddr- address to copy
IpAddress::IpAddress ( const GenAddress genaddr)

Construct an IP address from a GenAddress.

Parameters
genaddr- address to copy
IpAddress::~IpAddress ( )
inline

Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).

Definition at line 340 of file address.h.

Member Function Documentation

int IpAddress::addr_to_friendly ( )
protected
void IpAddress::clear ( )
virtual

Reset the object.

Reimplemented from Address.

Reimplemented in UdpAddress.

SnmpSyntax* IpAddress::clone ( ) const
inlinevirtual

Clone this object.

Returns
Pointer to the newly created object (allocated through new).

Implements SnmpSyntax.

Reimplemented in UdpAddress.

Definition at line 364 of file address.h.

virtual void IpAddress::format_output ( ) const
protectedvirtual

Implements Address.

Reimplemented in UdpAddress.

char* IpAddress::friendly_name ( int &  status)

Return the friendly name.

Does a reverse DNS lookup for the IP address.

Parameters
status- The errno value for the lookup
Returns
the friendly name or a zero length string (no null pointer)
virtual int IpAddress::get_asn1_length ( ) const
inlinevirtual

Return the space needed for serialization.

Implements Address.

Reimplemented in UdpAddress.

Definition at line 430 of file address.h.

virtual version_type IpAddress::get_ip_version ( ) const
inlinevirtual

Return the IP version of the address.

Returns
one of Address::version_type

Definition at line 438 of file address.h.

virtual int IpAddress::get_length ( ) const
inlinevirtual

Get the length of the binary address (accessible through operator[]).

Implements Address.

Reimplemented in UdpAddress.

Definition at line 409 of file address.h.

References IP6LEN_NO_SCOPE, IP6LEN_WITH_SCOPE, and IPLEN.

int IpAddress::get_match_bits ( const IpAddress  match_ip) const

Get the count of matching bits from the left.

Parameters
match_ip- address to match with
virtual const char* IpAddress::get_printable ( ) const
inlinevirtual

Get a printable ASCII value of the address.

Returns
String containing the numerical address

Implements SnmpSyntax.

Reimplemented in UdpAddress.

Definition at line 380 of file address.h.

virtual unsigned int IpAddress::get_scope ( ) const
virtual

Get the IPv6 scope.

virtual SmiUINT32 IpAddress::get_syntax ( ) const
inlinevirtual

Return the syntax.

Returns
This method always returns sNMP_SYNTAX_IPADDR.

Implements SnmpSyntax.

Reimplemented in UdpAddress.

Definition at line 425 of file address.h.

References sNMP_SYNTAX_IPADDR.

virtual addr_type IpAddress::get_type ( ) const
inlinevirtual

Return the type of the address.

See Also
Address::addr_type
Returns
Always Address:type_ip

Implements Address.

Reimplemented in UdpAddress.

Definition at line 418 of file address.h.

bool IpAddress::has_ipv6_scope ( ) const
inline

Definition at line 462 of file address.h.

virtual bool IpAddress::map_to_ipv6 ( )
virtual

Map a IPv4 address to a IPv6 address.

Returns
- TRUE if no error occured.

Reimplemented in UdpAddress.

void IpAddress::mask ( const IpAddress ipaddr)

Logically AND the address with the param.

Parameters
ipaddr- address to use as mask
virtual IpAddress::operator const char * ( ) const
inlinevirtual

Overloaded operator for streaming output.

Returns
String containing the numerical address

Implements Address.

Reimplemented in UdpAddress.

Definition at line 388 of file address.h.

virtual SnmpSyntax& IpAddress::operator= ( const SnmpSyntax val)
virtual

Map other SnmpSyntax objects to IpAddress.

Implements SnmpSyntax.

Reimplemented in UdpAddress.

virtual Address& IpAddress::operator= ( const Address val)
virtual

Map other Address objects to IpAddress.

Implements Address.

Reimplemented in UdpAddress.

virtual IpAddress& IpAddress::operator= ( const IpAddress ipaddress)
virtual

Overloaded assignment operator for other IP addresses.

Reimplemented in UdpAddress.

virtual bool IpAddress::parse_address ( const char *  inaddr)
protectedvirtual

Implements Address.

Reimplemented in UdpAddress.

int IpAddress::parse_coloned_ipstring ( const char *  inaddr)
protected
int IpAddress::parse_dotted_ipstring ( const char *  inaddr)
protected
virtual bool IpAddress::set_scope ( const unsigned int  scope)
virtual

Set the IPv6 scope.

Reimplemented in UdpAddress.

Member Data Documentation

bool IpAddress::have_ipv6_scope
protected

Definition at line 493 of file address.h.

version_type IpAddress::ip_version
protected

Definition at line 491 of file address.h.

char IpAddress::iv_friendly_name[MAX_FRIENDLY_NAME]
protected

Definition at line 469 of file address.h.

int IpAddress::iv_friendly_name_status
protected

Definition at line 470 of file address.h.

SNMP_PP_MUTABLE char IpAddress::output_buffer[OUTBUFF]
protected

Definition at line 466 of file address.h.


The documentation for this class was generated from the following file: