SNMP++  3.3.11
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...
 
const 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 int get_inet_address_type () const
 Get the InetAddressType value for this address. More...
 
virtual addr_type get_type () const
 Return the type of the address. More...
 
virtual SmiUINT32 get_syntax () const
 Return the syntax. More...
 
virtual OctetStrclone_as_hex () const
 Return clone as binary string. 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
 
virtual Addressoperator= (const Address &val)=0
 Overloaded assignment operator. More...
 
virtual Addressoperator= (const char *str)
 
virtual SnmpSyntaxoperator= (const SnmpSyntax &val)=0
 Overloaded assignment operator. More...
 
- 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
 
virtual SnmpSyntaxoperator= (const SnmpSyntax &val)=0
 Overloaded assignment operator. More...
 
- 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]
 
std::string iv_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...
 
enum  InetAddressType {
  e_unknown = 0, e_ipv4 = 1, e_ipv6 = 2, e_ipv4z = 3,
  e_ipv6z = 4, e_dns = 16
}
 Type returned by Address::get_inet_address_type() More...
 

Detailed Description

Definition at line 315 of file address.h.

Constructor & Destructor Documentation

◆ IpAddress() [1/4]

IpAddress::IpAddress ( )

Construct an empty invalid IP address.

◆ IpAddress() [2/4]

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() [3/4]

IpAddress::IpAddress ( const IpAddress ipaddr)

Construct an IP address from another IP address.

Parameters
ipaddr- address to copy

◆ IpAddress() [4/4]

IpAddress::IpAddress ( const GenAddress genaddr)

Construct an IP address from a GenAddress.

Parameters
genaddr- address to copy

◆ ~IpAddress()

IpAddress::~IpAddress ( )
inline

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

Definition at line 353 of file address.h.

Member Function Documentation

◆ addr_to_friendly()

int IpAddress::addr_to_friendly ( )
protected

◆ clear()

void IpAddress::clear ( )
virtual

Reset the object.

Reimplemented from Address.

Reimplemented in UdpAddress.

◆ clone()

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 377 of file address.h.

◆ clone_as_hex()

virtual OctetStr* IpAddress::clone_as_hex ( ) const
virtual

Return clone as binary string.

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

◆ format_output()

virtual void IpAddress::format_output ( ) const
protectedvirtual

Implements Address.

Reimplemented in UdpAddress.

◆ friendly_name()

const 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)

◆ get_asn1_length()

virtual int IpAddress::get_asn1_length ( ) const
inlinevirtual

Return the space needed for serialization.

Implements Address.

Reimplemented in UdpAddress.

Definition at line 457 of file address.h.

◆ get_inet_address_type()

virtual int IpAddress::get_inet_address_type ( ) const
inlinevirtual

Get the InetAddressType value for this address.

Definition at line 429 of file address.h.

◆ get_ip_version()

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 465 of file address.h.

◆ get_length()

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 422 of file address.h.

References IP6LEN_NO_SCOPE, IP6LEN_WITH_SCOPE, and IPLEN.

◆ get_match_bits()

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

◆ get_printable()

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 393 of file address.h.

◆ get_scope()

virtual unsigned int IpAddress::get_scope ( ) const
virtual

Get the IPv6 scope.

◆ get_syntax()

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 445 of file address.h.

References sNMP_SYNTAX_IPADDR.

◆ get_type()

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 438 of file address.h.

◆ has_ipv6_scope()

bool IpAddress::has_ipv6_scope ( ) const
inline

Definition at line 489 of file address.h.

◆ map_to_ipv6()

virtual bool IpAddress::map_to_ipv6 ( )
virtual

Map a IPv4 address to a IPv6 address.

Returns
- TRUE if no error occured.

Reimplemented in UdpAddress.

◆ mask()

void IpAddress::mask ( const IpAddress ipaddr)

Logically AND the address with the param.

Parameters
ipaddr- address to use as mask

◆ operator const char *()

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 401 of file address.h.

◆ operator=() [1/6]

virtual SnmpSyntax& SnmpSyntax::operator=

Overloaded assignment operator.

◆ operator=() [2/6]

virtual Address& Address::operator=
inline

Definition at line 275 of file address.h.

◆ operator=() [3/6]

virtual Address& Address::operator=

Overloaded assignment operator.

◆ operator=() [4/6]

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

Map other SnmpSyntax objects to IpAddress.

Implements SnmpSyntax.

Reimplemented in UdpAddress.

◆ operator=() [5/6]

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

Map other Address objects to IpAddress.

Implements Address.

Reimplemented in UdpAddress.

◆ operator=() [6/6]

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

Overloaded assignment operator for other IP addresses.

Reimplemented in UdpAddress.

◆ parse_address()

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

Implements Address.

Reimplemented in UdpAddress.

◆ parse_coloned_ipstring()

int IpAddress::parse_coloned_ipstring ( const char *  inaddr)
protected

◆ parse_dotted_ipstring()

int IpAddress::parse_dotted_ipstring ( const char *  inaddr)
protected

◆ set_scope()

virtual bool IpAddress::set_scope ( const unsigned int  scope)
virtual

Set the IPv6 scope.

Reimplemented in UdpAddress.

Member Data Documentation

◆ have_ipv6_scope

bool IpAddress::have_ipv6_scope
protected

Definition at line 520 of file address.h.

◆ ip_version

version_type IpAddress::ip_version
protected

Definition at line 518 of file address.h.

◆ iv_friendly_name

std::string IpAddress::iv_friendly_name
protected

Definition at line 496 of file address.h.

◆ iv_friendly_name_status

int IpAddress::iv_friendly_name_status
protected

Definition at line 497 of file address.h.

◆ output_buffer

SNMP_PP_MUTABLE char IpAddress::output_buffer[OUTBUFF]
protected

Definition at line 493 of file address.h.


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