#include <Address.h>

Collaboration diagram for Ip::Address:

Public Member Functions

unsigned short port () const
 
unsigned short port (unsigned short port)
 
void setAnyAddr ()
 NOTE: Does NOT clear the Port stored. Ony the Address and Type. More...
 
void setNoAddr ()
 
void setLocalhost ()
 
void setEmpty ()
 Fast reset of the stored content to what would be after default constructor. More...
 
bool setIPv4 ()
 
int cidr () const
 
int applyMask (const Address &mask)
 
bool applyMask (const unsigned int cidr, int mtype)
 
void applyClientMask (const Address &mask)
 
char * toStr (char *buf, const unsigned int blen, int force=AF_UNSPEC) const
 
char * toUrl (char *buf, unsigned int len) const
 
unsigned int toHostStr (char *buf, const unsigned int len) const
 
bool fromHost (const char *hostWithoutPort)
 
bool getReverseString (char buf[MAX_IPSTRLEN], int show_type=AF_UNSPEC) const
 
int matchIPAddr (const Address &rhs) const
 
int compareWhole (const Ip::Address &rhs) const
 
void getAddrInfo (struct addrinfo *&ai, int force=AF_UNSPEC) const
 
bool GetHostByName (const char *s)
 
void getSockAddr (struct sockaddr_storage &addr, const int family) const
 
void getSockAddr (struct sockaddr_in &) const
 
bool getInAddr (struct in_addr &) const
 
void getSockAddr (struct sockaddr_in6 &) const
 
void getInAddr (struct in6_addr &) const
 
Constructors and Destructor
 Address ()
 
 Address (const struct in_addr &)
 
 Address (const struct sockaddr_in &)
 
 Address (const struct in6_addr &)
 
 Address (const struct sockaddr_in6 &)
 
 Address (const struct hostent &)
 
 Address (const struct addrinfo &)
 
 Address (const char *)
 
 ~Address ()
 
Assignment Operators
Addressoperator= (struct sockaddr_in const &s)
 
Addressoperator= (struct sockaddr_storage const &s)
 
Addressoperator= (struct in_addr const &s)
 
Addressoperator= (struct in6_addr const &s)
 
Addressoperator= (struct sockaddr_in6 const &s)
 
bool operator= (const struct hostent &s)
 
bool operator= (const struct addrinfo &s)
 
bool operator= (const char *s)
 
Boolean Operators
bool operator== (Address const &s) const
 
bool operator!= (Address const &s) const
 
bool operator>= (Address const &rhs) const
 
bool operator<= (Address const &rhs) const
 
bool operator> (Address const &rhs) const
 
bool operator< (Address const &rhs) const
 
bool isIPv4 () const
 
bool isIPv6 () const
 
bool isSockAddr () const
 
bool isAnyAddr () const
 
bool isNoAddr () const
 
bool isLocalhost () const
 
bool isSiteLocal6 () const
 
bool isSiteLocalAuto () const
 

Static Public Member Functions

static void FreeAddr (struct addrinfo *&ai)
 
static void InitAddr (struct addrinfo *&ai)
 

Private Member Functions

bool getReverseString4 (char buf[MAX_IPSTRLEN], const struct in_addr &dat) const
 
bool getReverseString6 (char buf[MAX_IPSTRLEN], const struct in6_addr &dat) const
 
void map4to6 (const struct in_addr &src, struct in6_addr &dest) const
 
void map6to4 (const struct in6_addr &src, struct in_addr &dest) const
 
bool lookupHostIP (const char *s, bool nodns)
 

Private Attributes

struct sockaddr_in6 mSocketAddr_
 

Static Private Attributes

static const unsigned int STRLEN_IP4A = 16
 
static const unsigned int STRLEN_IP4R = 28
 
static const unsigned int STRLEN_IP4S = 21
 
static const unsigned int MAX_IP4_STRLEN = STRLEN_IP4R
 
static const unsigned int STRLEN_IP6A = 42
 
static const unsigned int STRLEN_IP6R = 75
 
static const unsigned int STRLEN_IP6S = 48
 
static const unsigned int MAX_IP6_STRLEN = STRLEN_IP6R
 
static const struct in6_addr v4_localhost
 
static const struct in6_addr v4_anyaddr
 
static const struct in6_addr v4_noaddr
 
static const struct in6_addr v6_noaddr
 

Detailed Description

Holds and manipulates IPv4, IPv6, and Socket Addresses.

Definition at line 40 of file Address.h.

Constructor & Destructor Documentation

◆ Address() [1/8]

Ip::Address::Address ( )
inline

Definition at line 46 of file Address.h.

References setEmpty().

◆ Address() [2/8]

Ip::Address::Address ( const struct in_addr &  s)

Definition at line 465 of file Address.cc.

References operator=(), and setEmpty().

◆ Address() [3/8]

Ip::Address::Address ( const struct sockaddr_in &  s)

Definition at line 423 of file Address.cc.

References operator=(), and setEmpty().

◆ Address() [4/8]

Ip::Address::Address ( const struct in6_addr &  s)

Definition at line 479 of file Address.cc.

References operator=(), and setEmpty().

◆ Address() [5/8]

Ip::Address::Address ( const struct sockaddr_in6 &  s)

Definition at line 452 of file Address.cc.

References operator=(), and setEmpty().

◆ Address() [6/8]

Ip::Address::Address ( const struct hostent s)

Definition at line 494 of file Address.cc.

References operator=(), and setEmpty().

◆ Address() [7/8]

Ip::Address::Address ( const struct addrinfo s)

Definition at line 538 of file Address.cc.

References operator=(), and setEmpty().

◆ Address() [8/8]

Ip::Address::Address ( const char *  s)

Definition at line 359 of file Address.cc.

References lookupHostIP(), and setEmpty().

◆ ~Address()

Member Function Documentation

◆ applyClientMask()

void Ip::Address::applyClientMask ( const Address mask)

Apply so-called 'privacy masking' to IPv4 addresses, except localhost IP. IPv6 clients use 'privacy addressing' instead.

Definition at line 105 of file Address.cc.

References applyMask(), isIPv4(), and isLocalhost().

Referenced by ConnStateData::ConnStateData(), AccessLogEntry::getLogClientIp(), ProxyProtocol::Header::getValues(), and ~Address().

◆ applyMask() [1/2]

int Ip::Address::applyMask ( const Address mask)

Apply a mask to the stored address.

Parameters
maskNetmask format to be bit-mask-AND'd over the stored address.

Definition at line 87 of file Address.cc.

References i, and mSocketAddr_.

Referenced by aclIpAddrNetworkCompare(), applyClientMask(), asnAddNet(), acl_ip_data::DecodeMask(), acl_ip_data::FactoryParse(), networkFromInaddr(), testIpAddress::testMasking(), and ~Address().

◆ applyMask() [2/2]

bool Ip::Address::applyMask ( const unsigned int  cidr,
int  mtype 
)

Apply a mask to the stored address. CIDR will be converted appropriate to map the stored content.

Parameters
cidrCIDR Mask being applied. As an integer in host format.
mtypeType of CIDR mask being applied (AF_INET or AF_INET6)

Definition at line 112 of file Address.cc.

References mSocketAddr_, NULL, p, and setNoAddr().

◆ cidr()

int Ip::Address::cidr ( ) const

Valid results IF and only IF the stored IP address is actually a network bitmask

Return values
Nnumber of bits which are set in the bitmask stored.

Definition at line 44 of file Address.cc.

References isIPv6(), len, and mSocketAddr_.

Referenced by acl_ip_data::DecodeMask(), acl_ip_data::FactoryParse(), printRadixNode(), testIpAddress::testMasking(), acl_ip_data::toStr(), and ~Address().

◆ compareWhole()

int Ip::Address::compareWhole ( const Ip::Address rhs) const

Compare taking IP, port, protocol, etc. into account. Returns an integer less than, equal to, or greater than zero if the object is found, respectively, to be less than, to match, or to be greater than rhs. The exact ordering algorithm is not specified and may change.

Definition at line 724 of file Address.cc.

Referenced by ~Address().

◆ FreeAddr()

◆ fromHost()

bool Ip::Address::fromHost ( const char *  hostWithoutPort)

Empties the address and then slowly imports the IP from a possibly [bracketed] portless host. For the semi-reverse operation, see toHostStr() which does export the port.

Returns
whether the conversion was successful

Definition at line 908 of file Address.cc.

