Public Types | Public Member Functions | Data Fields | Static Public Attributes

IpAddr Struct Reference

Storage for an IP address. More...

#include <ink_inet.h>

Collaboration diagram for IpAddr:
Collaboration graph
[legend]

Public Types

typedef IpAddr self
 Self reference type.

Public Member Functions

 IpAddr ()
 Default construct (invalid address).
 IpAddr (in_addr_t addr)
 Construct as IPv4 addr.
 IpAddr (in6_addr const &addr)
 Construct as IPv6 addr.
 IpAddr (sockaddr const *addr)
 Construct from sockaddr.
 IpAddr (sockaddr_in6 const &addr)
 Construct from sockaddr_in6.
 IpAddr (sockaddr_in6 const *addr)
 Construct from sockaddr_in6.
 IpAddr (IpEndpoint const &addr)
 Construct from IpEndpoint.
 IpAddr (IpEndpoint const *addr)
 Construct from IpEndpoint.
selfoperator= (IpEndpoint const &ip)
 Assign from end point.
int load (char const *str)
 Load from string.
char * toString (char *dest, size_t len) const
 Output to a string.
bool operator== (self const &that) const
 Equality.
bool operator!= (self const &that)
 Inequality.
bool isValid () const
 Test for validity.
selfinvalidate ()
 Make invalid.
bool isMulticast () const
 Test for multicast.
is passed to @c getaddrinfo which does a host lookup if @a

Get the best address info for name.

name is not in IP address format. The results are examined for the "best" addresses. This is only significant for the host name case (for IP address data, there is at most one result). The preference is Global > Non-Routable > Multicast > Loopback.

IPv4 and IPv4 results are handled independently and stored in ip4 and ip6 respectively. If name is known to be a numeric IP address ats_ip_pton is a better choice. Use this function if the type of name is not known. If you want to look at the addresses and not just get the "best", use getaddrinfo directly.

ip4 or ip6 can be NULL and the result for that family is discarded. It is legal for both to be NULL in which case this is just a format check.

Returns:
0 if an address was found, non-zero otherwise.
See also:
ats_ip_pton
getaddrinfo
selfassign (sockaddr const *addr)
 Assign sockaddr storage.
selfoperator= (in_addr_t ip)
 Assign from IPv4 raw address.
selfoperator= (in6_addr const &ip)
 Assign from IPv6 raw address.
bool isCompatibleWith (self const &that)
 Test for same address family.
uint16_t family () const
 Get the address family.
bool isIp4 () const
 Test for IPv4.
bool isIp6 () const
 Test for IPv6.

Data Fields

uint16_t _family
 Protocol family.
