Data Structures | Defines | Typedefs | Functions | Variables

ink_inet.h File Reference

A brief file description. More...

#include <netinet/in.h>
#include <netdb.h>
#include <ink_memory.h>
#include <sys/socket.h>
#include <ts/ink_apidefs.h>
#include <ts/TsBuffer.h>
Include dependency graph for ink_inet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  IpEndpoint
 A union to hold the standard IP address structures. More...
struct  ink_gethostbyname_r_data
struct  ink_gethostbyaddr_r_data
struct  IpAddr
 Storage for an IP address. More...

Defines

#define INK_GETHOSTBYNAME_R_DATA_SIZE   1024
#define INK_GETHOSTBYADDR_R_DATA_SIZE   1024

Typedefs

typedef char ip_text_buffer [INET6_ADDRSTRLEN]
 Convenience type for address formatting.
typedef char ip_port_text_buffer [INET6_ADDRPORTSTRLEN]
 Convenience type for address formatting.

Functions

struct hostent * ink_gethostbyname_r (char *hostname, ink_gethostbyname_r_data *data)
 Wrapper for gethostbyname_r().
struct hostent * ink_gethostbyaddr_r (char *ip, int len, int type, ink_gethostbyaddr_r_data *data)
 Wrapper for gethostbyaddr_r().
int ats_ip_parse (ts::ConstBuffer src, ts::ConstBuffer *addr, ts::ConstBuffer *port)
 Parse a string for pieces of an IP address.
int ats_ip_check_characters (ts::ConstBuffer text)
 Check to see if a buffer contains only IP address characters.
inkcoreapi uint32_t ats_inet_addr (const char *s)
 Wrapper for inet_addr().
const char * ats_ip_ntop (const struct sockaddr *addr, char *dst, size_t size)
void ats_ip_invalidate (sockaddr *addr)
 Reset an address to invalid.
void ats_ip_invalidate (sockaddr_in6 *addr)
void ats_ip_invalidate (IpEndpoint *ip)
char const * ats_ip_family_name (int family)
 Get a string name for an IP address family.
bool ats_is_ip (sockaddr const *addr)
 Test for IP protocol.
bool ats_is_ip (IpEndpoint const *addr)
bool ats_is_ip (int family)
 Test for IP protocol.
bool ats_is_ip4 (sockaddr const *addr)
 Test for IPv4 protocol.
bool ats_is_ip4 (IpEndpoint const *addr)
 Test for IPv4 protocol.
bool ats_is_ip6 (sockaddr const *addr)
 Test for IPv6 protocol.
bool ats_is_ip6 (IpEndpoint const *addr)
 Test for IPv6 protocol.
bool ats_ip_are_compatible (sockaddr const *lhs, sockaddr const *rhs)
bool ats_ip_are_compatible (IpEndpoint const *lhs, IpEndpoint const *rhs)
bool ats_ip_are_compatible (int lhs, sockaddr const *rhs)
bool ats_ip_are_compatible (sockaddr const *lhs, int rhs)
sockaddr * ats_ip_sa_cast (sockaddr_storage *a)
sockaddr const * ats_ip_sa_cast (sockaddr_storage const *a)
sockaddr * ats_ip_sa_cast (sockaddr_in *a)
sockaddr const * ats_ip_sa_cast (sockaddr_in const *a)
sockaddr * ats_ip_sa_cast (sockaddr_in6 *a)
sockaddr const * ats_ip_sa_cast (sockaddr_in6 const *a)
sockaddr_storage * ats_ip_ss_cast (sockaddr *a)
sockaddr_storage const * ats_ip_ss_cast (sockaddr const *a)
sockaddr_in * ats_ip4_cast (sockaddr *a)
sockaddr_in const * ats_ip4_cast (sockaddr const *a)
sockaddr_in & ats_ip4_cast (sockaddr &a)
sockaddr_in const & ats_ip4_cast (sockaddr const &a)
sockaddr_in * ats_ip4_cast (sockaddr_in6 *a)
sockaddr_in const * ats_ip4_cast (sockaddr_in6 const *a)
sockaddr_in & ats_ip4_cast (sockaddr_in6 &a)
sockaddr_in const & ats_ip4_cast (sockaddr_in6 const &a)
sockaddr_in6 * ats_ip6_cast (sockaddr *a)
sockaddr_in6 const * ats_ip6_cast (sockaddr const *a)
sockaddr_in6 & ats_ip6_cast (sockaddr &a)
sockaddr_in6 const & ats_ip6_cast (sockaddr const &a)
size_t ats_ip_size (sockaddr const *addr)
size_t ats_ip_size (IpEndpoint const *addr)
size_t ats_ip_addr_size (sockaddr const *addr)
size_t ats_ip_addr_size (IpEndpoint const *addr)
in_port_t & ats_ip_port_cast (sockaddr *sa)
 Get a reference to the port in an address.
in_port_t const & ats_ip_port_cast (sockaddr const *sa)
in_port_t const & ats_ip_port_cast (IpEndpoint const *ip)
in_port_t & ats_ip_port_cast (IpEndpoint *ip)
in_addr_t & ats_ip4_addr_cast (sockaddr *addr)
 Access the IPv4 address.
in_addr_t const & ats_ip4_addr_cast (sockaddr const *addr)
 Access the IPv4 address.
in_addr_t & ats_ip4_addr_cast (IpEndpoint *ip)
 Access the IPv4 address.
in_addr_t const & ats_ip4_addr_cast (IpEndpoint const *ip)
 Access the IPv4 address.
in6_addr & ats_ip6_addr_cast (sockaddr *addr)
 Access the IPv6 address.
in6_addr const & ats_ip6_addr_cast (sockaddr const *addr)
in6_addr & ats_ip6_addr_cast (IpEndpoint *ip)
in6_addr const & ats_ip6_addr_cast (IpEndpoint const *ip)
uint32_t * ats_ip_addr32_cast (sockaddr *addr)
 Cast an IP address to an array of uint32_t.
uint32_t const * ats_ip_addr32_cast (sockaddr const *addr)
uint8_t * ats_ip_addr8_cast (sockaddr *addr)
 Cast an IP address to an array of uint8_t.
uint8_t const * ats_ip_addr8_cast (sockaddr const *addr)
uint8_t * ats_ip_addr8_cast (IpEndpoint *ip)
uint8_t const * ats_ip_addr8_cast (IpEndpoint const *ip)
bool ats_is_ip_loopback (sockaddr const *ip)
 Check for loopback.
bool ats_is_ip_loopback (IpEndpoint const *ip)
 Check for loopback.
bool ats_is_ip_multicast (sockaddr const *ip)
 Check for multicast.
bool ats_is_ip_multicast (IpEndpoint const *ip)
 Check for multicast.
bool ats_is_ip_private (sockaddr const *ip)
 Check for Private.
bool ats_is_ip_private (IpEndpoint const *ip)
 Check for Private.
bool ats_is_ip_linklocal (sockaddr const *ip)
 Check for Link Local.
bool ats_is_ip_linklocal (IpEndpoint const *ip)
 Check for Link Local.
bool ats_is_ip_any (sockaddr const *ip)
 Check for being "any" address.
in_port_t ats_ip_port_host_order (sockaddr const *addr)
 Get IP TCP/UDP port.
in_port_t ats_ip_port_host_order (IpEndpoint const *ip)
 Get IP TCP/UDP port.
in_addr_t ats_ip4_addr_host_order (sockaddr const *addr)
 Extract the IPv4 address.
sockaddr * ats_ip4_set (sockaddr_in *dst, in_addr_t addr, in_port_t port=0)
 Write IPv4 data to storage dst.
sockaddr * ats_ip4_set (IpEndpoint *dst, in_addr_t ip4, in_port_t port=0)
 Write IPv4 data to dst.
sockaddr * ats_ip4_set (sockaddr *dst, in_addr_t ip4, in_port_t port=0)
 Write IPv4 data to storage dst.
sockaddr * ats_ip6_set (sockaddr_in6 *dst, in6_addr const &addr, in_port_t port=0)
 Write IPv6 data to storage dst.
sockaddr * ats_ip6_set (sockaddr *dst, in6_addr const &addr, in_port_t port=0)
 Write IPv6 data to storage dst.
sockaddr * ats_ip6_set (IpEndpoint *dst, in6_addr const &addr, in_port_t port=0)
 Write IPv6 data to storage dst.
char const * ats_ip_ntop (const sockaddr *addr, char *dst, size_t size)
 Write a null terminated string for addr to dst.
char const * ats_ip_ntop (IpEndpoint const *addr, char *dst, size_t size)
 Write a null terminated string for addr to dst.
char const * ats_ip_nptop (const sockaddr *addr, char *dst, size_t size)
 Write a null terminated string for addr to dst with port.
char const * ats_ip_nptop (IpEndpoint const *addr, char *dst, size_t size)
 Write a null terminated string for addr to dst with port.
int ats_ip_pton (const ts::ConstBuffer &text, sockaddr *addr)
 Convert text to an IP address and write it to addr.
int ats_ip_pton (char const *text, sockaddr_in6 *addr)
 Convert text to an IP address and write it to addr.
int ats_ip_pton (const ts::ConstBuffer &text, IpEndpoint *addr)
int ats_ip_pton (const char *text, IpEndpoint *addr)
int ats_ip_pton (const char *text, sockaddr *addr)
Address operators

bool ats_ip_copy (sockaddr *dst, sockaddr const *src)
 Copy the address from src to dst if it's IP.
bool ats_ip_copy (IpEndpoint *dst, sockaddr const *src)
bool ats_ip_copy (IpEndpoint *dst, IpEndpoint const *src)
bool ats_ip_copy (sockaddr *dst, IpEndpoint const *src)
int ats_ip_addr_cmp (sockaddr const *lhs, sockaddr const *rhs)
 Compare two addresses.
int ats_ip_addr_cmp (IpEndpoint const *lhs, IpEndpoint const *rhs)
 Compare two addresses.
bool ats_ip_addr_eq (sockaddr const *lhs, sockaddr const *rhs)
 Check if two addresses are equal.
bool ats_ip_addr_eq (IpEndpoint const *lhs, IpEndpoint const *rhs)
bool operator== (IpEndpoint const &lhs, IpEndpoint const &rhs)
bool operator!= (IpEndpoint const &lhs, IpEndpoint const &rhs)
bool ats_ip_addr_port_eq (sockaddr const *lhs, sockaddr const *rhs)
 Compare address and port for equality.
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
int ats_ip_getbestaddrinfo (char const *name, IpEndpoint *ip4, IpEndpoint *ip6)
uint32_t ats_ip_hash (sockaddr const *addr)
 Generic IP address hash function.
int ats_ip_to_hex (sockaddr const *addr, char *dst, size_t len)
 Convert address to string as a hexidecimal value.
bool operator== (IpAddr const &lhs, sockaddr const *rhs)
bool operator== (sockaddr const *lhs, IpAddr const &rhs)
bool operator!= (IpAddr const &lhs, sockaddr const *rhs)
bool operator!= (sockaddr const *lhs, IpAddr const &rhs)
bool operator== (IpAddr const &lhs, IpEndpoint const &rhs)
bool operator== (IpEndpoint const &lhs, IpAddr const &rhs)
bool operator!= (IpAddr const &lhs, IpEndpoint const &rhs)
bool operator!= (IpEndpoint const &lhs, IpAddr const &rhs)
sockaddr * ats_ip_set (sockaddr *dst, IpAddr const &addr, in_port_t port=0)
 Write IP addr to storage dst.
int ats_ip_pton (char const *text, IpAddr &addr)
 Convert text to an IP address and write it to addr.

Variables

static size_t const TS_IP6_SIZE = sizeof(in6_addr)
 Size in bytes of an IPv6 address.
static size_t const INET6_ADDRPORTSTRLEN = INET6_ADDRSTRLEN + 6
 Buffer size sufficient for IPv6 address and port.

Detailed Description

A brief file description.

License

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file ink_inet.h.


Define Documentation

#define INK_GETHOSTBYADDR_R_DATA_SIZE   1024

Definition at line 36 of file ink_inet.h.

#define INK_GETHOSTBYNAME_R_DATA_SIZE   1024

Definition at line 35 of file ink_inet.h.


Typedef Documentation

Convenience type for address formatting.

Definition at line 916 of file ink_inet.h.

typedef char ip_text_buffer[INET6_ADDRSTRLEN]

Convenience type for address formatting.

Definition at line 914 of file ink_inet.h.


Function Documentation

inkcoreapi uint32_t ats_inet_addr ( const char *  s  ) 

Wrapper for inet_addr().

Parameters:
s IP address in the Internet standard dot notation.
in_addr_t& ats_ip4_addr_cast ( sockaddr *  addr  )  [inline]
in_addr_t const& ats_ip4_addr_cast ( sockaddr const *  addr  )  [inline]

Access the IPv4 address.

If this is not an IPv4 address a zero valued address is returned.

Note:
This is direct access to the address so it will be in network order.
Returns:
A reference to the IPv4 address in addr.

Definition at line 440 of file ink_inet.h.

References ats_ip4_cast(), and ats_is_ip4().

in_addr_t& ats_ip4_addr_cast ( IpEndpoint ip  )  [inline]

Access the IPv4 address.

If this is not an IPv4 address a zero valued address is returned.

Note:
This is direct access to the address so it will be in network order.
Convenience overload.
Returns:
A reference to the IPv4 address in addr.

Definition at line 457 of file ink_inet.h.

References ats_ip4_addr_cast(), and IpEndpoint::sa.

in_addr_t const& ats_ip4_addr_cast ( IpEndpoint const *  ip  )  [inline]

Access the IPv4 address.

If this is not an IPv4 address a zero valued address is returned.

Note:
This is direct access to the address so it will be in network order.
Convenience overload.
Returns:
A reference to the IPv4 address in addr.

Definition at line 470 of file ink_inet.h.

References ats_ip4_addr_cast(), and IpEndpoint::sa.

in_addr_t ats_ip4_addr_host_order ( sockaddr const *  addr  )  [inline]

Extract the IPv4 address.

Returns:
Host order IPv4 address.
Parameters:
addr Address object.

Definition at line 808 of file ink_inet.h.

References ats_ip4_addr_cast().

sockaddr_in const& ats_ip4_cast ( sockaddr const &  a  )  [inline]

Definition at line 324 of file ink_inet.h.

sockaddr_in* ats_ip4_cast ( sockaddr_in6 *  a  )  [inline]

Definition at line 328 of file ink_inet.h.

sockaddr_in const* ats_ip4_cast ( sockaddr_in6 const *  a  )  [inline]

Definition at line 331 of file ink_inet.h.

sockaddr_in& ats_ip4_cast ( sockaddr_in6 &  a  )  [inline]

Definition at line 335 of file ink_inet.h.

sockaddr_in const& ats_ip4_cast ( sockaddr_in6 const &  a  )  [inline]

Definition at line 338 of file ink_inet.h.

sockaddr_in& ats_ip4_cast ( sockaddr &  a  )  [inline]

Definition at line 321 of file ink_inet.h.

sockaddr_in* ats_ip4_cast ( sockaddr *  a  )  [inline]
sockaddr_in const* ats_ip4_cast ( sockaddr const *  a  )  [inline]

Definition at line 317 of file ink_inet.h.

sockaddr* ats_ip4_set ( sockaddr_in *  dst,
in_addr_t  addr,
in_port_t  port = 0 
) [inline]
sockaddr* ats_ip4_set ( IpEndpoint dst,
in_addr_t  ip4,
in_port_t  port = 0 
) [inline]

Write IPv4 data to dst.

Note:
Convenience overload.
Parameters:
dst Destination storage.
ip4 address, IPv4 network order.
port port, network order.

Definition at line 833 of file ink_inet.h.

References ats_ip4_set(), and IpEndpoint::sin.

sockaddr* ats_ip4_set ( sockaddr *  dst,
in_addr_t  ip4,
in_port_t  port = 0 
) [inline]

Write IPv4 data to storage dst.

This is the generic overload. Caller must verify that dst is at least sizeof(sockaddr_in) bytes.

Parameters:
dst Destination storage.
ip4 address, IPv4 network order.
port port, network order.

Definition at line 846 of file ink_inet.h.

References ats_ip4_cast(), and ats_ip4_set().

in6_addr& ats_ip6_addr_cast ( sockaddr *  addr  )  [inline]

Access the IPv6 address.

If this is not an IPv6 address a zero valued address is returned.

Note:
This is direct access to the address so it will be in network order.
Returns:
A reference to the IPv6 address in addr.

Definition at line 482 of file ink_inet.h.

References ats_ip6_cast().

Referenced by IpAddr::assign(), ats_ip_addr32_cast(), ats_ip_addr8_cast(), ats_ip_ntop(), ats_is_ip_any(), ats_is_ip_linklocal(), ats_is_ip_loopback(), ats_is_ip_multicast(), ats_is_ip_private(), LogAccess::marshal_ip(), and operator==().

in6_addr const& ats_ip6_addr_cast ( sockaddr const *  addr  )  [inline]

Definition at line 485 of file ink_inet.h.

References ats_ip6_cast().

in6_addr& ats_ip6_addr_cast ( IpEndpoint ip  )  [inline]

Definition at line 488 of file ink_inet.h.

References IpEndpoint::sin6.

in6_addr const& ats_ip6_addr_cast ( IpEndpoint const *  ip  )  [inline]

Definition at line 491 of file ink_inet.h.

References IpEndpoint::sin6.

sockaddr_in6* ats_ip6_cast ( sockaddr *  a  )  [inline]
sockaddr_in6 const* ats_ip6_cast ( sockaddr const *  a  )  [inline]

Definition at line 345 of file ink_inet.h.

sockaddr_in6& ats_ip6_cast ( sockaddr &  a  )  [inline]

Definition at line 348 of file ink_inet.h.

sockaddr_in6 const& ats_ip6_cast ( sockaddr const &  a  )  [inline]

Definition at line 351 of file ink_inet.h.

sockaddr* ats_ip6_set ( sockaddr_in6 *  dst,
in6_addr const &  addr,
in_port_t  port = 0 
) [inline]

Write IPv6 data to storage dst.

Returns:
dst cast to sockaddr*.
Parameters:
dst Destination storage.
addr address in network order.
port Port, network order.

Definition at line 856 of file ink_inet.h.

References ats_ip_sa_cast(), and memcpy.

Referenced by ats_ip6_set(), ats_ip_pton(), ats_ip_set(), ip_addr_set(), and LogAccess::unmarshal_ip().

sockaddr* ats_ip6_set ( sockaddr *  dst,
in6_addr const &  addr,
in_port_t  port = 0 
) [inline]

Write IPv6 data to storage dst.

Returns:
dst cast to sockaddr*.
Parameters:
dst Destination storage.
addr address in network order.
port Port, network order.

Definition at line 873 of file ink_inet.h.

References ats_ip6_cast(), and ats_ip6_set().

sockaddr* ats_ip6_set ( IpEndpoint dst,
in6_addr const &  addr,
in_port_t  port = 0 
) [inline]

Write IPv6 data to storage dst.

Returns:
dst cast to sockaddr*.
Parameters:
dst Destination storage.
addr address in network order.
port Port, network order.

Definition at line 883 of file ink_inet.h.

References ats_ip6_set(), and IpEndpoint::sin6.

uint32_t* ats_ip_addr32_cast ( sockaddr *  addr  )  [inline]

Cast an IP address to an array of uint32_t.

Note:
The size of the array is dependent on the address type which must be checked independently of this function.
Returns:
A pointer to the address information in addr or NULL if addr is not an IP address.

Definition at line 501 of file ink_inet.h.

References ats_ip4_addr_cast(), and ats_ip6_addr_cast().

Referenced by ats_ip_addr32_cast(), and HOSTDB_CLIENT_IP_HASH().

uint32_t const* ats_ip_addr32_cast ( sockaddr const *  addr  )  [inline]

Definition at line 509 of file ink_inet.h.

References ats_ip_addr32_cast().

uint8_t* ats_ip_addr8_cast ( sockaddr *  addr  )  [inline]

Cast an IP address to an array of uint8_t.

Note:
The size of the array is dependent on the address type which must be checked independently of this function.
Returns:
A pointer to the address information in addr or NULL if addr is not an IP address.
See also:
ats_ip_addr_size

Definition at line 520 of file ink_inet.h.

References ats_ip4_addr_cast(), and ats_ip6_addr_cast().

Referenced by ats_ip_addr8_cast(), ats_ip_hash(), ats_ip_to_hex(), ats_is_ip_loopback(), ats_is_ip_multicast(), and make_key().

uint8_t const* ats_ip_addr8_cast ( sockaddr const *  addr  )  [inline]

Definition at line 528 of file ink_inet.h.

References ats_ip_addr8_cast().

uint8_t* ats_ip_addr8_cast ( IpEndpoint ip  )  [inline]

Definition at line 531 of file ink_inet.h.

References ats_ip_addr8_cast(), and IpEndpoint::sa.

uint8_t const* ats_ip_addr8_cast ( IpEndpoint const *  ip  )  [inline]

Definition at line 534 of file ink_inet.h.

References ats_ip_addr8_cast(), and IpEndpoint::sa.

int ats_ip_addr_cmp ( sockaddr const *  lhs,
sockaddr const *  rhs 
) [inline]

Compare two addresses.

This is useful for IPv4, IPv6, and the unspecified address type. If the addresses are of different types they are ordered

Non-IP < IPv4 < IPv6

  • all non-IP addresses are the same ( including AF_UNSPEC )
  • IPv4 addresses are compared numerically (host order)
  • IPv6 addresses are compared byte wise in network order (MSB to LSB)
Returns:
  • -1 if lhs is less than rhs.
  • 0 if lhs is identical to rhs.
  • 1 if lhs is greater than rhs.
Parameters:
lhs Left hand operand.
rhs Right hand operand.

Definition at line 698 of file ink_inet.h.

References ats_ip4_cast(), and ats_ip6_cast().

Referenced by ats_ip_addr_cmp(), ats_ip_addr_eq(), src_ip_info_t::contains(), ExtractIpRange(), PeerConfigData::GetHostIPByName(), HttpTransact::HandleICPLookup(), IpMap_Fill(), operator!=(), operator==(), and IpAllow::Print().

int ats_ip_addr_cmp ( IpEndpoint const *  lhs,
IpEndpoint const *  rhs 
) [inline]

Compare two addresses.

Note:
Convenience overload.
See also:
ats_ip_addr_cmp(sockaddr const* lhs, sockaddr const* rhs)

Definition at line 746 of file ink_inet.h.

References ats_ip_addr_cmp(), and IpEndpoint::sa.

bool ats_ip_addr_eq ( sockaddr const *  lhs,
sockaddr const *  rhs 
) [inline]
bool ats_ip_addr_eq ( IpEndpoint const *  lhs,
IpEndpoint const *  rhs 
) [inline]

Definition at line 757 of file ink_inet.h.

References ats_ip_addr_cmp(), and IpEndpoint::sa.

bool ats_ip_addr_port_eq ( sockaddr const *  lhs,
sockaddr const *  rhs 
) [inline]

Compare address and port for equality.

Definition at line 769 of file ink_inet.h.

References ats_ip4_cast(), ats_ip6_cast(), and ats_ip_port_cast().

Referenced by HttpSM::do_http_server_open(), ServerSessionPool::IPHashing::equal(), and ServerSessionPool::match().

size_t ats_ip_addr_size ( sockaddr const *  addr  )  [inline]
Returns:
The size of the IP address only.
Parameters:
addr Address object.

Definition at line 373 of file ink_inet.h.

Referenced by ats_ip_to_hex(), and make_key().

size_t ats_ip_addr_size ( IpEndpoint const *  addr  )  [inline]
Parameters:
addr Address object.

Definition at line 381 of file ink_inet.h.

References IpEndpoint::sa.

bool ats_ip_are_compatible ( IpEndpoint const *  lhs,
IpEndpoint const *  rhs 
) [inline]
Returns:
true if the address families are compatible.
Parameters:
lhs Address to test.
rhs Address to test.

Definition at line 259 of file ink_inet.h.