References lookupHostIP(), setEmpty(), xfree, and xstrdup.

Referenced by ipcacheCheckNumeric(), ACLDestinationDomainStrategy::match(), and ~Address().

◆ getAddrInfo()

void Ip::Address::getAddrInfo ( struct addrinfo *&  ai,
int  force = AF_UNSPEC 
) const

Get RFC 3493 addrinfo structure from the Ip::Address data for protocol-neutral socket operations. Should be passed a NULL pointer of type struct addrinfo* it will allocate memory for the structures involved. (see FreeAddr() to clear). Defaults to a TCP streaming socket, if other values (such as UDP) are needed the caller MUST override these default settings. Some situations may also require an actual call to the system getaddrinfo() to pull relevant OS details for the socket.

Ip::Address allocated objects MUST be destructed by Ip::Address::FreeAddr System getaddrinfo() allocated objects MUST be freed with system freeaddrinfo()
Parameters
aistructure to be filled out.
forcea specific sockaddr type is needed. default: don't care.

Definition at line 599 of file Address.cc.

References addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_family, addrinfo::ai_flags, AI_NUMERICHOST, addrinfo::ai_protocol, addrinfo::ai_socktype, Ip::EnableIpv6, getSockAddr(), IASSERT, isIPv4(), isIPv6(), and NULL.

Referenced by client_comm_bind(), client_comm_connect(), comm_connect_addr(), comm_openex(), comm_udp_sendto(), ftpSendPORT(), getMyHostname(), Ipc::ImportFdIntoComm(), process_request(), resolveDestination(), Icmp6::SendEcho(), Icmp4::SendEcho(), Ipc::SharedListenJoined(), testIpAddress::testAddrInfo(), and ~Address().

◆ GetHostByName()

bool Ip::Address::GetHostByName ( const char *  s)

Lookup a Host by Name. Equivalent to system call gethostbyname(char*)

Parameters
sThe textual FQDN of the host being located.
Return values
truelookup was successful and an IPA was located.
falselookup failed or FQDN has no IP associated.

Definition at line 372 of file Address.cc.

References lookupHostIP().

Referenced by ProxyProtocol::One::ExtractIp(), GetHostWithPort(), parse_address(), resolveDestination(), and ~Address().

◆ getInAddr() [1/2]

◆ getInAddr() [2/2]

void Ip::Address::getInAddr ( struct in6_addr &  buf) const

Definition at line 1024 of file Address.cc.

References mSocketAddr_.

◆ getReverseString()

bool Ip::Address::getReverseString ( char  buf[MAX_IPSTRLEN],
int  show_type = AF_UNSPEC 
) const

Convert the content into a Reverse-DNS string. The buffer sent MUST be allocated large enough to hold the resulting string. Name truncation will occur if buf does not have enough space. The constant MAX_IPSTRLEN is defined to provide for sizing arrays correctly.

Parameters
show_typemay be one of: AF_INET, AF_INET6 for the format of rDNS string wanted. AF_UNSPEC the default displays the IP in its most advanced native form.
bufbuffer to receive the text string output.

Definition at line 338 of file Address.cc.

References buf, DBG_CRITICAL, debugs, getReverseString4(), getReverseString6(), isIPv4(), isIPv6(), mSocketAddr_, and toStr().

Referenced by testIpAddress::testgetReverseString(), and ~Address().

◆ getReverseString4()

bool Ip::Address::getReverseString4 ( char  buf[MAX_IPSTRLEN],
const struct in_addr &  dat 
) const
private

Definition at line 326 of file Address.cc.

References buf, i, and int.

Referenced by getReverseString(), and ~Address().

◆ getReverseString6()

bool Ip::Address::getReverseString6 ( char  buf[MAX_IPSTRLEN],
const struct in6_addr &  dat 
) const
private

Definition at line 299 of file Address.cc.

References buf, i, and p.

Referenced by getReverseString(), and ~Address().

◆ getSockAddr() [1/3]

◆ getSockAddr() [2/3]

void Ip::Address::getSockAddr ( struct sockaddr_in &  buf) const

Definition at line 956 of file Address.cc.

References assert, DBG_CRITICAL, debugs, HERE(), isIPv4(), map6to4(), and mSocketAddr_.

◆ getSockAddr() [3/3]

void Ip::Address::getSockAddr ( struct sockaddr_in6 &  buf) const

Definition at line 976 of file Address.cc.

References mSocketAddr_.

◆ InitAddr()

void Ip::Address::InitAddr ( struct addrinfo *&  ai)
static

Initializes an empty addrinfo properly for use. It is intended for use in cases such as getsockopt() where the addrinfo is about to be changed and the stored details may not match the new ones coming.

Parameters
aiaddrinfo struct to be initialized as AF_UNSPEC with large address buffer

Definition at line 668 of file Address.cc.

References addrinfo::ai_addr, addrinfo::ai_addrlen, and NULL.

Referenced by comm_local_port(), comm_udp_recvfrom(), ipc_thread_1(), ipcCreate(), Comm::ConnOpener::lookupLocalAddress(), Comm::TcpAcceptor::oldAccept(), Icmp6::Recv(), Icmp4::Recv(), and ~Address().

◆ isAnyAddr()

bool Ip::Address::isAnyAddr ( ) const

Content-neutral test for whether the specific IP case ANY_ADDR is stored. This is the default content of a new undefined Ip::Address object.

Return values
trueIPv4 0.0.0.0
trueIPv6 ::
falseanything else.

Definition at line 170 of file Address.cc.

References mSocketAddr_, and v4_anyaddr.

Referenced by aclIpAddrNetworkCompare(), asnMatchIp(), Format::Format::assemble(), Ftp::Server::checkDataConnPre(), client_Inst(), Adaptation::Ecap::XactionRep::clientIpValue(), comm_apply_flags(), comm_local_port(), Ftp::Server::createDataConnection(), FindListeningPortAddressInAddress(), IdleConnList::findUseable(), fqdncache_gethostbyaddr(), getMyHostname(), getOutgoingAddress(), AnyP::Uri::host(), htcpOpenPorts(), icpOpenPorts(), idnsAddNameserver(), internalRemoteUri(), Adaptation::Icap::ModXact::makeRequestHeaders(), netdbExchangeHandleReply(), operator<(), operator<=(), Ftp::ParseIpPort(), Ftp::ParseProtoIpPort(), process_request(), Ssl::setClientSNI(), setIPv4(), snmpOpenPorts(), Log::Format::SquidIcap(), testIpAddress::testBugNullingDisplay(), testIpAddress::testCopyConstructor(), testIpAddress::testDefaults(), testIpAddress::testHostentConstructor(), testIpAddress::testInAddr6Constructor(), testIpAddress::testInAddrConstructor(), testIpAddress::testMasking(), testIpAddress::testsetEmpty(), testIpAddress::testSockAddr6Constructor(), testIpAddress::testSockAddrConstructor(), testIpAddress::testStringConstructor(), acl_ip_data::toStr(), toStr(), wccp2Init(), wccpConnectionOpen(), wccpInit(), and ~Address().

◆ isIPv4()

bool Ip::Address::isIPv4 ( ) const

Test whether content can be used as an IPv4 address

Return values
trueif content was received as an IPv4-Mapped address
falseif content was received as a non-mapped IPv6 native address.

Definition at line 158 of file Address.cc.

References mSocketAddr_.

Referenced by ProxyProtocol::Header::addressFamily(), applyClientMask(), Format::Format::assemble(), client_Inst(), comm_connect_addr(), ResolvedPeers::ConnectionFamily(), Ftp::Server::createDataConnection(), Comm::ConnOpener::createFd(), acl_ip_data::DecodeMask(), Log::TcpLogger::doConnect(), ftpSendPORT(), getAddrInfo(), getInAddr(), getOutgoingAddress(), getReverseString(), getSockAddr(), VectorPool::id(), ClassCHostPool::id(), idnsInitVC(), isIPv6(), logfile_mod_udp_open(), ClassCHostPool::makeHostKey(), IndividualPool::makeKey(), ClassCNetPool::makeKey(), ClassCHostPool::makeKey(), ACLARP::match(), netdbBinaryExchange(), netdbExchangeUpdatePeer(), PeerSelector::noteIp(), Comm::TcpAcceptor::oldAccept(), Ip::Intercept::ProbeForTproxy(), IcmpPinger::Recv(), Ftp::Client::sendPassive(), setIPv4(), Ip::Qos::setSockTos(), snmp_meshCtblFn(), snmp_meshPtblFn(), Comm::ConnOpener::start(), testIpAddress::testBugNullingDisplay(), testIpAddress::testCopyConstructor(), testIpAddress::testDefaults(), testIpAddress::testHostentConstructor(), testIpAddress::testInAddr6Constructor(), testIpAddress::testInAddrConstructor(), testIpAddress::testMasking(), testIpAddress::testsetEmpty(), testIpAddress::testSockAddr6Constructor(), testIpAddress::testSockAddrConstructor(), testIpAddress::testStringConstructor(), acl_ip_data::toStr(), toStr(), and ~Address().

◆ isIPv6()

◆ isLocalhost()

bool Ip::Address::isLocalhost ( ) const

Content-neutral test for whether the specific IP case LOCALHOST is stored. This is the default content of a new undefined Ip::Address object.

Return values
trueIPv4 127.0.0.1
trueIPv6 ::1
falseanything else.

Definition at line 249 of file Address.cc.

References mSocketAddr_, and v4_localhost.

Referenced by applyClientMask(), setIPv4(), and ~Address().

◆ isNoAddr()

◆ isSiteLocal6()

bool Ip::Address::isSiteLocal6 ( ) const

Test whether content is an IPv6 Site-Local address.

Return values
trueif address begins with fd00::/8.
falseif –disable-ipv6 has been compiled.
falseif address does not match fd00::/8

Definition at line 267 of file Address.cc.

References mSocketAddr_.

Referenced by Eui::Eui64::lookupSlaac(), and ~Address().

◆ isSiteLocalAuto()

bool Ip::Address::isSiteLocalAuto ( ) const

Test whether content is an IPv6 address with SLAAC EUI-64 embeded.

Return values
trueif address matches ::ff:fe00:0
falseif –disable-ipv6 has been compiled.
falseif address does not match ::ff:fe00:0

Definition at line 277 of file Address.cc.

References mSocketAddr_.

Referenced by Eui::Eui64::lookupSlaac(), and ~Address().

◆ isSockAddr()

bool Ip::Address::isSockAddr ( ) const

Test whether content can be used as a Socket address.

Return values
trueif address AND port are both set
trueif content was received as a Socket address with port
falseif port in unset (zero)

Definition at line 152 of file Address.cc.

References mSocketAddr_.

Referenced by testIpAddress::testBugNullingDisplay(), testIpAddress::testCopyConstructor(), testIpAddress::testDefaults(), testIpAddress::testHostentConstructor(), testIpAddress::testInAddr6Constructor(), testIpAddress::testInAddrConstructor(), testIpAddress::testsetEmpty(), testIpAddress::testSockAddr6Constructor(), testIpAddress::testSockAddrConstructor(), testIpAddress::testStringConstructor(), and ~Address().

◆ lookupHostIP()

bool Ip::Address::lookupHostIP ( const char *  s,
bool  nodns 
)
private

◆ map4to6()

void Ip::Address::map4to6 ( const struct in_addr &  src,
struct in6_addr &  dest 
) const
private

Definition at line 989 of file Address.cc.

References v4_anyaddr, and v4_noaddr.

Referenced by operator=(), and ~Address().

◆ map6to4()

void Ip::Address::map6to4 ( const struct in6_addr &  src,
struct in_addr &  dest 
) const
private

Definition at line 1010 of file Address.cc.

Referenced by getInAddr(), getSockAddr(), and ~Address().

◆ matchIPAddr()

int Ip::Address::matchIPAddr ( const Address rhs) const

Test how two IP relate to each other.

Return values
0IP are equal
1IP rhs is greater (numerically) than that stored.
-1IP rhs is less (numerically) than that stored.

Definition at line 703 of file Address.cc.

References i, and mSocketAddr_.

Referenced by aclIpAddrNetworkCompare(), IdleConnList::findUseable(), operator<(), operator<=(), operator==(), operator>(), operator>=(), testIpAddress::testBooleans(), and ~Address().

◆ operator!=()

bool Ip::Address::operator!= ( Address const &  s) const

Definition at line 736 of file Address.cc.

References operator==().

Referenced by ~Address().

◆ operator<()

bool Ip::Address::operator< ( Address const &  rhs) const

Definition at line 769 of file Address.cc.

References isAnyAddr(), and matchIPAddr().