union {
   in_addr_t   _ip4
 IPv4 address storage.
   in6_addr   _ip6
 IPv6 address storage.
   uint8_t   _byte [TS_IP6_SIZE]
 As raw bytes.
_addr
 Address data.

Static Public Attributes

static self const INVALID

Detailed Description

Storage for an IP address.

In some cases we want to store just the address and not the ancillary information (such as port, or flow data).

Note:
This is not easily used as an address for system calls.

Definition at line 1052 of file ink_inet.h.


Member Typedef Documentation

Self reference type.

Definition at line 1053 of file ink_inet.h.


Constructor & Destructor Documentation

IpAddr::IpAddr (  )  [inline]

Default construct (invalid address).

Definition at line 1056 of file ink_inet.h.

IpAddr::IpAddr ( in_addr_t  addr  )  [inline, explicit]

Construct as IPv4 addr.

Parameters:
addr Address to assign.

Definition at line 1058 of file ink_inet.h.

References _addr.

IpAddr::IpAddr ( in6_addr const &  addr  )  [inline, explicit]

Construct as IPv6 addr.

Parameters:
addr Address to assign.

Definition at line 1064 of file ink_inet.h.

References _addr.

IpAddr::IpAddr ( sockaddr const *  addr  )  [inline, explicit]

Construct from sockaddr.

Definition at line 1070 of file ink_inet.h.

References assign().

IpAddr::IpAddr ( sockaddr_in6 const &  addr  )  [inline, explicit]

Construct from sockaddr_in6.

Definition at line 1072 of file ink_inet.h.

References assign(), and ats_ip_sa_cast().

IpAddr::IpAddr ( sockaddr_in6 const *  addr  )  [inline, explicit]

Construct from sockaddr_in6.

Definition at line 1074 of file ink_inet.h.

References assign(), and ats_ip_sa_cast().

IpAddr::IpAddr ( IpEndpoint const &  addr  )  [inline, explicit]

Construct from IpEndpoint.

Definition at line 1076 of file ink_inet.h.

References assign(), and IpEndpoint::sa.

IpAddr::IpAddr ( IpEndpoint const *  addr  )  [inline, explicit]

Construct from IpEndpoint.

Definition at line 1078 of file ink_inet.h.

References assign(), and IpEndpoint::sa.


Member Function Documentation

IpAddr & IpAddr::assign ( sockaddr const *  addr  )  [inline]
uint16_t IpAddr::family (  )  const [inline]

Get the address family.

Returns:
The address family.

Definition at line 1176 of file ink_inet.h.

References _family.

Referenced by Ink_Inet(), Connection::open(), and HttpProxyPort::processOptions().

self& IpAddr::invalidate (  )  [inline]
bool IpAddr::isCompatibleWith ( self const &  that  )  [inline]

Test for same address family.

return true if that is the same address family as this.

Definition at line 1179 of file ink_inet.h.

References _family, and isValid().

bool IpAddr::isIp4 (  )  const [inline]

Test for IPv4.

Definition at line 1183 of file ink_inet.h.

References _family.

Referenced by DNSEntry::init(), make_net_accept_options(), and detail::HttpSessionAcceptOptions::setOutboundIp().

bool IpAddr::isIp6 (  )  const [inline]
bool IpAddr::isMulticast (  )  const

Test for multicast.

Definition at line 350 of file ink_inet.cc.

References _addr, and _family.

bool IpAddr::isValid (  )  const [inline]
int IpAddr::load ( char const *  str  ) 

Load from string.

The address is copied to this object if the conversion is successful, otherwise this object is invalidated.

Returns:
0 on success, non-zero on failure.
Parameters:
str Nul terminated input string.

Definition at line 334 of file ink_inet.cc.

References ats_ip_pton().

Referenced by ats_ip_pton(), HostDBContinuation::do_dns(), ICPConfiguration::icp_config_change_callback(), Ink_Inet(), LogFilterIP::LogFilterIP(), HttpProxyPort::processOptions(), and LogHost::set_ipstr_port().

bool IpAddr::operator!= ( self const &  that  )  [inline]

Inequality.

Definition at line 1127 of file ink_inet.h.

IpAddr & IpAddr::operator= ( in6_addr const &  ip  )  [inline]

Assign from IPv6 raw address.

Definition at line 1170 of file ink_inet.h.

References _addr, and _family.

self& IpAddr::operator= ( IpEndpoint const &  ip  )  [inline]

Assign from end point.

Definition at line 1086 of file ink_inet.h.

References assign(), and IpEndpoint::sa.

IpAddr & IpAddr::operator= ( in_addr_t  ip  )  [inline]

Assign from IPv4 raw address.

Parameters:
ip Network order IPv4 address.

Definition at line 1163 of file ink_inet.h.

References _addr, and _family.

bool IpAddr::operator== ( self const &  that  )  const [inline]

Equality.

Definition at line 1115 of file ink_inet.h.

References _addr, _family, and TS_IP6_SIZE.

char * IpAddr::toString ( char *  dest,
size_t  len 
) const

Output to a string.

Returns:
The string dest.
Parameters:
[out] dest Destination string buffer.
[in] len Size of buffer.

Definition at line 342 of file ink_inet.cc.

References IpEndpoint::assign(), and ats_ip_ntop().

Referenced by UnixNetVConnection::connectUp(), HostDBContinuation::do_dns(), HostDBContinuation::lookup_done(), HttpProxyPort::print(), remove_round_robin(), and LogCollationClientSM::send().


Field Documentation

union { ... } IpAddr::_addr

Address data.

Pre-constructed invalid instance.

Referenced by assign(), ats_ip_set(), DNSEntry::init(), Ink_Inet(), IpAddr(), isMulticast(), operator=(), operator==(), operator==(), and HostDBMD5::refresh().

As raw bytes.

Definition at line 1155 of file ink_inet.h.

Referenced by HostDBMD5::refresh().

uint16_t IpAddr::_family
in_addr_t IpAddr::_ip4

IPv4 address storage.

Definition at line 1153 of file ink_inet.h.

Referenced by ats_ip_set(), DNSEntry::init(), Ink_Inet(), and operator==().

in6_addr IpAddr::_ip6

IPv6 address storage.

Definition at line 1154 of file ink_inet.h.

Referenced by ats_ip_set(), DNSEntry::init(), Ink_Inet(), and operator==().

IpAddr const IpAddr::INVALID [static]

Definition at line 1159 of file ink_inet.h.


The documentation for this struct was generated from the following files: