Loading...
Searching...
No Matches
XrdNetAddrInfo Class Reference

`#include <XrdNetAddrInfo.hh>`

Inheritance diagram for XrdNetAddrInfo:
Collaboration diagram for XrdNetAddrInfo:

## Classes

struct | LocInfo

## Public Types

enum | fmtUse { fmtAuto =0 , fmtName , fmtAddr , fmtAdv6 }
enum | IPType { IPv4 = AF_INET , IPv6 = AF_INET6 , IPuX = AF_UNIX }

## Public Member Functions

| XrdNetAddrInfo ()
| Constructor.
| XrdNetAddrInfo (const XrdNetAddrInfo *addr)
| XrdNetAddrInfo (XrdNetAddrInfo const &oP)
| Copy constructor.
| ~XrdNetAddrInfo ()
| Destructor.
const char * | Dialect ()
int | Family () const
int | Format (char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
bool | isIPType (IPType ipType) const
bool | isLoopback ()
bool | isMapped () const
bool | isPrivate ()
bool | isRegistered ()
bool | isUsingTLS ()
const struct LocInfo * | Location ()
const char * | Name (const char *eName=0, const char **eText=0)
const XrdNetSockAddr * | NetAddr ()
XrdNetAddrInfo & | operator= (XrdNetAddrInfo const &rhs)
| Assignment operator.
int | Port ()
int | Protocol ()
int | Same (const XrdNetAddrInfo *ipAddr, bool plusPort=false)
const sockaddr * | SockAddr ()
int | SockFD ()
SOCKLEN_t | SockSize ()

## Static Public Member Functions

static bool | isHostName (const char *name)

## Static Public Attributes

static const int | noPort = 0x0000001
| Do not add port number.
static const int | noPortRaw = 0x0000002
| Use raw address format (no port).
static const int | old6Map4 = 0x0000004
| Use deprecated IPV6 mapped format.
static const int | prefipv4 = 0x0000008
| Use if mapped IPV4 actual format.

## Protected Member Functions

char * | LowCase (char *str)
int | QFill (char *bAddr, int bLen)
int | Resolve ()

## Protected Attributes

union { |
struct sockaddr * | sockAddr
struct sockaddr_un * | unixPipe
}; |
LocInfo | addrLoc
unsigned short | addrSize
char * | hostName
XrdNetSockAddr | IP
unsigned char | protFlgs
const char * | protName
unsigned char | protType
int | sockNum

## Static Protected Attributes

static XrdNetCache * | dnsCache = 0
static const char | isTLS = 0x01
| Location using TLS.

## Detailed Description

Definition at line 53 of file XrdNetAddrInfo.hh.

## Member Enumeration Documentation

## fmtUse

enum XrdNetAddrInfo::fmtUse

Format our address into a supplied buffer with one of the following layouts (the ':<port>' or ':/path' can be omitted if desired, see fmtOpts param): IP.xx: host_name:<port> IP.v4: a.b.c.d:<port> IP.4to6: [::ffff:a.b.c.d]:<port> | [::a.b.c.d]:<port> IP.v6: [a:b:c:d:e:f:g:h]:<port> IP.Unix: localhost:/<path>

Parameters

  bAddr | address of buffer for result
  bLen | length of buffer
  fmtType | specifies the type of format desired via fmtUse enum.
  fmtOpts | additional formatting options (can be or'd): noPort - do not append the port number to the address. noPortRaw - no port and no brackets for IPv6. old6Map4 - use deprecated IPV6 mapped format '[::x.x.x.x]'

Returns
  Success: The number of characters (less null) in Buff.
  Failure: 0 (buffer is too small or not a valid address). However, if bLen > 0 the buffer will contain a null terminated string of up to 8 question marks.

Enumerator
fmtAuto | Hostname if already resolved o/w use fmtAddr.
fmtName | Hostname if it is resolvable o/w use fmtAddr.
fmtAddr | Address using suitable ipv4 or ipv6 format.
fmtAdv6 |

Definition at line 99 of file XrdNetAddrInfo.hh.

{fmtAuto=0,
fmtName,
fmtAddr,
fmtAdv6};
XrdNetAddrInfo::fmtAddr
@ fmtAddr
Address using suitable ipv4 or ipv6 format.
Definition XrdNetAddrInfo.hh:101
XrdNetAddrInfo::fmtName
@ fmtName
Hostname if it is resolvable o/w use fmtAddr.
Definition XrdNetAddrInfo.hh:100
XrdNetAddrInfo::fmtAuto
@ fmtAuto
Hostname if already resolved o/w use fmtAddr.
Definition XrdNetAddrInfo.hh:99
XrdNetAddrInfo::fmtAdv6
@ fmtAdv6
Definition XrdNetAddrInfo.hh:102

## IPType

enum XrdNetAddrInfo::IPType

Indicate whether or not our address is if the desired type.

Parameters

  ipType | The IP address version to test (see enum below).

Returns
  True: This is the address version of ipType.
  False: This is not the address version of ipType.

Enumerator
IPv4 |
IPv6 |
IPuX |

Definition at line 144 of file XrdNetAddrInfo.hh.

{IPv4 = AF_INET, IPv6 = AF_INET6, IPuX = AF_UNIX};
XrdNetAddrInfo::IPv4
@ IPv4
Definition XrdNetAddrInfo.hh:144
XrdNetAddrInfo::IPv6
@ IPv6
Definition XrdNetAddrInfo.hh:144
XrdNetAddrInfo::IPuX
@ IPuX
Definition XrdNetAddrInfo.hh:144

## Constructor & Destructor Documentation

## XrdNetAddrInfo() [1/3]

XrdNetAddrInfo::XrdNetAddrInfo | ( | XrdNetAddrInfo const & | oP | ) |

inline

Copy constructor.

Definition at line 326 of file XrdNetAddrInfo.hh.

{hostName = 0;
unixPipe = 0;
*this = oP;
}
XrdNetAddrInfo::hostName
char * hostName
Definition XrdNetAddrInfo.hh:363

References XrdNetAddrInfo(), and hostName.

Referenced by XrdNetAddr::XrdNetAddr(), XrdNetAddr::XrdNetAddr(), XrdNetAddr::XrdNetAddr(), XrdNetAddr::XrdNetAddr(), XrdNetAddr::XrdNetAddr(), XrdNetAddr::XrdNetAddr(), XrdNetAddrInfo(), XrdNetAddrInfo(), operator=(), and Same().

Here is the call graph for this function:
Here is the caller graph for this function:

## XrdNetAddrInfo() [2/3]

XrdNetAddrInfo::XrdNetAddrInfo | ( |  | ) |

inline

Constructor.

Definition at line 336 of file XrdNetAddrInfo.hh.

: hostName(0), addrSize(0), protType(0),
protFlgs(0), sockNum(0), protName(0)
{IP.Addr.sa_family = 0;
sockAddr = &IP.Addr;
}
XrdNetAddrInfo::protName
const char * protName
Definition XrdNetAddrInfo.hh:369
XrdNetAddrInfo::protFlgs
unsigned char protFlgs
Definition XrdNetAddrInfo.hh:367
XrdNetAddrInfo::IP
XrdNetSockAddr IP
Definition XrdNetAddrInfo.hh:359
XrdNetAddrInfo::protType
unsigned char protType
Definition XrdNetAddrInfo.hh:366
XrdNetAddrInfo::addrSize
unsigned short addrSize
Definition XrdNetAddrInfo.hh:365
XrdNetAddrInfo::sockNum
int sockNum
Definition XrdNetAddrInfo.hh:368

References addrSize, hostName, IP, protFlgs, protName, protType, and sockNum.

## XrdNetAddrInfo() [3/3]

XrdNetAddrInfo::XrdNetAddrInfo | ( | const XrdNetAddrInfo * | addr | ) |

inline

Definition at line 342 of file XrdNetAddrInfo.hh.

: hostName(0) {*this = *addr;}

References XrdNetAddrInfo(), and hostName.

Here is the call graph for this function:

## ~XrdNetAddrInfo()

XrdNetAddrInfo::~XrdNetAddrInfo | ( |  | ) |

inline

Destructor.

Definition at line 348 of file XrdNetAddrInfo.hh.

{if (hostName) free(hostName);
if (sockAddr != &IP.Addr) delete unixPipe;
}

References hostName, and IP.

## Member Function Documentation

## Dialect()

const char * XrdNetAddrInfo::Dialect | ( |  | ) |

inline

Provide the protocol languag being spoken (e.g. xroot, http, etc).

Returns
  Pointer to the protocol language being used. If unknown, nil ia returned. Use the isUsingTLS() method to see if a secure version of the protocol is being used.

Definition at line 65 of file XrdNetAddrInfo.hh.

{return protName;}

References protName.

Referenced by XrdCmsRedirLocal::Locate().

Here is the caller graph for this function:

## Family()

int XrdNetAddrInfo::Family | ( |  | ) | const

inline

Provide our address family.

Returns
  Success: Returns AF_INET, AF_INET6, or AF_UNIX. Failure: Returns 0, address is not valid.

Definition at line 74 of file XrdNetAddrInfo.hh.

{return static_cast<int>(IP.Addr.sa_family);}

References IP.

## Format()

int XrdNetAddrInfo::Format | ( | char * | bAddr,
|  | int | bLen,
|  | fmtUse | fmtType = fmtAuto,
|  | int | fmtOpts = 0 )

Definition at line 81 of file XrdNetAddrInfo.cc.

{
const char *pFmt = "]:%d";
int totLen, n, pNum, addBrak = 0;
int omitP = (fmtOpts & (noPort|noPortRaw));
int ipRaw = (fmtOpts & noPortRaw);
int ipOld = fmtOpts & (old6Map4 | prefipv4);
// Handle the degenerative case first
//
if (IP.Addr.sa_family == AF_UNIX)
{n = (omitP ? snprintf(bAddr, bLen, "localhost")
: snprintf(bAddr, bLen, "localhost:%s", unixPipe->sun_path));
return (n < bLen ? n : QFill(bAddr, bLen));
}
// Grab the potr. The port number is the same position and same size regardless
// of address type.
//
pNum = ntohs(IP.v4.sin_port);
// Resolve address if need be and return result if possible
//
if (theFmt == fmtName || theFmt == fmtAuto)
{if (!hostName && dnsCache && !(hostName = dnsCache->Find(this))
&& theFmt == fmtName) Resolve();
if (hostName)
{n = (omitP ? snprintf(bAddr, bLen, "%s", hostName)
: snprintf(bAddr, bLen, "%s:%d", hostName, pNum));
return (n < bLen ? n : QFill(bAddr, bLen));
}
theFmt = fmtAddr;
}
// Check if we can now produce an address format quickly. We used assume that
// the hostname was an address if it started with a non-alpha. But this does
// not correspond to RFC 1178 and RFC 3696, among others. We now only use
// the optimization path if the name is actually an IPV6/mapped4 address.
//
if (hostName && *hostName == '[' && !ipOld)
{n = (omitP ? snprintf(bAddr, bLen, "%s", hostName)
: snprintf(bAddr, bLen, "%s:%d", hostName, pNum));
return (n < bLen ? n : QFill(bAddr, bLen));
}
// Format address
//
if (IP.Addr.sa_family == AF_INET6)
{if (bLen < (INET6_ADDRSTRLEN+2)) return QFill(bAddr, bLen);
if (ipOld && IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr))
{ if (fmtOpts & prefipv4) {n = 0; pFmt = ":%d";}
else if (ipRaw) {strcpy(bAddr, "::"); n = 2;}
else {strcpy(bAddr, "[::"); n = 3; addBrak=1;}
if (!inet_ntop(AF_INET, &IP.v6.sin6_addr.s6_addr32[3],
bAddr+n, bLen-n)) return QFill(bAddr, bLen);
} else {
if (!ipRaw) {*bAddr = '['; n = 1; addBrak = 1;}
else n = 0;
if (!inet_ntop(AF_INET6,&(IP.v6.sin6_addr),bAddr+n,bLen-n))
return QFill(bAddr, bLen);
}
}
else if (IP.Addr.sa_family == AF_INET)
{if (theFmt != fmtAdv6) {n = 0; pFmt = ":%d";}
else {if (bLen < (INET_ADDRSTRLEN+9)) return QFill(bAddr, bLen);
if (fmtOpts & old6Map4) {strcpy(bAddr, "[::"); n = 3;}
else {strcpy(bAddr, "[::ffff:"); n = 8;}
if (ipRaw) {strcpy(bAddr, bAddr+1); n--;}
addBrak = 1;
}
if (!inet_ntop(AF_INET, &(IP.v4.sin_addr),bAddr+n,bLen-n))
return QFill(bAddr, bLen);
}
else return QFill(bAddr, bLen);
// Recalculate buffer position and length
//
totLen = strlen(bAddr); bAddr += totLen; bLen -= totLen;
// Process when no port number wanted
//
if (omitP)
{if (addBrak)
{if (bLen < 2) return QFill(bAddr, bLen);
*bAddr++ = ']'; *bAddr = 0; totLen++;
}
return totLen;
}
// Add the port number and return result
//
if ((n = snprintf(bAddr, bLen, pFmt, pNum)) >= bLen)
return QFill(bAddr, bLen);
return totLen+n;
}
XrdNetAddrInfo::dnsCache
static XrdNetCache * dnsCache
Definition XrdNetAddrInfo.hh:357
XrdNetAddrInfo::noPort
static const int noPort
Do not add port number.
Definition XrdNetAddrInfo.hh:104
XrdNetAddrInfo::old6Map4
static const int old6Map4
Use deprecated IPV6 mapped format.
Definition XrdNetAddrInfo.hh:106
XrdNetAddrInfo::noPortRaw
static const int noPortRaw
Use raw address format (no port).
Definition XrdNetAddrInfo.hh:105
XrdNetAddrInfo::prefipv4
static const int prefipv4
Use if mapped IPV4 actual format.
Definition XrdNetAddrInfo.hh:107
XrdNetAddrInfo::QFill
int QFill(char *bAddr, int bLen)
Definition XrdNetAddrInfo.cc:356
XrdNetAddrInfo::Resolve
int Resolve()
Definition XrdNetAddrInfo.cc:373

References dnsCache, fmtAddr, fmtAdv6, fmtAuto, fmtName, hostName, IP, noPort, noPortRaw, old6Map4, prefipv4, QFill(), and Resolve().

Referenced by XrdBwm::XrdBwm(), XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdInet::Accept(), XrdLinkCtl::Alloc(), XrdNetSecurity::Authorize(), XrdNetPMarkCfg::Config(), XrdNetIF::GetIF(), XrdSecServer::getParms(), XrdCmsManList::getRef(), XrdSsiClientProvider::GetService(), XrdNetUtils::GetSokInfo(), XrdNetUtils::IPFormat(), and Resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

## isHostName()

bool XrdNetAddrInfo::isHostName | ( | const char * | name | ) |

static

Indicate whether or not a string is a possible hostname and not IP address. The return value does not aimply any kind of validity. For instance, a false return indicates this is not a valid hostname does not mean it is a valid IP address.

Parameters

  name | The string to check.

Returns
  True: This is a possible hostname (i.e. not IP address).
  False: This is not a possible hostname.

Definition at line 278 of file XrdNetAddrInfo.cc.

{
const char *dot;
int dnum;
// First check for Iv6 format or hostname
//
if (*name == '[') return false;
if (!isdigit(*name)) return true;
// The IPv4 case is more complicated. The fastest way here is this is a
// host name if there are no dots or if the last component is not a digit
// according to the RFC spec.
//
if (!(dot = rindex(name, '.')) || !isdigit(*(dot+1))) return true;
// We are not out of the woods yet. Now we need to do a full check.
//
name++; dnum = 0;
while(*name)
{if (*name == '.') dnum++;
else if (!isdigit(*name)) return true;
name++;
}
return (dnum == 3 ? false : true);
}

Referenced by XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdNetPMarkCfg::Begin(), isRegistered(), XrdNetAddr::Register(), and XrdNetAddr::Set().

Here is the caller graph for this function:

## isIPType()

bool XrdNetAddrInfo::isIPType | ( | IPType | ipType | ) | const

inline

Definition at line 146 of file XrdNetAddrInfo.hh.

{return IP.Addr.sa_family == ipType;}

References IP.

Referenced by XrdNetUtils::GetSokInfo(), and XrdNetIF::SetIF().

Here is the caller graph for this function:

## isLoopback()

bool XrdNetAddrInfo::isLoopback | ( |  | ) |

Indicate whether or not our address is the loopback address. Use this method to gaurd against UDP packet spoofing.

Returns
  True: This is the loopback address.
  False: This is not the loopback address.

Definition at line 181 of file XrdNetAddrInfo.cc.

{
// Check for loopback address
//
if (IP.Addr.sa_family == AF_INET)
return !memcmp(&IP.v4.sin_addr.s_addr, &lbVal[12], 1);
if (IP.Addr.sa_family == AF_INET6)
return !memcmp(&IP.v6.sin6_addr, &in6addr_loopback, sizeof(in6_addr))
|| !memcmp(&IP.v6.sin6_addr, lbVal, sizeof(lbVal));
return false;
}

References IP.

## isMapped()

bool XrdNetAddrInfo::isMapped | ( |  | ) | const

inline

Indicate whether or not our address is an IPv4 mapped to IPv6 address.

Returns
  True: The address is a mapped IPv4 address. False: The address is not a mapped IPv4 address.

Definition at line 155 of file XrdNetAddrInfo.hh.

{return IP.Addr.sa_family == AF_INET6
&& IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr);
}

References IP.

Referenced by XrdNetUtils::GetSokInfo(), Same(), and XrdNetIF::SetIF().

Here is the caller graph for this function:

## isPrivate()

bool XrdNetAddrInfo::isPrivate | ( |  | ) |

Indicate whether or not our address is private.

Returns
  True: This address is private. False: This address is not private.

Definition at line 200 of file XrdNetAddrInfo.cc.

{
unsigned char *ipV4 = 0;
// For IPV6 addresses we will use the macro unless it is mapped
//
if (IP.Addr.sa_family == AF_INET6)
{if ((IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr)))
ipV4 = (unsigned char *)&IP.v6.sin6_addr.s6_addr32[3];
else {if ((IN6_IS_ADDR_LINKLOCAL(&IP.v6.sin6_addr))
|| (IN6_IS_ADDR_SITELOCAL(&IP.v6.sin6_addr))
|| (IN6_IS_ADDR_UNIQLOCAL(&IP.v6.sin6_addr))
|| (IN6_IS_ADDR_LOOPBACK (&IP.v6.sin6_addr))) return true;
return false;
}
}
// If this is not an IPV4 address then we will consider it private
//
if (!ipV4)
{if (IP.Addr.sa_family != AF_INET) return true;
ipV4 = (unsigned char *)&IP.v4.sin_addr.s_addr;
}
// For IPV4 we use the RFC definition of private. Note that this includes
// mapped addresses which, as odd as it is, we could get.
//
if (ipV4[0] == 10
|| (ipV4[0] == 172 && ipV4[1] >= 16 && ipV4[1] <= 31)
|| (ipV4[0] == 192 && ipV4[1] == 168)
|| (ipV4[0] == 169 && ipV4[1] == 254)
|| ipV4[0] == 127) return true;
// Not a local address
//
return false;
}
IN6_IS_ADDR_UNIQLOCAL
#define IN6_IS_ADDR_UNIQLOCAL(a)
Definition XrdNetAddrInfo.cc:63