Referenced by ~Address().

◆ operator<=()

bool Ip::Address::operator<= ( Address const &  rhs) const

Definition at line 742 of file Address.cc.

References isAnyAddr(), and matchIPAddr().

Referenced by ~Address().

◆ operator=() [1/8]

Ip::Address & Ip::Address::operator= ( struct sockaddr_in const &  s)

Definition at line 430 of file Address.cc.

References map4to6(), and mSocketAddr_.

Referenced by Address(), lookupHostIP(), operator=(), and ~Address().

◆ operator=() [2/8]

Ip::Address & Ip::Address::operator= ( struct sockaddr_storage const &  s)

Definition at line 439 of file Address.cc.

References map4to6(), and mSocketAddr_.

◆ operator=() [3/8]

Ip::Address & Ip::Address::operator= ( struct in_addr const &  s)

Definition at line 472 of file Address.cc.

References map4to6(), and mSocketAddr_.

◆ operator=() [4/8]

Ip::Address & Ip::Address::operator= ( struct in6_addr const &  s)

Definition at line 486 of file Address.cc.

References mSocketAddr_.

◆ operator=() [5/8]

Ip::Address & Ip::Address::operator= ( struct sockaddr_in6 const &  s)

Definition at line 459 of file Address.cc.

References mSocketAddr_.

◆ operator=() [6/8]

bool Ip::Address::operator= ( const struct hostent s)

Definition at line 501 of file Address.cc.

References hostent::h_addr_list, hostent::h_addrtype, IASSERT, NULL, and operator=().

◆ operator=() [7/8]

bool Ip::Address::operator= ( const struct addrinfo s)

◆ operator=() [8/8]

bool Ip::Address::operator= ( const char *  s)

Definition at line 366 of file Address.cc.

References lookupHostIP().

◆ operator==()

bool Ip::Address::operator== ( Address const &  s) const

Definition at line 730 of file Address.cc.

References matchIPAddr().

Referenced by operator!=(), and ~Address().

◆ operator>()

bool Ip::Address::operator> ( Address const &  rhs) const

Definition at line 760 of file Address.cc.

References isNoAddr(), and matchIPAddr().

Referenced by ~Address().

◆ operator>=()

bool Ip::Address::operator>= ( Address const &  rhs) const

Definition at line 751 of file Address.cc.

References isNoAddr(), and matchIPAddr().

Referenced by ~Address().

◆ port() [1/2]

unsigned short Ip::Address::port ( ) const

Retrieve the Port if stored.

Return values
0Port is unset or an error occurred.
nPort associated with this address in host native -endian.

Definition at line 778 of file Address.cc.

References mSocketAddr_.

Referenced by Format::Format::assemble(), clientBeginRequest(), comm_apply_flags(), comm_connect_addr(), comm_import_opened(), comm_local_port(), Ftp::Client::connectDataChannel(), Ftp::Server::createDataConnection(), Adaptation::Icap::Xaction::dnsLookupDone(), ProxyProtocol::One::ExtractPort(), ConnStateData::fakeAConnectRequest(), IdleConnList::findUseable(), ftpOpenListenSocket(), ftpReadPORT(), GetHostWithPort(), getOutgoingAddress(), Ip::Qos::getTosFromServer(), ProxyProtocol::Header::getValues(), Ftp::Client::handleEpsvReply(), htcpHandleTstResponse(), htcpOpenPorts(), icpOpenPorts(), idnsAddNameserver(), idnsFromKnownNameserver(), ConnStateData::initiateTunneledRequest(), Ftp::Server::listenForDataConnection(), Eui::Eui48::lookup(), lookupHostIP(), ACLLocalPortStrategy::match(), neighborIgnoreNonPeer(), PeerSelector::noteIp(), Comm::TcpAcceptor::oldAccept(), HappyConnOpener::openFreshConnection(), PeerPoolMgr::openNewConnection(), Ftp::ParseIpPort(), Ftp::ParseProtoIpPort(), peerDNSConfigure(), peerProbeConnect(), Ip::Intercept::PfInterception(), ConnStateData::postHttpsAccept(), prepareAcceleratedURL(), prepareTransparentURL(), Ip::Intercept::ProbeForTproxy(), process_request(), IcmpSquid::Recv(), resolveDestination(), send_announce(), Ftp::Client::sendEprt(), snmpOpenPorts(), snmpPortOpened(), Ident::Start(), testIpAddress::testBugNullingDisplay(), testIpAddress::testCopyConstructor(), testIpAddress::testDefaults(), testIpAddress::testHostentConstructor(), testIpAddress::testInAddr6Constructor(), testIpAddress::testInAddrConstructor(), testIpAddress::testsetEmpty(), testIpAddress::testSockAddr6Constructor(), testIpAddress::testSockAddrConstructor(), testIpAddress::testStringConstructor(), toUrl(), wccp2ConnectionOpen(), wccp2HereIam(), wccpConnectionOpen(), whichPeer(), and ~Address().

