Data Structures | Functions

ink_inet.cc File Reference

A brief file description. More...

#include "libts.h"
#include "ts/TestBox.h"
Include dependency graph for ink_inet.cc:

Go to the source code of this file.

Data Structures

struct  ip_parse_spec

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().
uint32_t ink_inet_addr (const char *s)
const char * ats_ip_ntop (const struct sockaddr *addr, char *dst, size_t size)
char const * ats_ip_family_name (int family)
 Get a string name for an IP address family.
char const * ats_ip_nptop (sockaddr const *addr, char *dst, size_t size)
 Write a null terminated string for addr to dst with port.
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_pton (const ts::ConstBuffer &src, sockaddr *ip)
 Convert text to an IP address and write it to addr.
uint32_t ats_ip_hash (sockaddr const *addr)
 Generic IP address hash function.
int ats_ip_to_hex (sockaddr const *src, char *dst, size_t len)
 Convert address to string as a hexidecimal value.
sockaddr * ats_ip_set (sockaddr *dst, IpAddr const &addr, uint16_t port)
bool operator== (IpAddr const &lhs, sockaddr const *rhs)
int ats_ip_getbestaddrinfo (char const *host, IpEndpoint *ip4, IpEndpoint *ip6)
int ats_ip_check_characters (ts::ConstBuffer text)
 Check to see if a buffer contains only IP address characters.
REGRESSION_TEST() Ink_Inet (RegressionTest *t, int, int *pstatus)

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.cc.


Function Documentation

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().

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 *  host,
IpEndpoint ip4,
IpEndpoint ip6 
)
Parameters:
[in] host 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  ) 
char const* ats_ip_nptop ( const sockaddr *  addr,
char *  dst,
size_t  size 
)
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().

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] src text.
[out] ip 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().

sockaddr* ats_ip_set ( sockaddr *  dst,
IpAddr const &  addr,
uint16_t  port 
)
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:
src 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().

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.

Referenced by ClusterMachine::ClusterMachine().

REGRESSION_TEST() Ink_Inet ( RegressionTest t,
int  ,
int *  pstatus 
)
uint32_t ink_inet_addr ( const char *  s  ) 
bool operator== ( IpAddr const &  lhs,
sockaddr const *  rhs 
)