References ats_ip_are_compatible(), and IpEndpoint::sa.

bool ats_ip_are_compatible ( sockaddr const *  lhs,
sockaddr const *  rhs 
) [inline]
Returns:
true if the address families are compatible.
Parameters:
lhs Address to test.
rhs Address to test.

Definition at line 252 of file ink_inet.h.

Referenced by ats_ip_are_compatible(), UDPNetProcessor::CreateUDPSocket(), HOSTDB_CLIENT_IP_HASH(), and TSNetConnectTransparent().

bool ats_ip_are_compatible ( int  lhs,
sockaddr const *  rhs 
) [inline]
Returns:
true if the address families are compatible.
Parameters:
lhs Address family to test.
rhs Address to test.

Definition at line 266 of file ink_inet.h.

bool ats_ip_are_compatible ( sockaddr const *  lhs,
int  rhs 
) [inline]
Returns:
true if the address families are compatible.
Parameters:
lhs Address to test.
rhs Family to test.

Definition at line 273 of file ink_inet.h.

int ats_ip_check_characters ( ts::ConstBuffer  text  ) 

Check to see if a buffer contains only IP address characters.

Returns:
  • AF_UNSPEC - not a numeric address.
  • AF_INET - only digits and dots.
  • AF_INET6 - colons found.

Definition at line 458 of file ink_inet.cc.

References ts::ConstBuffer::data(), and ts::ConstBuffer::size().

Referenced by LogHost::set_name_or_ipstr().

bool ats_ip_copy ( IpEndpoint dst,
IpEndpoint const *  src 
) [inline]
Parameters:
dst Destination object.
src Source object.

Definition at line 667 of file ink_inet.h.

References ats_ip_copy(), and IpEndpoint::sa.

bool ats_ip_copy ( sockaddr *  dst,
sockaddr const *  src 
) [inline]

Copy the address from src to dst if it's IP.

This attempts to do a minimal copy based on the type of src. If src is not an IP address type it is not copied and dst is marked as invalid.

Returns:
true if src was an IP address, false otherwise.
Parameters:
dst Destination object.
src Source object.

Definition at line 639 of file ink_inet.h.

References ats_ip_invalidate(), and memcpy.

Referenced by UnixNetProcessor::accept_internal(), NetAccept::acceptFastEvent(), IpEndpoint::assign(), ats_ip_copy(), ats_ip_getbestaddrinfo(), HttpSM::attach_client_session(), PrefetchBlaster::blastObject(), br(), check_n_attach_prefetch_transform(), CongestionEntry::CongestionEntry(), DNSConnection::connect(), UnixNetProcessor::connect_re_internal(), NetAccept::do_blocking_accept(), ExtractIpRange(), ParentSiblingPeer::ExtToIntRecvSockAddr(), MultiCastPeer::ExtToIntRecvSockAddr(), DNSHandler::failover(), SocksEntry::findServer(), SocksEntry::free(), get_congest_entry(), UDPConnection::getBinding(), HttpTransact::HandleRequest(), SocksEntry::init(), KeepAliveLockHandler::init(), HttpTransact::initialize_state_variables_from_request(), ink_res_getservers(), ink_res_init(), ink_res_setservers(), PrefetchBlaster::invokeBlaster(), Server::listen(), Machine::Machine(), HostDBContinuation::make_put_message(), net_accept(), new_incoming_UDPPacket(), new_UDPPacket(), DNSProcessor::open(), DNSHandler::open_con(), HttpTransact::OSDNSLookup(), PrefetchTransform::parse_data(), HttpTransact::PPDNSLookup(), HttpSM::process_hostdb_info(), HttpTransact::ReDNSRoundRobin(), request_to_data(), PluginVC::set_local_addr(), HttpSM::set_next_state(), PluginVC::set_remote_addr(), UnixNetVConnection::set_remote_addr(), UDPConnection::setBinding(), ts::detail::Ip6Node::setMax(), ts::detail::Ip6Node::setMin(), Connection::setRemote(), Connection::setup_mc_send(), HttpSM::state_http_server_open(), TSHttpTxnServerAddrSet(), and PrefetchUrlBlaster::udpUrlBlaster().

bool ats_ip_copy ( IpEndpoint dst,
sockaddr const *  src 
) [inline]
Parameters:
dst Destination object.
src Source object.

Definition at line 661 of file ink_inet.h.

References ats_ip_copy(), and IpEndpoint::sa.

bool ats_ip_copy ( sockaddr *  dst,
IpEndpoint const *  src 
) [inline]

Definition at line 673 of file ink_inet.h.

References ats_ip_copy(), and IpEndpoint::sa.

char const* ats_ip_family_name ( int  family  ) 

Get a string name for an IP address family.

Returns:
The string name (never NULL).

Definition at line 176 of file ink_inet.cc.

Referenced by HttpSM::do_http_server_open(), and HttpProxyPort::processOptions().

int ats_ip_getbestaddrinfo ( char const *  name,
IpEndpoint ip4,
IpEndpoint ip6 
)
Parameters:
[in] name Address name (IPv4, IPv6, or host name)
[out] ip4 Storage for IPv4 address.
[out] ip6 Storage for IPv6 address

Definition at line 372 of file ink_inet.cc.

References ats_ip_copy(), ats_ip_invalidate(), ats_ip_parse(), ats_ip_port_cast(), ats_is_ip(), ats_is_ip4(), ats_is_ip6(), ats_is_ip_linklocal(), ats_is_ip_loopback(), ats_is_ip_multicast(), ats_is_ip_private(), ts::ConstBuffer::data(), memcpy, ts::ConstBuffer::set(), and ts::ConstBuffer::size().

Referenced by RecHttpLoadIp(), and setup_socks_servers().

uint32_t ats_ip_hash ( sockaddr const *  addr  ) 
void ats_ip_invalidate ( IpEndpoint ip  )  [inline]

Definition at line 202 of file ink_inet.h.

References IpEndpoint::sa.

void ats_ip_invalidate ( sockaddr_in6 *  addr  )  [inline]

Definition at line 199 of file ink_inet.h.

void ats_ip_invalidate ( sockaddr *  addr  )  [inline]
char const* ats_ip_nptop ( const sockaddr *  addr,
char *  dst,
size_t  size 
)
char const* ats_ip_nptop ( IpEndpoint const *  addr,
char *  dst,
size_t  size 
) [inline]

Write a null terminated string for addr to dst with port.

A buffer of size INET6_ADDRPORTSTRLEN suffices, including a terminating nul.

Parameters:
addr Address.
dst Output buffer.
size Length of buffer.

Definition at line 930 of file ink_inet.h.

References ats_ip_nptop(), and IpEndpoint::sa.

char const* ats_ip_ntop ( const sockaddr *  addr,
char *  dst,
size_t  size 
)

Write a null terminated string for addr to dst.

A buffer of size INET6_ADDRSTRLEN suffices, including a terminating nul.

Parameters:
addr Address.
dst Output buffer.
size Length of buffer.
char const* ats_ip_ntop ( IpEndpoint const *  addr,
char *  dst,
size_t  size 
) [inline]

Write a null terminated string for addr to dst.

A buffer of size INET6_ADDRSTRLEN suffices, including a terminating nul.

Parameters:
addr Address.
dst Output buffer.
size Length of buffer.

Definition at line 903 of file ink_inet.h.

References ats_ip_ntop(), and IpEndpoint::sa.

const char* ats_ip_ntop ( const struct sockaddr *  addr,
char *  dst,
size_t  size 
)

Definition at line 156 of file ink_inet.cc.

References ats_ip4_addr_cast(), and ats_ip6_addr_cast().

Referenced by HttpSessionAccept::accept(), HttpTransact::add_client_ip_to_outgoing_request(), MultiCastPeer::AddMultiCastChild(), ats_ip_nptop(), ats_ip_ntop(), HttpTransact::build_error_response(), check_n_attach_prefetch_transform(), client_handler(), config_read_proto(), DNSConnection::connect(), HttpTransact::delete_server_rr_entry(), HttpSM::do_http_server_open(), HttpServerSession::do_io_close(), DNSHandler::failover(), SocksEntry::findServer(), CCCongestionDBTestCont::gen_CongestionEntry(), HttpTransact::handle_response_from_parent(), HttpTransact::HandleBlindTunnel(), KeepAliveConn::handleEvent(), IpMap_Fill(), IpMapTestPrint(), Machine::Machine(), HttpSM::mark_host_failure(), HttpServerSession::new_connection(), HttpTransact::OSDNSLookup(), ICPPeerReadCont::PeerReadStateMachine(), HttpTransact::PPDNSLookup(), IpAllow::Print(), IpMatcher< Data, Result >::Print(), acl_filter_rule::print(), CoreUtils::process_NetVC(), HttpTransact::process_quick_http_filter(), DNSHandler::recover(), DNSHandler::recv_dns(), HttpTransact::ReDNSRoundRobin(), remap_parse_config_bti(), remove_round_robin(), reply_to_cont(), HttpTransact::retry_server_connection_not_open(), DNSHandler::rr_failure(), HttpSM::set_next_state(), setup_socks_servers(), ShowNet::showConnectionsOnThread(), ShowHostDB::showLookupDone(), ShowHostDB::showOne(), CongestionEntry::sprint(), SSLDiagnostic(), IpAddr::toString(), LogAccess::unmarshal_ip_to_str(), and HttpSM::update_stats().

int ats_ip_parse ( ts::ConstBuffer  src,
ts::ConstBuffer addr,
ts::ConstBuffer port 
)

Parse a string for pieces of an IP address.

This doesn't parse the actual IP address, but picks it out from src. It is intended to deal with the brackets that can optionally surround an IP address (usually IPv6) which in turn are used to differentiate between an address and an attached port. E.g.

      [FE80:9312::192:168:1:1]:80

addr or port can be NULL in which case that value isn't returned.

Returns:
0 if an address was found, non-zero otherwise.
Parameters:
[in] src String to search.
[out] addr Range containing IP address.
[out] port Range containing port.

Definition at line 196 of file ink_inet.cc.

References ts::ConstBuffer::after(), ts::ConstBuffer::clip(), ts::ConstBuffer::data(), ts::ConstBuffer::find(), ts::ConstBuffer::reset(), and ts::ConstBuffer::splitOn().

Referenced by ats_ip_getbestaddrinfo(), ats_ip_pton(), Ink_Inet(), and LogHost::set_name_or_ipstr().

in_port_t const& ats_ip_port_cast ( sockaddr const *  sa  )  [inline]

Definition at line 406 of file ink_inet.h.

References ats_ip_port_cast().

in_port_t& ats_ip_port_cast ( IpEndpoint ip  )  [inline]

Definition at line 412 of file ink_inet.h.

References ats_ip_port_cast(), and IpEndpoint::sa.

in_port_t const& ats_ip_port_cast ( IpEndpoint const *  ip  )  [inline]

Definition at line 409 of file ink_inet.h.

References ats_ip_port_cast(), and IpEndpoint::sa.

in_port_t& ats_ip_port_cast ( sockaddr *  sa  )  [inline]
in_port_t ats_ip_port_host_order ( IpEndpoint const *  ip  )  [inline]

Get IP TCP/UDP port.

Returns:
The port in host order for an IPv4 or IPv6 address, or zero if neither.
Parameters:
ip Address with port.

Definition at line 796 of file ink_inet.h.

References ats_ip_port_cast(), and IpEndpoint::sa.

in_port_t ats_ip_port_host_order ( sockaddr const *  addr  )  [inline]
int ats_ip_pton ( const ts::ConstBuffer text,
IpEndpoint addr 
) [inline]
Parameters:
[in] text text.
[out] addr address

Definition at line 978 of file ink_inet.h.

References ats_ip_pton(), and IpEndpoint::sa.

int ats_ip_pton ( const char *  text,
sockaddr *  addr 
) [inline]
Parameters:
[in] text text.
[out] addr address

Definition at line 992 of file ink_inet.h.

References ats_ip_pton().

int ats_ip_pton ( const ts::ConstBuffer text,
sockaddr *  addr 
)

Convert text to an IP address and write it to addr.

text is expected to be an explicit address, not a hostname. No hostname resolution is done. The call must provide an ip large enough to hold the address value.

This attempts to recognize and process a port value if present. The port in ip is set appropriately, or to zero if no port was found or it was malformed.

Note:
The return values are logically reversed from inet_pton.
This uses getaddrinfo internally and so involves memory allocation.
Returns:
0 on success, non-zero on failure.
Parameters:
[in] text text.
[out] addr address

Definition at line 249 of file ink_inet.cc.

References ats_ip4_set(), ats_ip6_set(), ats_ip_invalidate(), ats_ip_parse(), ats_ip_port_cast(), ats_is_ip(), ts::ConstBuffer::data(), ts::ConstBuffer::find(), memcpy, ts::ConstBuffer::set(), and ts::ConstBuffer::size().

Referenced by ats_ip_pton(), config_read_proto(), DNSProcessor::dns_init(), HttpSM::do_hostdb_reverse_lookup(), ExtractIpRange(), SocksEntry::findServer(), HttpTransact::HandleRequest(), PrefetchBlaster::init(), Ink_Inet(), IpMap_Fill(), IpMap_Unmark(), IpAddr::load(), PARENTSELECTION(), read_addr(), register_ShowHostDB(), register_ShowNet(), remove_congested_entry(), NetVCOptions::set_sni_servername(), and ssl_store_ssl_context().

int ats_ip_pton ( char const *  text,
sockaddr_in6 *  addr 
) [inline]

Convert text to an IP address and write it to addr.

text is expected to be an explicit address, not a hostname. No hostname resolution is done.

Note:
This uses getaddrinfo internally and so involves memory allocation.
Convenience overload.
Returns:
0 on success, non-zero on failure.
Parameters:
[in] text text.
[out] addr address

Definition at line 971 of file ink_inet.h.

References ats_ip_pton(), and ats_ip_sa_cast().

int ats_ip_pton ( const char *  text,
IpEndpoint addr 
) [inline]
Parameters:
[in] text text.
[out] addr address

Definition at line 985 of file ink_inet.h.

References ats_ip_pton(), and IpEndpoint::sa.

int ats_ip_pton ( char const *  text,
IpAddr addr 
) [inline]

Convert text to an IP address and write it to addr.

Convenience overload.

Returns:
0 on success, non-zero on failure.
Parameters:
[in] text text.
[out] addr address

Definition at line 1239 of file ink_inet.h.

References IpAddr::load().

sockaddr const* ats_ip_sa_cast ( sockaddr_storage const *  a  )  [inline]

Definition at line 289 of file ink_inet.h.

sockaddr* ats_ip_sa_cast ( sockaddr_storage *  a  )  [inline]
sockaddr* ats_ip_sa_cast ( sockaddr_in6 *  a  )  [inline]

Definition at line 300 of file ink_inet.h.

sockaddr const* ats_ip_sa_cast ( sockaddr_in6 const *  a  )  [inline]

Definition at line 303 of file ink_inet.h.

sockaddr const* ats_ip_sa_cast ( sockaddr_in const *  a  )  [inline]

Definition at line 296 of file ink_inet.h.

sockaddr* ats_ip_sa_cast ( sockaddr_in *  a  )  [inline]

Definition at line 293 of file ink_inet.h.

sockaddr* ats_ip_set ( sockaddr *  dst,
IpAddr const &  addr,
in_port_t  port = 0 
)

Write IP addr to storage dst.

Returns:
dst.
Parameters:
dst Destination storage.
addr source address.
port port, network order.
size_t ats_ip_size ( IpEndpoint const *  addr  )  [inline]
Parameters:
addr Address object.

Definition at line 364 of file ink_inet.h.

References IpEndpoint::sa.

size_t ats_ip_size ( sockaddr const *  addr  )  [inline]
sockaddr_storage* ats_ip_ss_cast ( sockaddr *  a  )  [inline]

Definition at line 307 of file ink_inet.h.

sockaddr_storage const* ats_ip_ss_cast ( sockaddr const *  a  )  [inline]

Definition at line 310 of file ink_inet.h.

int ats_ip_to_hex ( sockaddr const *  addr,
char *  dst,
size_t  len 
)

Convert address to string as a hexidecimal value.

The string is always nul terminated, the output string is clipped if dst is insufficient.

Returns:
The length of the resulting string (not including nul).
Parameters:
addr Address to convert. Must be IP.
dst Destination buffer.
len Length of dst.

Definition at line 301 of file ink_inet.cc.

References ats_ip_addr8_cast(), ats_ip_addr_size(), ats_is_ip(), and ink_assert.

Referenced by Machine::Machine(), SSLAddressLookupKey::SSLAddressLookupKey(), and LogAccess::unmarshal_ip_to_hex().

bool ats_is_ip ( IpEndpoint const *  addr  )  [inline]
Returns:
true if the address is IP, false otherwise.

Definition at line 219 of file ink_inet.h.

References IpEndpoint::sa.

bool ats_is_ip ( sockaddr const *  addr  )  [inline]
bool ats_is_ip ( int  family  )  [inline]

Test for IP protocol.

Returns:
true if the value is an IP address family, false otherwise.

Definition at line 225 of file ink_inet.h.

bool ats_is_ip4 ( IpEndpoint const *  addr  )  [inline]

Test for IPv4 protocol.

Note:
Convenience overload.
Returns:
true if the address is IPv4, false otherwise.

Definition at line 236 of file ink_inet.h.

References IpEndpoint::sa.

bool ats_is_ip4 ( sockaddr const *  addr  )  [inline]
bool ats_is_ip6 ( sockaddr const *  addr  )  [inline]
bool ats_is_ip6 ( IpEndpoint const *  addr  )  [inline]

Test for IPv6 protocol.

Note:
Convenience overload.
Returns:
true if the address is IPv6, false otherwise.

Definition at line 247 of file ink_inet.h.

References IpEndpoint::sa.

bool ats_is_ip_any ( sockaddr const *  ip  )  [inline]

Check for being "any" address.

Returns:
true if ip is the any / unspecified address.

Definition at line 624 of file ink_inet.h.

References ats_ip4_addr_cast(), ats_ip6_addr_cast(), ats_is_ip4(), and ats_is_ip6().

Referenced by remap_parse_config_bti(), and TSHttpConnectTransparent().

bool ats_is_ip_linklocal ( IpEndpoint const *  ip  )  [inline]

Check for Link Local.

Returns:
if ip is link local.

Definition at line 618 of file ink_inet.h.

References ats_is_ip_linklocal(), and IpEndpoint::sa.

bool ats_is_ip_linklocal ( sockaddr const *  ip  )  [inline]

Check for Link Local.

Returns:
if ip is link local.

Definition at line 601 of file ink_inet.h.

References a, ats_ip4_addr_cast(), ats_ip6_addr_cast(), ats_is_ip4(), and ats_is_ip6().

Referenced by ats_ip_getbestaddrinfo(), ats_is_ip_linklocal(), and Machine::Machine().

bool ats_is_ip_loopback ( sockaddr const *  ip  )  [inline]

Check for loopback.

Returns:
true if this is an IP loopback address, false otherwise.

Definition at line 540 of file ink_inet.h.

References ats_ip6_addr_cast(), and ats_ip_addr8_cast().

Referenced by ats_ip_getbestaddrinfo(), ats_is_ip_loopback(), client_handler(), and Machine::Machine().

bool ats_is_ip_loopback ( IpEndpoint const *  ip  )  [inline]

Check for loopback.

Returns:
true if this is an IP loopback address, false otherwise.

Definition at line 551 of file ink_inet.h.

References ats_is_ip_loopback(), and IpEndpoint::sa.

bool ats_is_ip_multicast ( IpEndpoint const *  ip  )  [inline]

Check for multicast.

Returns:
if ip is multicast.

Definition at line 567 of file ink_inet.h.

References ats_is_ip_multicast(), and IpEndpoint::sa.

bool ats_is_ip_multicast ( sockaddr const *  ip  )  [inline]

Check for multicast.

Returns:
if ip is multicast.

Definition at line 557 of file ink_inet.h.

References ats_ip6_addr_cast(), and ats_ip_addr8_cast().

Referenced by ats_ip_getbestaddrinfo(), ats_is_ip_multicast(), Machine::Machine(), and UDPNetProcessor::UDPBind().

bool ats_is_ip_private ( sockaddr const *  ip  )  [inline]

Check for Private.

Returns:
if ip is private.

Definition at line 574 of file ink_inet.h.

References a, ats_ip4_addr_cast(), ats_ip6_addr_cast(), ats_is_ip4(), and ats_is_ip6().

Referenced by ats_ip_getbestaddrinfo(), ats_is_ip_private(), and Machine::Machine().

bool ats_is_ip_private ( IpEndpoint const *  ip  )  [inline]

Check for Private.

Returns:
if ip is private.

Definition at line 594 of file ink_inet.h.

References ats_is_ip_private(), and IpEndpoint::sa.

struct hostent* ink_gethostbyaddr_r ( char *  ip,
int  len,
int  type,
ink_gethostbyaddr_r_data data 
) [read]

Wrapper for gethostbyaddr_r().

If successful, returns a pointer to the hostent structure. Returns NULL and sets data->herrno to the appropriate error code on failure.

Parameters:
ip IP address of the host
len length of the buffer indicated by ip
type family of the address
data pointer to ink_gethostbyname_r_data allocated by the caller

Definition at line 68 of file ink_inet.cc.

References ink_gethostbyaddr_r_data::buf, ink_gethostbyaddr_r_data::ent, ink_gethostbyaddr_r_data::herrno, and INK_GETHOSTBYNAME_R_DATA_SIZE.

Referenced by ClusterMachine::ClusterMachine().

struct hostent* ink_gethostbyname_r ( char *  hostname,
ink_gethostbyname_r_data data 
) [read]

Wrapper for gethostbyname_r().

If successful, returns a pointer to the hostent structure. Returns NULL and sets data->herrno to the appropriate error code on failure.

Parameters:
hostname null-terminated host name string
data pointer to ink_gethostbyname_r_data allocated by the caller

Definition at line 39 of file ink_inet.cc.

References ink_gethostbyname_r_data::buf, ink_gethostbyname_r_data::ent, ink_gethostbyname_r_data::herrno, and INK_GETHOSTBYNAME_R_DATA_SIZE.

bool operator!= ( IpEndpoint const &  lhs,
IpEndpoint const &  rhs 
) [inline]

Definition at line 764 of file ink_inet.h.

References ats_ip_addr_cmp(), and IpEndpoint::sa.

bool operator!= ( IpAddr const &  lhs,
sockaddr const *  rhs 
) [inline]

Definition at line 1208 of file ink_inet.h.

bool operator!= ( sockaddr const *  lhs,
IpAddr const &  rhs 
) [inline]

Definition at line 1211 of file ink_inet.h.

bool operator!= ( IpAddr const &  lhs,
IpEndpoint const &  rhs 
) [inline]

Definition at line 1220 of file ink_inet.h.

References IpEndpoint::sa.

bool operator!= ( IpEndpoint const &  lhs,
IpAddr const &  rhs 
) [inline]

Definition at line 1223 of file ink_inet.h.

References IpEndpoint::sa.

bool operator== ( IpAddr const &  lhs,
sockaddr const *  rhs 
)
bool operator== ( IpAddr const &  lhs,
IpEndpoint const &  rhs 
) [inline]

Definition at line 1214 of file ink_inet.h.

References IpEndpoint::sa.

bool operator== ( IpEndpoint const &  lhs,
IpAddr const &  rhs 
) [inline]

Definition at line 1217 of file ink_inet.h.

References IpEndpoint::sa.

bool operator== ( IpEndpoint const &  lhs,
IpEndpoint const &  rhs 
) [inline]

Definition at line 761 of file ink_inet.h.

References ats_ip_addr_cmp(), and IpEndpoint::sa.

bool operator== ( sockaddr const *  lhs,
IpAddr const &  rhs 
) [inline]

Definition at line 1205 of file ink_inet.h.


Variable Documentation

size_t const INET6_ADDRPORTSTRLEN = INET6_ADDRSTRLEN + 6 [static]
size_t const TS_IP6_SIZE = sizeof(in6_addr) [static]