◆ port() [2/2]

unsigned short Ip::Address::port ( unsigned short  port)

Set the Port value for an address. Replaces any previously existing Port value.

Parameters
portPort being assigned in host native -endian.
Return values
0Port is unset or an error occurred.
nPort associated with this address in host native -endian.

Definition at line 784 of file Address.cc.

References mSocketAddr_.

◆ setAnyAddr()

void Ip::Address::setAnyAddr ( )

◆ setEmpty()

◆ setIPv4()

◆ setLocalhost()

void Ip::Address::setLocalhost ( )

Set object to contain the specific IP case LOCALHOST (format-neutral). see isLocalhost() for more detail.

Definition at line 255 of file Address.cc.

References Ip::EnableIpv6, mSocketAddr_, and v4_localhost.

Referenced by external_acl::external_acl(), idnsAddNameserver(), DiskdIOStrategy::init(), logfile_mod_daemon_open(), IcmpSquid::Open(), unlinkdInit(), and ~Address().

◆ setNoAddr()

◆ toHostStr()

unsigned int Ip::Address::toHostStr ( char *  buf,
const unsigned int  len 
) const

Return a properly hostname formatted copy of the address Provides a URL formatted version of the content. If buffer is not large enough the data is truncated silently. eg. 127.0.0.1 (IPv4) or [::1] (IPv6)

Parameters
bufAllocated buffer to write address to
lenbyte length of buffer available for writing.
Returns
amount of buffer filled.

Definition at line 852 of file Address.cc.

References buf, isIPv6(), p, and toStr().

Referenced by ConnStateData::fakeAConnectRequest(), Ftp::Server::handleUserRequest(), AnyP::Uri::host(), internalRemoteUri(), prepareAcceleratedURL(), prepareTransparentURL(), Comm::TcpAcceptor::status(), testIpAddress::testBugNullingDisplay(), toUrl(), and ~Address().

◆ toStr()

char * Ip::Address::toStr ( char *  buf,
const unsigned int  blen,
int  force = AF_UNSPEC 
) const

Return the ASCII equivalent of the address Semantically equivalent to the IPv4 inet_ntoa() eg. 127.0.0.1 (IPv4) or ::1 (IPv6) But for memory safety it requires a buffer as input instead of producing one magically. If buffer is not large enough the data is truncated silently.

Parameters
bufAllocated buffer to write address to
lenbyte length of buffer available for writing.
force(optional) require the IPA in a specific format.
Returns
pointer to buffer received.

toStr Given a buffer writes a readable ascii version of the IPA and/or port stored

Buffer must be of a size large enough to hold the converted address. This size is provided in the form of a global defined variable MAX_IPSTRLEN Should a buffer shorter be provided the string result will be truncated at the length of the available buffer.

A copy of the buffer is also returned for simple immediate display.

Definition at line 802 of file Address.cc.

References assert, buf, DBG_CRITICAL, debugs, getInAddr(), inet_ntop, isAnyAddr(), isIPv4(), isIPv6(), min(), mSocketAddr_, and NULL.