References IN6_IS_ADDR_UNIQLOCAL, and IP.

Referenced by XrdNetPMarkCfg::Begin(), XrdNetIF::GetIF(), XrdNetIF::InDomain(), XrdCmsRedirLocal::Locate(), and XrdNetIF::SetIF().

Here is the caller graph for this function:

## isRegistered()

bool XrdNetAddrInfo::isRegistered | ( |  | ) |

Indicate whether or not our address is registered in the DNS.

Returns
  True: This address is registered. False: This address is not registered.

Definition at line 242 of file XrdNetAddrInfo.cc.

{
const char *hName;
// Simply see if we can resolve this name
//
if (!(hName = Name())) return false;
return isHostName(hName);
}
XrdNetAddrInfo::isHostName
static bool isHostName(const char *name)
Definition XrdNetAddrInfo.cc:278
XrdNetAddrInfo::Name
const char * Name(const char *eName=0, const char **eText=0)
Definition XrdNetAddrInfo.cc:309

References isHostName(), and Name().

Referenced by XrdConfig::Configure(), and XrdNetIF::SetIF().

Here is the call graph for this function:
Here is the caller graph for this function:

## isUsingTLS()

bool XrdNetAddrInfo::isUsingTLS | ( |  | ) |

Indicate whether or not the endpoint is using TLS for communications.

Returns
  True: This address is using TLS. False: This address is not using TLS.

Definition at line 256 of file XrdNetAddrInfo.cc.

{
return (protFlgs & isTLS) != 0;
}
XrdNetAddrInfo::isTLS
static const char isTLS
Location using TLS.
Definition XrdNetAddrInfo.hh:373

References isTLS, and protFlgs.

Referenced by XrdSecProtocolztnObject().

Here is the caller graph for this function:

## Location()

const struct LocInfo * XrdNetAddrInfo::Location | ( |  | ) |

inline

Definition at line 210 of file XrdNetAddrInfo.hh.

{return (addrLoc.Country[0] ? &addrLoc : 0);}
XrdNetAddrInfo::addrLoc
LocInfo addrLoc
Definition XrdNetAddrInfo.hh:364

References addrLoc.

## LowCase()

char * XrdNetAddrInfo::LowCase | ( | char * | str | ) |

protected

Definition at line 265 of file XrdNetAddrInfo.cc.

{
unsigned char *sp = (unsigned char*)str;
while(*sp) {if (isupper((int)*sp)) *sp = (char)tolower((int)*sp); sp++;}
return str;
}

Referenced by Resolve(), XrdNetAddr::Set(), and XrdNetAddr::Set().

Here is the caller graph for this function:

## Name()

const char * XrdNetAddrInfo::Name | ( | const char * | eName = 0,
|  | const char ** | eText = 0 )

Convert our IP address to the corresponding [host] name.

Parameters

  eName | value to return when the name cannot be determined.
  eText | when not null, the reason for a failure is returned.

Returns
  Success: Pointer to the name or ip address with eText, if supplied, set to zero. The memory is owned by the object and is deleted when the object is deleted or Set() is called. Failure: eName param and if eText is not zero, returns a pointer to a message describing the reason for the failure. The message is in persistent storage and cannot be modified.

Definition at line 309 of file XrdNetAddrInfo.cc.

{
int rc;
// Preset errtxt to zero
//
if (eText) *eText = 0;
// Check for unix family which is equal to localhost.
//
if (IP.Addr.sa_family == AF_UNIX) return "localhost";
// If we already translated this name, just return the translation
//
if (hostName || (dnsCache && (hostName = dnsCache->Find(this))))
return hostName;
// Try to resolve this address
//
if (!(rc = Resolve())) return hostName;
// We failed resolving this address
//
if (eText) *eText = gai_strerror(rc);
return eName;
}

References dnsCache, hostName, IP, and Resolve().

Referenced by XrdBwm::XrdBwm(), XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdInet::Accept(), XrdDigAuth::Authorize(), XrdNetSecurity::Authorize(), XrdOfsTPC::Authorize(), XrdNetPMarkCfg::Begin(), XrdConfig::Configure(), XrdFrmConfig::Configure(), XrdInet::Connect(), XrdNet::Connect(), XrdPosixAdmin::FanOut(), XrdSecServer::getParms(), XrdNetUtils::Hosts(), XrdNetIF::InDomain(), XrdSsiFileResource::Init(), XrdOucReqID::isMine(), isRegistered(), main(), XrdCmsManager::Rerun(), XrdAccAccess::Resolve(), XrdNetMsg::retErr(), XrdMpxOut::Run(), XrdOfsTPCInfo::Set(), XrdNetIF::SetIF(), XrdTlsNotary::Validate(), XrdOfsTPC::Verify(), XrdFfsMisc_get_list_of_data_servers(), XrdFfsMisc_getNameByAddr(), and XrdSecProtocolsssObject().

Here is the call graph for this function:
Here is the caller graph for this function:

## NetAddr()

const XrdNetSockAddr * XrdNetAddrInfo::NetAddr | ( |  | ) |

inline

Provide a pointer to our socket address suitable for use in calls to methods that require our internal format of sock addr. A value is only returned for IPV6/4 addresses and is nill otherwise. The pointer refers to memory allocated by this object and becomes invalid should the object be deleted. Use SockSize() to get its logical length.

Definition at line 237 of file XrdNetAddrInfo.hh.

{return (sockAddr == (void *)&IP ? &IP : 0);}

References IP.

Referenced by XrdOssPath::InitPrefix(), and XrdNetPMarkFF::Start().

Here is the caller graph for this function:

## operator=()

XrdNetAddrInfo & XrdNetAddrInfo::operator= | ( | XrdNetAddrInfo const & | rhs | ) |

inline

Assignment operator.

Definition at line 303 of file XrdNetAddrInfo.hh.

{if (&rhs != this)
{memmove(&IP, &rhs.IP, sizeof(IP));
addrSize = rhs.addrSize; sockNum = rhs.sockNum;
protType = rhs.protType;
protFlgs = rhs.protFlgs;
protName = rhs.protName;
if (hostName) free(hostName);
hostName = (rhs.hostName ? strdup(rhs.hostName):0);
addrLoc = rhs.addrLoc;
if (rhs.sockAddr != &rhs.IP.Addr)
{if (!unixPipe || sockAddr == &IP.Addr)
unixPipe = new sockaddr_un;
memcpy(unixPipe, rhs.unixPipe, sizeof(sockaddr_un));
} else sockAddr = &IP.Addr;
}
return *this;
}

References XrdNetAddrInfo(), XrdNetSockAddr::Addr, addrLoc, addrSize, hostName, IP, protFlgs, protName, protType, and sockNum.

Here is the call graph for this function:

## Port()

int XrdNetAddrInfo::Port | ( |  | ) |

Return the port number for our address.

Returns
  Success: The port number, which may be 0 if not set. Failure: -1 address is not an internet address or port is invalid.

Definition at line 340 of file XrdNetAddrInfo.cc.

{
// Make sure we have a proper address family here
//
if (IP.Addr.sa_family != AF_INET && IP.Addr.sa_family != AF_INET6)
return -1;
// Return port number
//
return ntohs(IP.v6.sin6_port);
}

References IP.

## Protocol()

int XrdNetAddrInfo::Protocol | ( |  | ) |

inline

Provide our protocol family.

Returns
  Success: Returns PF_INET, PF_INET6, or PF_UNIX. Failure: Returns 0, address is not valid.

Definition at line 255 of file XrdNetAddrInfo.hh.

{return static_cast<int>(protType);}

References protType.

## QFill()

int XrdNetAddrInfo::QFill | ( | char * | bAddr,
|  | int | bLen )

protected

Definition at line 356 of file XrdNetAddrInfo.cc.

{
static const char quests[] = "????????";
// Insert up to 8 question marks
//
if (bLen)
{strncpy(bAddr, quests, bLen);
bAddr[bLen-1] = 0;
}
return 0;
}

Referenced by Format().

Here is the caller graph for this function:

## Resolve()

int XrdNetAddrInfo::Resolve | ( |  | ) |

protected

Definition at line 373 of file XrdNetAddrInfo.cc.

{
char hBuff[NI_MAXHOST];
int n, rc;
// Free up hostname here
//
if (hostName) {free(hostName); hostName = 0;}
// Determine the actual size of the address structure
//
if (IP.Addr.sa_family == AF_INET ) n = sizeof(IP.v4);
else if (IP.Addr.sa_family == AF_INET6) n = sizeof(IP.v6);
else if (IP.Addr.sa_family == AF_UNIX )
{hostName = strdup("localhost");
return 0;
}
else return EAI_FAMILY;
// Do lookup of canonical name. If an error is returned we simply assume that
// the name is not resolvable and return the address as the host name.
//
if ((rc = getnameinfo(&IP.Addr, n, hBuff+1, sizeof(hBuff)-2, 0, 0, 0)))
{int ec = errno;
if (Format(hBuff, sizeof(hBuff), fmtAddr, noPort))
{hostName = strdup(hBuff); return 0;}
errno = ec;
return rc;
}
// Handle the case when the mapping returned an actual name or an address
// We always want numeric ipv6 addresses surrounded by brackets. Additionally,
// some implementations of getnameinfo() return the scopeid when a numeric
// address is returned. We check and remove it.
//
if (!index(hBuff+1, ':')) hostName = strdup(LowCase(hBuff+1));
else {char *perCent = index(hBuff+1, '%');
if (perCent) *perCent = 0;
n = strlen(hBuff+1);
hBuff[0] = '['; hBuff[n+1] = ']'; hBuff[n+2] = 0;
hostName = strdup(hBuff);
}
// Add the entry to the cache and return success
//
if (dnsCache) dnsCache->Add(this, hostName);
return 0;
}
ec
ec
Definition XrdSysFAttrSun.icc:100
XrdNetAddrInfo::Format
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
Definition XrdNetAddrInfo.cc:81
XrdNetAddrInfo::LowCase
char * LowCase(char *str)
Definition XrdNetAddrInfo.cc:265

References dnsCache, ec, fmtAddr, Format(), hostName, IP, LowCase(), and noPort.

Referenced by Format(), and Name().

Here is the call graph for this function:
Here is the caller graph for this function:

## Same()

int XrdNetAddrInfo::Same | ( | const XrdNetAddrInfo * | ipAddr,
|  | bool | plusPort = false )

Check if the IP address in this object is the same as the one passed.

Parameters

  ipAddr | points to the network address object to compare.
  plusPort | when true, port values must also match. In any case, both addresses must be of the same address family.

Returns
  Success: True (addresses are the same). Failure: False (addresses are not the same).

Note: implemented in terms of const version

Definition at line 432 of file XrdNetAddrInfo.cc.

{
static const int ipv4ASZ = sizeof(IP.v4.sin_addr);
bool isINet = IS_INET(MY_FAMILY) && IS_INET(UR_FAMILY);
// Do port comparison if requested and makes sense to do it
//
if (plusPort && isINet)
{in_port_t port1, port2;
port1 = (MY_FAMILY == AF_INET ? IP.v4.sin_port : IP.v6.sin6_port);
port2 = (UR_FAMILY == AF_INET ? ipAddr->IP.v4.sin_port
: ipAddr->IP.v6.sin6_port);
if (port1 != port2) return 0;
}
// If address families do not match, they are the same if the hostnames match.
// If we don't have a hostname and the addresses are convertable, we can
// compare the actual addresses.
//
if (MY_FAMILY != UR_FAMILY)
{if (!isINet) return 0;
if (hostName && ipAddr->hostName)
return !strcmp(hostName,ipAddr->hostName);
if (MY_FAMILY == AF_INET && ipAddr->isMapped())
return !memcmp(&IP.v4.sin_addr,
&(ipAddr->IP.v6.sin6_addr.s6_addr32[3]), ipv4ASZ);
if (isMapped() && UR_FAMILY == AF_INET)
return !memcmp(&IP.v6.sin6_addr.s6_addr32[3],
&(ipAddr->IP.v4.sin_addr), ipv4ASZ);
return 0;
}
// Now process to do the match
//
if (MY_FAMILY == AF_INET)
return !memcmp(&IP.v4.sin_addr, &(ipAddr->IP.v4.sin_addr), ipv4ASZ);
else if (MY_FAMILY == AF_INET6)
return !memcmp(&IP.v6.sin6_addr, &(ipAddr->IP.v6.sin6_addr),
sizeof(IP.v6.sin6_addr));
else if (MY_FAMILY == AF_UNIX)
return !strcmp(unixPipe->sun_path, ipAddr->unixPipe->sun_path);
return 0;
}
UR_FAMILY
#define UR_FAMILY
Definition XrdNetAddrInfo.cc:430
IS_INET
#define IS_INET(x)
Definition XrdNetAddrInfo.cc:426
MY_FAMILY
#define MY_FAMILY
Definition XrdNetAddrInfo.cc:428
XrdNetSockAddr::v6
struct sockaddr_in6 v6
Definition XrdNetSockAddr.hh:43
XrdNetSockAddr::v4
struct sockaddr_in v4
Definition XrdNetSockAddr.hh:44
XrdNetAddrInfo::isMapped
bool isMapped() const
Definition XrdNetAddrInfo.hh:155

References XrdNetAddrInfo(), hostName, IP, IS_INET, isMapped(), MY_FAMILY, UR_FAMILY, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.

Referenced by XrdNetAddr::Register().

Here is the call graph for this function:
Here is the caller graph for this function:

## SockAddr()

const sockaddr * XrdNetAddrInfo::SockAddr | ( |  | ) |

inline

Provide a pointer to our socket address suitable for use in calls to functions that require one (e.g. bind() etc). The pointer refers to memory allocated by this object and becomes invalid should the object be deleted or when Set() is called. Use SockSize() to get its length.

Definition at line 280 of file XrdNetAddrInfo.hh.

{return sockAddr;}

Referenced by XrdConfig::Configure(), XrdNetMsg::Send(), and XrdNetMsg::Send().

Here is the caller graph for this function:

## SockFD()

int XrdNetAddrInfo::SockFD | ( |  | ) |

inline

Get the associated file descriptor.

Returns
  The associated file descriptor. If negative, no association exists.

Definition at line 297 of file XrdNetAddrInfo.hh.

{return (sockNum ? sockNum : -1);}

References sockNum.

Referenced by XrdInet::Accept(), XrdLinkCtl::Alloc(), XrdHttpTpc::PMarkManager::beginPMarks(), XrdInet::Connect(), and XrdNetPMarkFF::Start().

Here is the caller graph for this function:

## SockSize()

SOCKLEN_t XrdNetAddrInfo::SockSize | ( |  | ) |

inline

Provide the length of our socket adress. Useful for system calls needing it.

Returns
  Success: Returns the length of the address returned by SockAddr(). Failure: Returns 0, address is not valid.

Definition at line 289 of file XrdNetAddrInfo.hh.

{return static_cast<SOCKLEN_t>(addrSize);}
SOCKLEN_t
#define SOCKLEN_t
Definition XrdSysPlatform.hh:269

References addrSize, and SOCKLEN_t.

Referenced by XrdNetMsg::Send(), and XrdNetMsg::Send().

Here is the caller graph for this function:

## Member Data Documentation

## [union]

union { ... } XrdNetAddrInfo

## addrLoc

LocInfo XrdNetAddrInfo::addrLoc

protected

Definition at line 364 of file XrdNetAddrInfo.hh.

Referenced by Location(), operator=(), and XrdNetAddr::SetLocation().

## addrSize

unsigned short XrdNetAddrInfo::addrSize

protected

Definition at line 365 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddrInfo(), operator=(), XrdNetAddr::Set(), XrdNetAddr::Set(), XrdNetAddr::Set(), XrdNetAddr::Set(), and SockSize().

## dnsCache

XrdNetCache * XrdNetAddrInfo::dnsCache = 0

static protected

Definition at line 357 of file XrdNetAddrInfo.hh.

Referenced by Format(), Name(), Resolve(), and XrdNetAddr::SetCache().

## hostName

char* XrdNetAddrInfo::hostName

protected

Definition at line 363 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddr::XrdNetAddr(), XrdNetAddrInfo(), XrdNetAddrInfo(), XrdNetAddrInfo(), ~XrdNetAddrInfo(), Format(), Name(), operator=(), XrdNetAddr::Register(), Resolve(), Same(), XrdNetAddr::Set(), XrdNetAddr::Set(), XrdNetAddr::Set(), and XrdNetAddr::Set().

## IP

XrdNetSockAddr XrdNetAddrInfo::IP

protected

Definition at line 359 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddrInfo(), ~XrdNetAddrInfo(), Family(), Format(), isIPType(), isLoopback(), isMapped(), isPrivate(), Name(), NetAddr(), operator=(), XrdNetAddr::Port(), Port(), Resolve(), Same(), XrdNetAddr::Set(), XrdNetAddr::Set(), XrdNetAddr::Set(), and XrdNetAddr::Set().

## isTLS

const char XrdNetAddrInfo::isTLS = 0x01

static protected

Location using TLS.

Definition at line 373 of file XrdNetAddrInfo.hh.

Referenced by isUsingTLS(), and XrdNetAddr::SetTLS().

## noPort

const int XrdNetAddrInfo::noPort = 0x0000001

static

Do not add port number.

Definition at line 104 of file XrdNetAddrInfo.hh.

Referenced by XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdInet::Accept(), XrdLinkCtl::Alloc(), XrdNetSecurity::Authorize(), Format(), XrdNetIF::GetIF(), XrdCl::AsyncSocketHandler::GetIpAddr(), XrdSecServer::getParms(), XrdNetUtils::IPFormat(), and Resolve().

## noPortRaw

const int XrdNetAddrInfo::noPortRaw = 0x0000002

static

Use raw address format (no port).

Definition at line 105 of file XrdNetAddrInfo.hh.

Referenced by Format(), and XrdNetUtils::GetSokInfo().

## old6Map4

const int XrdNetAddrInfo::old6Map4 = 0x0000004

static

Use deprecated IPV6 mapped format.

Definition at line 106 of file XrdNetAddrInfo.hh.

Referenced by XrdBwm::XrdBwm(), XrdLinkCtl::Alloc(), XrdNetSecurity::Authorize(), Format(), XrdCmsManList::getRef(), and XrdNetUtils::IPFormat().

## prefipv4

const int XrdNetAddrInfo::prefipv4 = 0x0000008

static

Use if mapped IPV4 actual format.

Definition at line 107 of file XrdNetAddrInfo.hh.

Referenced by Format(), and XrdNetUtils::GetSokInfo().

## protFlgs

unsigned char XrdNetAddrInfo::protFlgs

protected

Definition at line 367 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddrInfo(), isUsingTLS(), operator=(), and XrdNetAddr::SetTLS().

## protName

const char* XrdNetAddrInfo::protName

protected

Definition at line 369 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddrInfo(), Dialect(), operator=(), and XrdNetAddr::SetDialect().

## protType

unsigned char XrdNetAddrInfo::protType

protected

Definition at line 366 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddrInfo(), operator=(), Protocol(), XrdNetAddr::Set(), XrdNetAddr::Set(), XrdNetAddr::Set(), and XrdNetAddr::Set().

## sockNum

int XrdNetAddrInfo::sockNum

protected

Definition at line 368 of file XrdNetAddrInfo.hh.

Referenced by XrdNetAddrInfo(), operator=(), XrdNetAddr::Set(), XrdNetAddr::Set(), XrdNetAddr::Set(), and SockFD().

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

- XrdNetAddrInfo.hh
- XrdNetAddrInfo.cc