Loading...
Searching...
No Matches
XrdNetAddr Class Reference

`#include <XrdNetAddr.hh>`

Inheritance diagram for XrdNetAddr:
Collaboration diagram for XrdNetAddr:

## Public Member Functions

| XrdNetAddr ()
| Assignment operator and copy constructor are inherited, no need to define.
| XrdNetAddr (const sockaddr *addr)
| XrdNetAddr (const sockaddr_in *addr)
| XrdNetAddr (const sockaddr_in6 *addr)
| XrdNetAddr (const XrdNetAddr *addr)
| XrdNetAddr (int port)
| ~XrdNetAddr ()
| Destructor.
int | Port (int pNum=-1)
bool | Register (const char *hName)
const char * | Set (const char *hSpec, int &numIP, int maxIP, int pNum=PortInSpec, bool forUDP=false)
const char * | Set (const char *hSpec, int pNum=PortInSpec)
const char * | Set (const struct sockaddr *sockP, int sockFD=-1)
const char * | Set (int sockFD, bool peer=true)
const char * | Set (struct addrinfo *rP, int port, bool mapit=false)
void | SetDialect (const char *dP)
void | SetLocation (XrdNetAddrInfo::LocInfo &loc)
void | SetTLS (bool val)
Public Member Functions inherited from XrdNetAddrInfo
| 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 | DynDNS ()
static bool | IPV4Set ()
static void | SetCache (int keeptime)
static void | SetDynDNS (bool onoff)
static void | SetIPV4 ()
static void | SetIPV6 ()
Static Public Member Functions inherited from XrdNetAddrInfo
static bool | isHostName (const char *name)

## Static Public Attributes

static const int | PortInSpec = (int)0x80000000
Static Public Attributes inherited from XrdNetAddrInfo
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.

## Additional Inherited Members

Public Types inherited from XrdNetAddrInfo
enum | fmtUse { fmtAuto =0 , fmtName , fmtAddr , fmtAdv6 }
enum | IPType { IPv4 = AF_INET , IPv6 = AF_INET6 , IPuX = AF_UNIX }
Protected Member Functions inherited from XrdNetAddrInfo
char * | LowCase (char *str)
int | QFill (char *bAddr, int bLen)
int | Resolve ()
Protected Attributes inherited from XrdNetAddrInfo
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 inherited from XrdNetAddrInfo
static XrdNetCache * | dnsCache = 0
static const char | isTLS = 0x01
| Location using TLS.

## Detailed Description

Definition at line 41 of file XrdNetAddr.hh.

## Constructor & Destructor Documentation

## XrdNetAddr() [1/6]

XrdNetAddr::XrdNetAddr | ( |  | ) |

inline

Assignment operator and copy constructor are inherited, no need to define.

Constructor

Parameters

  addr | A pointer to an initialized and valid sockaddr or sockaddr compatible structure used to initialize the address.
  port | Uses the address of the current host and the speoified port number to initilize the address.

Definition at line 265 of file XrdNetAddr.hh.

: XrdNetAddrInfo() {}
XrdNetAddrInfo::XrdNetAddrInfo
XrdNetAddrInfo()
Constructor.
Definition XrdNetAddrInfo.hh:336

References XrdNetAddrInfo::XrdNetAddrInfo().

Referenced by XrdNetAddr(), Register(), and Set().

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

## XrdNetAddr() [2/6]

XrdNetAddr::XrdNetAddr | ( | const XrdNetAddr * | addr | ) |

inline

Definition at line 267 of file XrdNetAddr.hh.

: XrdNetAddrInfo(addr) {}

References XrdNetAddr(), and XrdNetAddrInfo::XrdNetAddrInfo().

Here is the call graph for this function:

## XrdNetAddr() [3/6]

XrdNetAddr::XrdNetAddr | ( | const sockaddr * | addr | ) |

inline

Definition at line 269 of file XrdNetAddr.hh.

: XrdNetAddrInfo()
{Set(addr);}
XrdNetAddr::Set
const char * Set(const char *hSpec, int pNum=PortInSpec)
Definition XrdNetAddr.cc:216

References XrdNetAddrInfo::XrdNetAddrInfo(), and Set().

Here is the call graph for this function:

## XrdNetAddr() [4/6]

XrdNetAddr::XrdNetAddr | ( | const sockaddr_in * | addr | ) |

inline

Definition at line 272 of file XrdNetAddr.hh.

: XrdNetAddrInfo()
{Set((sockaddr *)addr);}

References XrdNetAddrInfo::XrdNetAddrInfo(), and Set().

Here is the call graph for this function:

## XrdNetAddr() [5/6]

XrdNetAddr::XrdNetAddr | ( | const sockaddr_in6 * | addr | ) |

inline

Definition at line 275 of file XrdNetAddr.hh.

: XrdNetAddrInfo()
{Set((sockaddr *)addr);}

References XrdNetAddrInfo::XrdNetAddrInfo(), and Set().

Here is the call graph for this function:

## XrdNetAddr() [6/6]

XrdNetAddr::XrdNetAddr | ( | int | port | ) |

Definition at line 95 of file XrdNetAddr.cc.

: XrdNetAddrInfo()
{
const char *fqn = XrdNetIdentity::FQN();
// The host name might not be resolvable. If we have an fqn then either the
// name was manually set or we are using an IP address because reverse
// lookup did not work. If we have an fqn, then use it as the name. Otherwise,
// use localhost as that is always a safe fallback.
//
if (!fqn || Set(fqn, port))
{Set("localhost", port);
if (fqn)
{if (hostName) free(hostName);
hostName = strdup(fqn);
}
}
}
XrdNetAddrInfo::hostName
char * hostName
Definition XrdNetAddrInfo.hh:363
XrdNetIdentity::FQN
static const char * FQN(const char **etext=0)
Definition XrdNetIdentity.cc:187

References XrdNetAddrInfo::XrdNetAddrInfo(), XrdNetIdentity::FQN(), XrdNetAddrInfo::hostName, and Set().

Here is the call graph for this function:

## ~XrdNetAddr()

XrdNetAddr::~XrdNetAddr | ( |  | ) |

inline

Destructor.

Definition at line 284 of file XrdNetAddr.hh.

{}

## Member Function Documentation

## DynDNS()

bool XrdNetAddr::DynDNS | ( |  | ) |

inline static

Determine if dynamic DNS has been set.

Returns
  True Dynamic DNS has been set. False Dynamic DNS has not been set.

Definition at line 52 of file XrdNetAddr.hh.

{return dynDNS;}

Referenced by XrdCmsUtils::ParseMan().

Here is the caller graph for this function:

## IPV4Set()

bool XrdNetAddr::IPV4Set | ( |  | ) |

inline static

Determine if IPV4 mode has been set.

Returns
  True IPV4 mode has been set. False IPV4 mode has not been set.

Definition at line 61 of file XrdNetAddr.hh.

{return useIPV4;}

Referenced by XrdInet::BindSD(), and XrdConfig::Configure().

Here is the caller graph for this function:

## Port()

int XrdNetAddr::Port | ( | int | pNum = -1 | ) |

Optionally set and also returns the port number for our address.

Parameters

  pNum | when negative it only returns the current port. Otherwise, it is taken as the value to be set.

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 156 of file XrdNetAddr.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 if so wanted. The port location is the same regardless of
// the address family.
//
if (pNum < 0) return ntohs(IP.v6.sin6_port);
// Set port number if we have a valid address. The location of the port
// is the same regardless of address family.
//
if (pNum > 0xffff) return -1;
IP.v6.sin6_port = htons(static_cast<short>(pNum));
return pNum;
}
XrdNetAddrInfo::IP
XrdNetSockAddr IP
Definition XrdNetAddrInfo.hh:359

References XrdNetAddrInfo::IP.

Referenced by XrdBwm::XrdBwm(), XrdPosixAdmin::FanOut(), XrdNetUtils::Hosts(), XrdCmsManager::Rerun(), and Set().

Here is the caller graph for this function:

## Register()

bool XrdNetAddr::Register | ( | const char * | hName | ) |

Register a host name with this IP address. This is not MT-safe!

Parameters

  hName | -> to a true host name which should be fully qualified. One of the IP addresses registered to this name must match the IP address associated with this object.

Returns
  True: Specified name is now associated with this address. False: Nothing changed, registration could not be verified.

Definition at line 180 of file XrdNetAddr.cc.

{
XrdNetAddr *aListVec = 0;
int i, aListNum;
// Step one is to make sure the incoming name is not an address
//
if (!isHostName(hName)) return false;
// The next step is to get all of the IP addresses registered for this name
//
if (XrdNetUtils::GetAddrs(hName, &aListVec, aListNum,
XrdNetUtils::allIPMap, XrdNetUtils::NoPortRaw))
return false;
// In order to use the given name, one of the IP addresses in the list must
// match our address. This is about as secure we can get.
//
for (i = 0; i < aListNum; i++) {if (Same(&aListVec[i])) break;}
delete [] aListVec;
// If we didn't find a match, report it
//
if (i >= aListNum) return false;
// Replace current hostname with the wanted one
//
if (hostName) free(hostName);
hostName = strdup(hName);
return true;
}
XrdNetAddrInfo::isHostName
static bool isHostName(const char *name)
Definition XrdNetAddrInfo.cc:278
XrdNetAddrInfo::Same
int Same(const XrdNetAddrInfo *ipAddr, bool plusPort=false)
Definition XrdNetAddrInfo.cc:432
XrdNetAddr::XrdNetAddr
XrdNetAddr()
Assignment operator and copy constructor are inherited, no need to define.
Definition XrdNetAddr.hh:265
XrdNetUtils::NoPortRaw
static const int NoPortRaw
Definition XrdNetUtils.hh:150
XrdNetUtils::GetAddrs
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
Definition XrdNetUtils.cc:274
XrdNetUtils::allIPMap
@ allIPMap
Definition XrdNetUtils.hh:143

References XrdNetAddr(), XrdNetUtils::allIPMap, XrdNetUtils::GetAddrs(), XrdNetAddrInfo::hostName, XrdNetAddrInfo::isHostName(), XrdNetUtils::NoPortRaw, and XrdNetAddrInfo::Same().

Here is the call graph for this function:

## Set() [1/5]

const char * XrdNetAddr::Set | ( | const char * | hSpec,
|  | int & | numIP,
|  | int | maxIP,
|  | int | pNum = PortInSpec,
|  | bool | forUDP = false )

Return multiple addresses. This form can only be used on the first element of this object that has been allocated as an array. This method is useful for getting all of the aliases assigned to a dns entry. The file descriptor association is set to a negative value.

Parameters

  hSpec | 0 -> address is set to in6addr_any for binding via bind() !0 -> convert specification to an address. Valid formats: IP.v4: nnn.nnn.nnn.nnn[:<port>] IP.v6: [ipv6_addr][:<port>] IP.xx: name[:port] xx is determined by getaddrinfo()
  maxIP | number of elements in the array.
  numIP | the number of IP addresses actually set (returned value).
  pNum | >= 0 uses the value as the port number regardless of what is in hSpec, should it be supplied. However, if is present, it must be a valid port number or name. < 0 uses the positive value as the port number if the port number has not been specified in hSpec. **** When set to PortInSpec(the default, see below) the port number/name must be specified in hSpec. If it is not, an error is returned.
  forUDP | when true addresses are usable for UDP connections. Otherwise, they are for TCP connections.

Returns
  Success: 0 with numIP set to the number of elements set. Failure: the error message text describing the error and numIP is set to zero. The message is in persistent storage and cannot be modified.

Definition at line 343 of file XrdNetAddr.cc.

{
struct addrinfo *hP, *rP = 0, *pP, *nP;
XrdNetAddr *aVec = this;
const char *hnBeg, *hnEnd, *pnBeg, *pnEnd;
char hBuff[MAXHOSTNAMELEN+8];
int hLen, n;
// If only one address can be returned, just revert to standard processing
//
if (!hSpec || !isalpha(*hSpec) || maxIP < 2)
{const char *eMsg = Set(hSpec, pNum);
numIP = (eMsg ? 0 : 1);
return eMsg;
}
// Extract out host name
//
if (!XrdNetUtils::Parse(hSpec, &hnBeg, &hnEnd, &pnBeg, &pnEnd))
return "invalid host specification";
hLen = hnEnd - hnBeg;
if (hLen > MAXHOSTNAMELEN) return "host name too long";
strncpy(hBuff, hSpec, hLen); hBuff[hLen] = 0;
// Get the port number we will be setting
//
if (pnBeg == hnEnd)
{if (pNum == PortInSpec) return "port not specified";
if (pNum < 0) pNum = -pNum;
} else {
if (*pnEnd || !(n = XrdNetUtils::ServPort(pnBeg, optUDP)))
return "invalid port";
if (pNum < 0) pNum = n;
}
// Get all of the addresses
//
hP = (optUDP ? huntHintsUDP : huntHintsTCP);
n = getaddrinfo(hBuff, 0, hP, &rP);
if (n || !rP)
{if (rP) freeaddrinfo(rP);
return (n ? gai_strerror(n) : "host not found");
}
// Now self-referentially fill out ourselves with no duplicates
//
n = 0; pP = 0; nP = rP;
do {if (!pP || pP->ai_addrlen != nP->ai_addrlen
|| memcmp((const void *)pP->ai_addr, (const void *)nP->ai_addr,
nP->ai_addrlen)) {aVec[n].Set(nP, pNum); n++;}
pP = nP; nP = nP->ai_next;
} while(n < maxIP && nP);
// All done
//
numIP = n;
if (rP) freeaddrinfo(rP);
return 0;
}
eMsg
#define eMsg(x)
Definition XrdSecsssAdmin.cc:53
XrdNetAddr::PortInSpec
static const int PortInSpec
Definition XrdNetAddr.hh:112
XrdNetUtils::ServPort
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
Definition XrdNetUtils.cc:874
XrdNetUtils::Parse
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
Definition XrdNetUtils.cc:780

References XrdNetAddr(), eMsg, XrdNetUtils::Parse(), PortInSpec, XrdNetUtils::ServPort(), and Set().

Here is the call graph for this function:

## Set() [2/5]

const char * XrdNetAddr::Set | ( | const char * | hSpec,
|  | int | pNum = PortInSpec )

Definition at line 216 of file XrdNetAddr.cc.

{
static const char *badIPv4 = "invalid IPv4 address";
static const char *badIPv6 = "invalid IPv6 address";
static const char *badIP64 = "IPv6 address not IPv4 representable";
static const char *badName = "invalid host name";
static const int map46ID = htonl(0x0000ffff);
const char *Colon, *iP;
char aBuff[NI_MAXHOST+INET6_ADDRSTRLEN];
int aLen, n;
bool mapIt;
// Clear translation if set (note unixPipe & sockAddr are the same).
//
if (hostName) {free(hostName); hostName = 0;}
if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
memset(&IP, 0, sizeof(IP));
addrSize = sizeof(sockaddr_in6);
// Check for any address setting
//
if (!hSpec)
{if (useIPV4)
{IP.v4.sin_family = AF_INET;
IP.v4.sin_addr.s_addr = INADDR_ANY;
protType = PF_INET;
addrSize = sizeof(sockaddr_in);
} else {
IP.v6.sin6_family = AF_INET6;
IP.v6.sin6_addr = in6addr_any;
protType = PF_INET6;
}
if (pNum < 0) pNum= -pNum;
IP.v6.sin6_port = htons(static_cast<short>(pNum));
return 0;
}
// Check for Unix type address here
//
if (*hSpec == '/')
{if (strlen(hSpec) >= sizeof(unixPipe->sun_path)) return "path too long";
unixPipe = new sockaddr_un;
strcpy(unixPipe->sun_path, hSpec);
unixPipe->sun_family = IP.Addr.sa_family = AF_UNIX;
addrSize = sizeof(sockaddr_un);
protType = PF_UNIX;
return 0;
}
// Do length check to see if we can fit the host name in our buffer.
//
aLen = strlen(hSpec);
if (aLen >= (int)sizeof(aBuff)) return "host id too long";
// Convert the address as appropriate. Note that we do accept RFC5156 deprecated
// IPV4 mapped IPV6 addresses(i.e. [::a.b.c.d]. This is historical.
//
if (*hSpec == '[')
{const char *Brak = index(hSpec+1, ']');
if (!Brak) return badIPv6;
Colon = Brak+1;
if (!(*Colon)) Colon = 0;
else if (*Colon != ':') return badIPv6;
aLen = Brak - (hSpec+1);
if (aLen >= INET6_ADDRSTRLEN) return badIPv6;
mapIt = (*(hSpec+1) == ':' && *(hSpec+2) == ':'
&& *(hSpec+3) >= '0' && *(hSpec+3) <= '9'
&& (iP = index(hSpec+4, '.')) && iP < Brak);
strncpy(aBuff, hSpec+1, aLen); aBuff[aLen] = 0;
if (inet_pton(AF_INET6,aBuff,&IP.v6.sin6_addr) != 1) return badIPv6;
if (mapIt) IP.v6.sin6_addr.s6_addr32[2] = map46ID;
IP.v6.sin6_family = AF_INET6;
protType = PF_INET6;
if (useIPV4 && !Map64()) return badIP64;
}
else if (!isHostName(hSpec))
{if ((Colon = index(hSpec, ':')))
{aLen = Colon - hSpec;
if (aLen >= INET_ADDRSTRLEN) return badIPv4;
strncpy(aBuff, hSpec, aLen); aBuff[aLen] = 0; iP = aBuff;
} else iP = hSpec;
if (inet_pton(AF_INET ,iP, &IP.v6.sin6_addr.s6_addr32[3]) != 1)
return badIPv4;
IP.v6.sin6_addr.s6_addr32[2] = map46ID;
IP.v6.sin6_family = AF_INET6;
protType = PF_INET6;
if (useIPV4 && !Map64()) return badIPv4;
}
else if (*hSpec == 0) return badName;
else {struct addrinfo *rP = 0;
if ((Colon = index(hSpec, ':')))
{aLen = Colon - hSpec;
if (aLen > MAXHOSTNAMELEN) return badName;
strncpy(aBuff, hSpec, aLen); aBuff[aLen] = 0; iP = aBuff;
} else iP = hSpec;
n = getaddrinfo(iP, 0, hostHints, &rP);
if (n || !rP)
{if (rP) freeaddrinfo(rP);
if (n == EAI_NONAME && dynDNS)
return "Dynamic name or service not yet registered";
return (n ? gai_strerror(n) : "host not found");
}
memcpy(&IP.Addr, rP->ai_addr, rP->ai_addrlen);
protType = (IP.v6.sin6_family == AF_INET6 ? PF_INET6 : PF_INET);
if (rP->ai_canonname) hostName = LowCase(strdup(rP->ai_canonname));
freeaddrinfo(rP);
}
// Now set the port number as needed (v4 & v6 port locations are the same)
//
if (pNum == PortInSpec && !Colon) return "port not specified";
if (pNum <= 0 && Colon)
{char *eP;
pNum = strtol(Colon+1, &eP, 10);
if (pNum < 0 || pNum > 0xffff || *eP) return "invalid port number";
} else if (pNum < 0) pNum = -pNum;
IP.v6.sin6_port = htons(static_cast<short>(pNum));
// All done
//
return 0;
}
XrdNetAddrInfo::protType
unsigned char protType
Definition XrdNetAddrInfo.hh:366
XrdNetAddrInfo::LowCase
char * LowCase(char *str)
Definition XrdNetAddrInfo.cc:265
XrdNetAddrInfo::addrSize
unsigned short addrSize
Definition XrdNetAddrInfo.hh:365

References XrdNetAddrInfo::addrSize, XrdNetAddrInfo::hostName, XrdNetAddrInfo::IP, XrdNetAddrInfo::isHostName(), XrdNetAddrInfo::LowCase(), PortInSpec, and XrdNetAddrInfo::protType.

Referenced by XrdNetAddr(), XrdNetAddr(), XrdNetAddr(), XrdNetAddr(), XrdNetMsg::XrdNetMsg(), XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdNetSecurity::Authorize(), XrdNetPMarkCfg::Config(), XrdNet::Connect(), XrdCmsNode::do_SelAvoid(), XrdPosixAdmin::FanOut(), XrdNetIF::GetIF(), XrdSsiClientProvider::GetService(), XrdNetUtils::GetSokInfo(), XrdNetUtils::IPFormat(), XrdOucReqID::isMine(), XrdCmsRedirLocal::Locate(), main(), main(), XrdCmsUtils::ParseMan(), XrdCmsManager::Rerun(), XrdMpxOut::Run(), XrdNetMsg::Send(), XrdNetMsg::Send(), Set(), XrdOfsTPCInfo::Set(), XrdOfsTPC::Verify(), XrdFfsMisc_get_list_of_data_servers(), and XrdFfsMisc_getNameByAddr().

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

## Set() [3/5]

const char * XrdNetAddr::Set | ( | const struct sockaddr * | sockP,
|  | int | sockFD = -1 )

Set our address via a sockaddr structure.

Parameters

  sockP | a pointer to an initialized and valid sockaddr structure.
  sockFD | the associated file descriptor and can be used to record the file descriptor returned by accept().

Returns
  Success: Returns 0. Failure: Returns the error message text describing the error. The message is in persistent storage and cannot be modified.

Definition at line 406 of file XrdNetAddr.cc.

{
// Clear translation if set
//
if (hostName) {free(hostName); hostName = 0;}
if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
sockNum = sockFD;
// Copy the address based on address family
//
if (sockP->sa_family == AF_INET6) {addrSize = sizeof(IP.v6);
protType = PF_INET6;
}
else if (sockP->sa_family == AF_INET) {addrSize = sizeof(IP.v4);
protType = PF_INET;
}
else if (sockP->sa_family == AF_UNIX)
{unixPipe = new sockaddr_un;
memcpy(unixPipe, sockP, sizeof(struct sockaddr_un));
unixPipe->sun_path[sizeof(unixPipe->sun_path)-1] = 0;
addrSize = sizeof(sockaddr_un);
memset(&IP, 0, sizeof(IP));
IP.Addr.sa_family = AF_UNIX;
protType = PF_UNIX;
return 0;
}
else return "invalid address family";
// Copy the address and return
//
memcpy(&IP, sockP, addrSize);
return 0;
}
XrdNetAddrInfo::sockNum
int sockNum
Definition XrdNetAddrInfo.hh:368

References XrdNetAddrInfo::addrSize, XrdNetAddrInfo::hostName, XrdNetAddrInfo::IP, XrdNetAddrInfo::protType, and XrdNetAddrInfo::sockNum.

## Set() [4/5]

const char * XrdNetAddr::Set | ( | int | sockFD,
|  | bool | peer = true )

Set our address from the supplied socket file descriptor.

Parameters

  sockFD | a connected socket file descriptor. The value is also recorded as the associated file descriptor.
  peer | When true the address is set from getpeername() When false the address is set from getsockname()

Returns
  Success: Returns 0. Failure: Returns the error message text describing the error. The message is in persistent storage and cannot be modified.

Definition at line 442 of file XrdNetAddr.cc.

{
SOCKLEN_t aSize = static_cast<SOCKLEN_t>(sizeof(IP));
int rc;
// Clear translation if set
//
if (hostName) {free(hostName); hostName = 0;}
if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
sockNum = sockFD;
// Get the address on the appropriate side of this socket
//
if (peer) rc = getpeername(sockFD, &IP.Addr, &aSize);
else rc = getsockname(sockFD, &IP.Addr, &aSize);
if (rc < 0)
{addrSize = 0;
return XrdSysE2T(errno);
}
// Set the correct address size and protocol family
//
addrSize = aSize;
protType = (IP.Addr.sa_family == AF_INET ? PF_INET : PF_INET6);
// All done
//
return 0;
}
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
SOCKLEN_t
#define SOCKLEN_t
Definition XrdSysPlatform.hh:269

References XrdNetAddrInfo::addrSize, XrdNetAddrInfo::hostName, XrdNetAddrInfo::IP, XrdNetAddrInfo::protType, SOCKLEN_t, XrdNetAddrInfo::sockNum, and XrdSysE2T().

Here is the call graph for this function:

## Set() [5/5]

const char * XrdNetAddr::Set | ( | struct addrinfo * | rP,
|  | int | port,
|  | bool | mapit = false )

Set our address via and addrinfo structure and initialize the port.

Parameters

  rP | pointer to an addrinfo structure.
  port | the port number to set.
  mapit | when true maps IPv4 addresses to IPv6. Otherwise, does not.

Returns
  Success: Returns 0. Failure: Returns the error message text describing the error. The message is in persistent storage and cannot be modified.

Definition at line 474 of file XrdNetAddr.cc.

{
static const int map46ID = htonl(0x0000ffff);
// See if we need to convert this address otherwise just copy it
//
if (mapit && rP->ai_family == AF_INET)
{memset(&IP.Addr, 0, sizeof(IP.Addr));
IP.v6.sin6_family = AF_INET6;
memcpy(&IP.v6.sin6_addr.s6_addr32[3], (rP->ai_addr->sa_data)+2, 4);
IP.v6.sin6_addr.s6_addr32[2] = map46ID;
addrSize = sizeof(IP.v6);
protType = PF_INET6;
} else {
memcpy(&IP.Addr, rP->ai_addr, rP->ai_addrlen);
addrSize = rP->ai_addrlen;
protType = rP->ai_protocol;
}
// Cleanup pre-existing information
//
if (hostName) free(hostName);
hostName = (rP->ai_canonname ? LowCase(strdup(rP->ai_canonname)) : 0);
if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
IP.v6.sin6_port = htons(static_cast<short>(Port));
sockNum = 0;
return 0;
}
XrdNetAddr::Port
int Port(int pNum=-1)
Definition XrdNetAddr.cc:156

References XrdNetAddrInfo::addrSize, XrdNetAddrInfo::hostName, XrdNetAddrInfo::IP, XrdNetAddrInfo::LowCase(), Port(), XrdNetAddrInfo::protType, and XrdNetAddrInfo::sockNum.

Here is the call graph for this function:

## SetCache()

void XrdNetAddr::SetCache | ( | int | keeptime | ) |

static

Set the cache time for address to name resolutions. This method should only be called during initialization time. The default is to not use the cache.

Definition at line 507 of file XrdNetAddr.cc.

{
static XrdNetCache theCache;
// Set the cache keep time
//
theCache.SetKT(keeptime);
dnsCache = (keeptime > 0 ? &theCache : 0);
}
XrdNetAddrInfo::dnsCache
static XrdNetCache * dnsCache
Definition XrdNetAddrInfo.hh:357
XrdPosixGlobals::theCache
XrdOucCache * theCache
Definition XrdPosixConfig.cc:77

References XrdNetAddrInfo::dnsCache.

Referenced by XrdConfig::XrdConfig().

Here is the caller graph for this function:

## SetDialect()

void XrdNetAddr::SetDialect | ( | const char * | dP | ) |

inline

Set the dialect being spoken on this network link.

Parameters

  dP | Pointer to the dialect name. It must be permanently stable.

Definition at line 205 of file XrdNetAddr.hh.

{protName = dP;}
XrdNetAddrInfo::protName
const char * protName
Definition XrdNetAddrInfo.hh:369

References XrdNetAddrInfo::protName.

Referenced by XrdHttpProtocol::Match().

Here is the caller graph for this function:

## SetDynDNS()

void XrdNetAddr::SetDynDNS | ( | bool | onoff | ) |

static

Indicate whether or not dynamic DNS is being used. This method should only be called during initialization time. The default is fixed DNS.

Parameters

  onoff | True if dynamic DNS is being used, false otherwise.

Definition at line 521 of file XrdNetAddr.cc.

{dynDNS = onoff;}

## SetIPV4()

void XrdNetAddr::SetIPV4 | ( |  | ) |

static

Force this object to work in IPV4 mode only. This method permanently sets IPV4 mode which cannot be undone without a restart. It is meant to bypass broken IPV6 stacks on those unfortunate hosts that have one. It should be called before any other calls to this object (e.g. initialization time).

Definition at line 527 of file XrdNetAddr.cc.

{
// To force IPV4 mode we merely change the hints structure and set the IPV4
// mode flag to reject IPV6 address unless they are mapped.
//
hostHints->ai_flags = AI_CANONNAME;
hostHints->ai_family = AF_INET;
huntHintsTCP->ai_flags = AI_ADDRCONFIG;
huntHintsTCP->ai_family = AF_INET;
huntHintsUDP->ai_flags = AI_ADDRCONFIG;
huntHintsUDP->ai_family = AF_INET;
useIPV4 = true;
// Inform NetUtils that we changed mode
//
XrdNetUtils::SetAuto(XrdNetUtils::onlyIPv4);
}
XrdNetUtils::SetAuto
static int SetAuto(AddrOpts aOpts=allIPMap)
Definition XrdNetUtils.cc:915
XrdNetUtils::onlyIPv4
@ onlyIPv4
Definition XrdNetUtils.hh:144

References XrdNetUtils::onlyIPv4, and XrdNetUtils::SetAuto().

Referenced by XrdConfig::Configure().

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

## SetIPV6()

void XrdNetAddr::SetIPV6 | ( |  | ) |

static

Force this object to work in IPV6 mode using IPV6 or mapped IPV4 addresses. This method permanently sets IPV6 mode which cannot be undone without a restart. It is meant to disable the default mode which determines which address to use based on which address types are configured on the host (i.e. getaddrinfo() with hints AI_ADDRCONFIG|AI_V4MAPPED).

Definition at line 553 of file XrdNetAddr.cc.

{
// To force IPV6 mode we merely change the hints structure and set the IPV4
// mode flag to accept IPV6 address.
//
hostHints->ai_flags = AI_V4MAPPED | AI_CANONNAME;
hostHints->ai_family = AF_INET6;
huntHintsTCP->ai_flags = AI_V4MAPPED | AI_ALL;
huntHintsTCP->ai_family = AF_INET6;
huntHintsUDP->ai_flags = AI_V4MAPPED | AI_ALL;
huntHintsUDP->ai_family = AF_INET6;
useIPV4 = false;
// Inform NetUtils that we changed mode
//
XrdNetUtils::SetAuto(XrdNetUtils::allIPMap);
}

References XrdNetUtils::allIPMap, and XrdNetUtils::SetAuto().

Referenced by XrdConfig::Configure().

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

## SetLocation()

void XrdNetAddr::SetLocation | ( | XrdNetAddrInfo::LocInfo & | loc | ) |

Set the location for this address

Parameters

  loc | pointer to the structure that describes the location. See XrdnetAddrInfo for the definition of the stucture.

Definition at line 579 of file XrdNetAddr.cc.

{
// Copy in the new location information but preserve the flags
//
addrLoc = loc;
}
XrdNetAddrInfo::addrLoc
LocInfo addrLoc
Definition XrdNetAddrInfo.hh:364

References XrdNetAddrInfo::addrLoc.

## SetTLS()

void XrdNetAddr::SetTLS | ( | bool | val | ) |

Set the location's TLS state.

Parameters

  val | True if TLS is being used, false otherwise.

Definition at line 590 of file XrdNetAddr.cc.

{
if (val) protFlgs |= isTLS;
else protFlgs &= ~isTLS;
}
XrdNetAddrInfo::protFlgs
unsigned char protFlgs
Definition XrdNetAddrInfo.hh:367
XrdNetAddrInfo::isTLS
static const char isTLS
Location using TLS.
Definition XrdNetAddrInfo.hh:373

References XrdNetAddrInfo::isTLS, and XrdNetAddrInfo::protFlgs.

Referenced by XrdHttpProtocol::Match().

Here is the caller graph for this function:

## Member Data Documentation

## PortInSpec

const int XrdNetAddr::PortInSpec = (int)0x80000000

static

Set the IP address and possibly the port number.

Parameters

  hSpec | 0 -> address is set to in6addr_any for binding via bind() (INADDR_ANY in IPV4 mode). !0 -> convert specification to an address. Valid formats: IPv4: nnn.nnn.nnn.nnn[:<port>] IPv6: [ipv6_addr][:<port>] addr brackets required IPvx: name[:port] x is determined by getaddrinfo() Unix: /<path>
  pNum | >= 0 uses the value as the port number regardless of what is in hSpec, should it be supplied. However, if is present, it must be a valid port number or name. < 0 uses the positive value as the port number if the port number has not been specified in hSpec. **** When set to PortInSpec(the default, see below) the port number/name must be specified in hSpec. If it is not, an error is returned.

Returns
  Success: 0. Failure: Error message text describing the error. The message is in persistent storage and cannot be modified.

Definition at line 112 of file XrdNetAddr.hh.

Referenced by XrdNetUtils::Hosts(), XrdNetSocket::Open(), Set(), and Set().

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

- XrdNetAddr.hh
- XrdNetAddr.cc