Referenced by Format::Format::assemble(), client_entry(), clientdbCutoffDenied(), clientdbEstablished(), clientdbGetInfo(), clientdbUpdate(), ClientInfo::ClientInfo(), Adaptation::Ecap::XactionRep::clientIpValue(), comm_connect_addr(), ErrorState::compileLegacyCode(), ErrorState::Dump(), dump_address(), dump_IpAddress_list(), fqdncache_gethostbyaddr(), fqdncache_nbgethostbyaddr(), ftpReadPORT(), AccessLogEntry::getLogClientIp(), getReverseString(), ProxyProtocol::Header::getValues(), Ftp::Server::handlePasvReply(), HttpStateData::httpBuildRequestHeader(), idnsPTRLookup(), ConnStateData::initiateTunneledRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), neighborIgnoreNonPeer(), netdbHashInsert(), netdbLookupAddr(), Comm::TcpAcceptor::oldAccept(), peerSourceHashSelectParent(), ConnStateData::postHttpsAccept(), printRadixNode(), Ftp::Client::sendEprt(), snmp_meshCtblFn(), snmp_meshPtblFn(), Log::Format::SquidIcap(), Log::Format::SquidNative(), testIpAddress::testBugNullingDisplay(), testIpAddress::testMasking(), testIpAddress::testtoStr(), toHostStr(), acl_ip_data::toStr(), and ~Address().

◆ toUrl()

char * Ip::Address::toUrl ( char *  buf,
unsigned int  len 
) const

Return the ASCII equivalent of the address:port combination Provides a URL formatted version of the content. If buffer is not large enough the data is truncated silently. eg. 127.0.0.1:80 (IPv4) or [::1]:80 (IPv6)

Parameters
bufAllocated buffer to write address:port to
lenbyte length of buffer available for writing.
Returns
pointer to buffer received.

Definition at line 884 of file Address.cc.

References buf, mSocketAddr_, NULL, p, port(), and toHostStr().

Referenced by Transport::Connect(), Security::ServerOptions::createSigningContexts(), Security::ServerOptions::initServerContexts(), PconnPool::key(), Security::KeyData::loadFromFiles(), neighborsHtcpClear(), peerCountMcastPeersStart(), ConnStateData::pinConnection(), process_request(), fde::remoteAddr(), Ident::Start(), Ftp::Server::start(), statClientRequests(), testIpAddress::testBugNullingDisplay(), testIpAddress::testtoUrl_fromInAddr(), testIpAddress::testtoUrl_fromSockAddr(), and ~Address().

Member Data Documentation

◆ MAX_IP4_STRLEN

const unsigned int Ip::Address::MAX_IP4_STRLEN = STRLEN_IP4R
staticprivate

Definition at line 340 of file Address.h.

◆ MAX_IP6_STRLEN

const unsigned int Ip::Address::MAX_IP6_STRLEN = STRLEN_IP6R
staticprivate

Definition at line 344 of file Address.h.

◆ mSocketAddr_

◆ STRLEN_IP4A

const unsigned int Ip::Address::STRLEN_IP4A = 16
staticprivate

Definition at line 337 of file Address.h.

◆ STRLEN_IP4R

const unsigned int Ip::Address::STRLEN_IP4R = 28
staticprivate

Definition at line 338 of file Address.h.

◆ STRLEN_IP4S

const unsigned int Ip::Address::STRLEN_IP4S = 21
staticprivate

Definition at line 339 of file Address.h.

◆ STRLEN_IP6A

const unsigned int Ip::Address::STRLEN_IP6A = 42
staticprivate

Definition at line 341 of file Address.h.

◆ STRLEN_IP6R

const unsigned int Ip::Address::STRLEN_IP6R = 75
staticprivate

Definition at line 342 of file Address.h.

◆ STRLEN_IP6S

const unsigned int Ip::Address::STRLEN_IP6S = 48
staticprivate

Definition at line 343 of file Address.h.

◆ v4_anyaddr

const struct in6_addr Ip::Address::v4_anyaddr
staticprivate

Definition at line 346 of file Address.h.

Referenced by isAnyAddr(), map4to6(), setEmpty(), and setIPv4().

◆ v4_localhost

const struct in6_addr Ip::Address::v4_localhost
staticprivate

Definition at line 345 of file Address.h.

Referenced by isLocalhost(), setEmpty(), setIPv4(), and setLocalhost().

◆ v4_noaddr

const struct in6_addr Ip::Address::v4_noaddr
staticprivate

Definition at line 347 of file Address.h.

Referenced by isNoAddr(), map4to6(), setEmpty(), and setIPv4().

◆ v6_noaddr

const struct in6_addr Ip::Address::v6_noaddr
staticprivate

Definition at line 348 of file Address.h.

Referenced by isNoAddr(), and setEmpty().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors