XRootD
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. More...
 
 XrdNetAddr (const sockaddr *addr)
 
 XrdNetAddr (const sockaddr_in *addr)
 
 XrdNetAddr (const sockaddr_in6 *addr)
 
 XrdNetAddr (const XrdNetAddr *addr)
 
 XrdNetAddr (int port)
 
 ~XrdNetAddr ()
 Destructor. More...
 
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. More...
 
 XrdNetAddrInfo (const XrdNetAddrInfo *addr)
 
 XrdNetAddrInfo (XrdNetAddrInfo const &oP)
 Copy constructor. More...
 
 ~XrdNetAddrInfo ()
 Destructor. More...
 
const char * Dialect ()
 
int Family () const
 
int Format (char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
 
bool isIPType (IPType ipType) const
 
bool isLocal ()
 
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. More...
 
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. More...
 
static const int noPortRaw = 0x0000002
 Use raw address format (no port) More...
 
static const int old6Map4 = 0x0000004
 Use deprecated IPV6 mapped format. More...
 
static const int prefipv4 = 0x0000008
 Use if mapped IPV4 actual format. More...
 

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

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
addrA pointer to an initialized and valid sockaddr or sockaddr compatible structure used to initialize the address.
portUses the address of the current host and the speoified port number to initilize the address.

Definition at line 265 of file XrdNetAddr.hh.

265 : XrdNetAddrInfo() {}
XrdNetAddrInfo()
Constructor.

◆ XrdNetAddr() [2/6]

XrdNetAddr::XrdNetAddr ( const XrdNetAddr *  addr)
inline

Definition at line 267 of file XrdNetAddr.hh.

267 : XrdNetAddrInfo(addr) {}

◆ XrdNetAddr() [3/6]

XrdNetAddr::XrdNetAddr ( const sockaddr *  addr)
inline

Definition at line 269 of file XrdNetAddr.hh.

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

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

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

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

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

References Set().

+ Here is the call graph for this function:

◆ XrdNetAddr() [6/6]

XrdNetAddr::XrdNetAddr ( int  port)

Definition at line 95 of file XrdNetAddr.cc.

95  : XrdNetAddrInfo()
96 {
97  const char *fqn = XrdNetIdentity::FQN();
98 
99 // The host name might not be resolvable. If we have an fqn then either the
100 // name was manually set or we are using an IP address because reverse
101 // lookup did not work. If we have an fqn, then use it as the name. Otherwise,
102 // use localhost as that is always a safe fallback.
103 //
104  if (!fqn || Set(fqn, port))
105  {Set("localhost", port);
106  if (fqn)
107  {if (hostName) free(hostName);
108  hostName = strdup(fqn);
109  }
110  }
111 }
static const char * FQN(const char **etext=0)

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

284 {}

Member Function Documentation

◆ DynDNS()

static bool XrdNetAddr::DynDNS ( )
inlinestatic

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.

52 {return dynDNS;}

Referenced by XrdCmsUtils::ParseMan().

+ Here is the caller graph for this function:

◆ IPV4Set()

static bool XrdNetAddr::IPV4Set ( )
inlinestatic

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.

61 {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
pNumwhen 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.

157 {
158 // Make sure we have a proper address family here
159 //
160  if (IP.Addr.sa_family != AF_INET && IP.Addr.sa_family != AF_INET6)
161  return -1;
162 
163 // Return port number if so wanted. The port location is the same regardless of
164 // the address family.
165 //
166  if (pNum < 0) return ntohs(IP.v6.sin6_port);
167 
168 // Set port number if we have a valid address. The location of the port
169 // is the same regardless of address family.
170 //
171  if (pNum > 0xffff) return -1;
172  IP.v6.sin6_port = htons(static_cast<short>(pNum));
173  return pNum;
174 }
struct sockaddr_in6 v6
struct sockaddr Addr
XrdNetSockAddr IP

References XrdNetSockAddr::Addr, XrdNetAddrInfo::IP, and XrdNetSockAddr::v6.

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

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

181 {
182  XrdNetAddr *aListVec = 0;
183  int i, aListNum;
184 
185 // Step one is to make sure the incoming name is not an address
186 //
187  if (!isHostName(hName)) return false;
188 
189 // The next step is to get all of the IP addresses registered for this name
190 //
191  if (XrdNetUtils::GetAddrs(hName, &aListVec, aListNum,
193  return false;
194 
195 // In order to use the given name, one of the IP addresses in the list must
196 // match our address. This is about as secure we can get.
197 //
198  for (i = 0; i < aListNum; i++) {if (Same(&aListVec[i])) break;}
199  delete [] aListVec;
200 
201 // If we didn't find a match, report it
202 //
203  if (i >= aListNum) return false;
204 
205 // Replace current hostname with the wanted one
206 //
207  if (hostName) free(hostName);
208  hostName = strdup(hName);
209  return true;
210 }
static bool isHostName(const char *name)
int Same(const XrdNetAddrInfo *ipAddr, bool plusPort=false)
static const int NoPortRaw
Definition: XrdNetUtils.hh:150
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
Definition: XrdNetUtils.cc:274

References 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
hSpec0 -> 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()
maxIPnumber of elements in the array.
numIPthe 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.
forUDPwhen 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 344 of file XrdNetAddr.cc.

346 {
347  struct addrinfo *hP, *rP = 0, *pP, *nP;
348  XrdNetAddr *aVec = this;
349  const char *hnBeg, *hnEnd, *pnBeg, *pnEnd;
350  char hBuff[MAXHOSTNAMELEN+8];
351  int hLen, n;
352 
353 // If only one address can be returned, just revert to standard processing
354 //
355  if (!hSpec || !isalpha(*hSpec) || maxIP < 2)
356  {const char *eMsg = Set(hSpec, pNum);
357  numIP = (eMsg ? 0 : 1);
358  return eMsg;
359  }
360 
361 // Extract out host name
362 //
363  if (!XrdNetUtils::Parse(hSpec, &hnBeg, &hnEnd, &pnBeg, &pnEnd))
364  return "invalid host specification";
365  hLen = hnEnd - hnBeg;
366  if (hLen > MAXHOSTNAMELEN) return "host name too long";
367  strncpy(hBuff, hSpec, hLen); hBuff[hLen] = 0;
368 
369 // Get the port number we will be setting
370 //
371  if (pnBeg == hnEnd)
372  {if (pNum == PortInSpec) return "port not specified";
373  if (pNum < 0) pNum = -pNum;
374  } else {
375  if (*pnEnd || !(n = XrdNetUtils::ServPort(pnBeg, optUDP)))
376  return "invalid port";
377  if (pNum < 0) pNum = n;
378  }
379 
380 // Get all of the addresses
381 //
382  hP = (optUDP ? huntHintsUDP : huntHintsTCP);
383  n = getaddrinfo(hBuff, 0, hP, &rP);
384  if (n || !rP)
385  {if (rP) freeaddrinfo(rP);
386  return (n ? gai_strerror(n) : "host not found");
387  }
388 
389 // Now self-referentially fill out ourselves with no duplicates
390 //
391  n = 0; pP = 0; nP = rP;
392  do {if (!pP || pP->ai_addrlen != nP->ai_addrlen
393  || memcmp((const void *)pP->ai_addr, (const void *)nP->ai_addr,
394  nP->ai_addrlen)) {aVec[n].Set(nP, pNum); n++;}
395  pP = nP; nP = nP->ai_next;
396  } while(n < maxIP && nP);
397 
398 // All done
399 //
400  numIP = n;
401  if (rP) freeaddrinfo(rP);
402  return 0;
403 }
#define eMsg(x)
static const int PortInSpec
Definition: XrdNetAddr.hh:112
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
Definition: XrdNetUtils.cc:874
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
Definition: XrdNetUtils.cc:780

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

217 {
218  static const char *badIPv4 = "invalid IPv4 address";
219  static const char *badIPv6 = "invalid IPv6 address";
220  static const char *badIP64 = "IPv6 address not IPv4 representable";
221  static const char *badName = "invalid host name";
222  static const int map46ID = htonl(0x0000ffff);
223 
224  const char *Colon, *iP;
225  char aBuff[NI_MAXHOST+INET6_ADDRSTRLEN];
226  int aLen, n;
227  bool mapIt;
228 
229 // Clear translation if set (note unixPipe & sockAddr are the same).
230 //
231  if (hostName) {free(hostName); hostName = 0;}
232  if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
233  memset(&IP, 0, sizeof(IP));
234  addrSize = sizeof(sockaddr_in6);
235 
236 // Check for any address setting
237 //
238  if (!hSpec)
239  {if (useIPV4)
240  {IP.v4.sin_family = AF_INET;
241  IP.v4.sin_addr.s_addr = INADDR_ANY;
242  protType = PF_INET;
243  addrSize = sizeof(sockaddr_in);
244  } else {
245  IP.v6.sin6_family = AF_INET6;
246  IP.v6.sin6_addr = in6addr_any;
247  protType = PF_INET6;
248  }
249  if (pNum < 0) pNum= -pNum;
250  IP.v6.sin6_port = htons(static_cast<short>(pNum));
251  return 0;
252  }
253 
254 // Check for Unix type address here
255 //
256  if (*hSpec == '/')
257  {if (strlen(hSpec) >= sizeof(unixPipe->sun_path)) return "path too long";
258  unixPipe = new sockaddr_un;
259  strcpy(unixPipe->sun_path, hSpec);
260  unixPipe->sun_family = IP.Addr.sa_family = AF_UNIX;
261  addrSize = sizeof(sockaddr_un);
262  protType = PF_UNIX;
263  return 0;
264  }
265 
266 // Do length check to see if we can fit the host name in our buffer.
267 //
268  aLen = strlen(hSpec);
269  if (aLen >= (int)sizeof(aBuff)) return "host id too long";
270 
271 // Convert the address as appropriate. Note that we do accept RFC5156 deprecated
272 // IPV4 mapped IPV6 addresses(i.e. [::a.b.c.d]. This is historical.
273 //
274  if (*hSpec == '[')
275  {const char *Brak = index(hSpec+1, ']');
276  if (!Brak) return badIPv6;
277  Colon = Brak+1;
278  if (!(*Colon)) Colon = 0;
279  else if (*Colon != ':') return badIPv6;
280  aLen = Brak - (hSpec+1);
281  if (aLen >= INET6_ADDRSTRLEN) return badIPv6;
282  mapIt = (*(hSpec+1) == ':' && *(hSpec+2) == ':'
283  && *(hSpec+3) >= '0' && *(hSpec+3) <= '9'
284  && (iP = index(hSpec+4, '.')) && iP < Brak);
285  strncpy(aBuff, hSpec+1, aLen); aBuff[aLen] = 0;
286  if (inet_pton(AF_INET6,aBuff,&IP.v6.sin6_addr) != 1) return badIPv6;
287  if (mapIt) IP.v6.sin6_addr.s6_addr32[2] = map46ID;
288  IP.v6.sin6_family = AF_INET6;
289  protType = PF_INET6;
290  if (useIPV4 && !Map64()) return badIP64;
291  }
292  else if (!isHostName(hSpec))
293  {if ((Colon = index(hSpec, ':')))
294  {aLen = Colon - hSpec;
295  if (aLen >= INET_ADDRSTRLEN) return badIPv4;
296  strncpy(aBuff, hSpec, aLen); aBuff[aLen] = 0; iP = aBuff;
297  } else iP = hSpec;
298  if (inet_pton(AF_INET ,iP, &IP.v6.sin6_addr.s6_addr32[3]) != 1)
299  return badIPv4;
300  IP.v6.sin6_addr.s6_addr32[2] = map46ID;
301  IP.v6.sin6_family = AF_INET6;
302  protType = PF_INET6;
303  if (useIPV4 && !Map64()) return badIPv4;
304  }
305  else if (*hSpec == 0) return badName;
306 
307  else {struct addrinfo *rP = 0;
308  if ((Colon = index(hSpec, ':')))
309  {aLen = Colon - hSpec;
310  if (aLen > MAXHOSTNAMELEN) return badName;
311  strncpy(aBuff, hSpec, aLen); aBuff[aLen] = 0; iP = aBuff;
312  } else iP = hSpec;
313  n = getaddrinfo(iP, 0, hostHints, &rP);
314  if (n || !rP)
315  {if (rP) freeaddrinfo(rP);
316  if (n == EAI_NONAME && dynDNS)
317  return "Dynamic name or service not yet registered";
318  return (n ? gai_strerror(n) : "host not found");
319  }
320  memcpy(&IP.Addr, rP->ai_addr, rP->ai_addrlen);
321  addrSize = rP->ai_addrlen;
322  protType = (IP.v6.sin6_family == AF_INET6 ? PF_INET6 : PF_INET);
323  if (rP->ai_canonname) hostName = LowCase(strdup(rP->ai_canonname));
324  freeaddrinfo(rP);
325  }
326 
327 // Now set the port number as needed (v4 & v6 port locations are the same)
328 //
329  if (pNum == PortInSpec && !Colon) return "port not specified";
330  if (pNum <= 0 && Colon)
331  {char *eP;
332  pNum = strtol(Colon+1, &eP, 10);
333  if (pNum < 0 || pNum > 0xffff || *eP) return "invalid port number";
334  } else if (pNum < 0) pNum = -pNum;
335  IP.v6.sin6_port = htons(static_cast<short>(pNum));
336 
337 // All done
338 //
339  return 0;
340 }
struct sockaddr_in v4
unsigned char protType
char * LowCase(char *str)
unsigned short addrSize

References XrdNetSockAddr::Addr, XrdNetAddrInfo::addrSize, XrdNetAddrInfo::hostName, XrdNetAddrInfo::IP, XrdNetAddrInfo::isHostName(), XrdNetAddrInfo::LowCase(), PortInSpec, XrdNetAddrInfo::protType, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.

Referenced by XrdHttpTpc::PMarkManager::SocketInfo::SocketInfo(), XrdNetAddr(), XrdNetMsg::XrdNetMsg(), XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdNetSecurity::Authorize(), XrdNetPMarkCfg::Config(), XrdNet::Connect(), XrdCmsNode::do_SelAvoid(), XrdPosixAdmin::FanOut(), XrdNetIF::GetIF(), getMyFQN(), XrdSsiClientProvider::GetService(), XrdNetUtils::GetSokInfo(), XrdNetUtils::IPFormat(), XrdOucReqID::isMine(), XrdCmsRedirLocal::Locate(), main(), XrdNetSocket::Open(), XrdCmsUtils::ParseMan(), XrdCmsManager::Rerun(), XrdMpxOut::Run(), XrdNetMsg::Send(), XrdOfsTPCInfo::Set(), 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
sockPa pointer to an initialized and valid sockaddr structure.
sockFDthe 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 407 of file XrdNetAddr.cc.

408 {
409 // Clear translation if set
410 //
411  if (hostName) {free(hostName); hostName = 0;}
412  if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
413  sockNum = sockFD;
414 
415 // Copy the address based on address family
416 //
417  if (sockP->sa_family == AF_INET6) {addrSize = sizeof(IP.v6);
418  protType = PF_INET6;
419  }
420  else if (sockP->sa_family == AF_INET) {addrSize = sizeof(IP.v4);
421  protType = PF_INET;
422  }
423  else if (sockP->sa_family == AF_UNIX)
424  {unixPipe = new sockaddr_un;
425  memcpy(unixPipe, sockP, sizeof(struct sockaddr_un));
426  unixPipe->sun_path[sizeof(unixPipe->sun_path)-1] = 0;
427  addrSize = sizeof(sockaddr_un);
428  memset(&IP, 0, sizeof(IP));
429  IP.Addr.sa_family = AF_UNIX;
430  protType = PF_UNIX;
431  return 0;
432  }
433  else return "invalid address family";
434 
435 // Copy the address and return
436 //
437  memcpy(&IP, sockP, addrSize);
438  return 0;
439 }

References XrdNetSockAddr::Addr, XrdNetAddrInfo::addrSize, XrdNetAddrInfo::hostName, XrdNetAddrInfo::IP, XrdNetAddrInfo::protType, XrdNetAddrInfo::sockNum, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.

◆ Set() [4/5]

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

Set our address from the supplied socket file descriptor.

Parameters
sockFDa connected socket file descriptor. The value is also recorded as the associated file descriptor.
peerWhen 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 443 of file XrdNetAddr.cc.

444 {
445  SOCKLEN_t aSize = static_cast<SOCKLEN_t>(sizeof(IP));
446  int rc;
447 
448 // Clear translation if set
449 //
450  if (hostName) {free(hostName); hostName = 0;}
451  if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
452  sockNum = sockFD;
453 
454 // Get the address on the appropriate side of this socket
455 //
456  if (peer) rc = getpeername(sockFD, &IP.Addr, &aSize);
457  else rc = getsockname(sockFD, &IP.Addr, &aSize);
458  if (rc < 0)
459  {addrSize = 0;
460  return XrdSysE2T(errno);
461  }
462 
463 // Set the correct address size and protocol family
464 //
465  addrSize = aSize;
466  protType = (IP.Addr.sa_family == AF_INET ? PF_INET : PF_INET6);
467 
468 // All done
469 //
470  return 0;
471 }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:101
#define SOCKLEN_t

References XrdNetSockAddr::Addr, 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
rPpointer to an addrinfo structure.
portthe port number to set.
mapitwhen 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 475 of file XrdNetAddr.cc.

476 {
477  static const int map46ID = htonl(0x0000ffff);
478 
479 // See if we need to convert this address otherwise just copy it
480 //
481  if (mapit && rP->ai_family == AF_INET)
482  {memset(&IP.Addr, 0, sizeof(IP.Addr));
483  IP.v6.sin6_family = AF_INET6;
484  memcpy(&IP.v6.sin6_addr.s6_addr32[3], (rP->ai_addr->sa_data)+2, 4);
485  IP.v6.sin6_addr.s6_addr32[2] = map46ID;
486  addrSize = sizeof(IP.v6);
487  protType = PF_INET6;
488  } else {
489  memcpy(&IP.Addr, rP->ai_addr, rP->ai_addrlen);
490  addrSize = rP->ai_addrlen;
491  protType = rP->ai_protocol;
492  }
493 
494 // Cleanup pre-existing information
495 //
496  if (hostName) free(hostName);
497  hostName = (rP->ai_canonname ? LowCase(strdup(rP->ai_canonname)) : 0);
498  if (sockAddr != &IP.Addr) {delete unixPipe; sockAddr = &IP.Addr;}
499  IP.v6.sin6_port = htons(static_cast<short>(Port));
500  sockNum = 0;
501  return 0;
502 }

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

+ 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 508 of file XrdNetAddr.cc.

509 {
510  static XrdNetCache theCache;
511 
512 // Set the cache keep time
513 //
514  theCache.SetKT(keeptime);
515  dnsCache = (keeptime > 0 ? &theCache : 0);
516 }
static XrdNetCache * dnsCache
XrdOucCache * theCache

References XrdNetAddrInfo::dnsCache, and XrdPosixGlobals::theCache.

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
dPPointer to the dialect name. It must be permanently stable.

Definition at line 205 of file XrdNetAddr.hh.

205 {protName = dP;}
const char * protName

References XrdNetAddrInfo::protName.

Referenced by XrdHttpProtocol::Match(), and XrdLinkXeq::setProtName().

+ 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
onoffTrue if dynamic DNS is being used, false otherwise.

Definition at line 522 of file XrdNetAddr.cc.

522 {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 528 of file XrdNetAddr.cc.

529 {
530 
531 // To force IPV4 mode we merely change the hints structure and set the IPV4
532 // mode flag to reject IPV6 address unless they are mapped.
533 //
534  hostHints->ai_flags = AI_CANONNAME;
535  hostHints->ai_family = AF_INET;
536 
537  huntHintsTCP->ai_flags = AI_ADDRCONFIG;
538  huntHintsTCP->ai_family = AF_INET;
539 
540  huntHintsUDP->ai_flags = AI_ADDRCONFIG;
541  huntHintsUDP->ai_family = AF_INET;
542 
543  useIPV4 = true;
544 
545 // Inform NetUtils that we changed mode
546 //
548 }
static int SetAuto(AddrOpts aOpts=allIPMap)
Definition: XrdNetUtils.cc:915

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 554 of file XrdNetAddr.cc.

555 {
556 
557 // To force IPV6 mode we merely change the hints structure and set the IPV4
558 // mode flag to accept IPV6 address.
559 //
560  hostHints->ai_flags = AI_V4MAPPED | AI_CANONNAME;
561  hostHints->ai_family = AF_INET6;
562 
563  huntHintsTCP->ai_flags = AI_V4MAPPED | AI_ALL;
564  huntHintsTCP->ai_family = AF_INET6;
565 
566  huntHintsUDP->ai_flags = AI_V4MAPPED | AI_ALL;
567  huntHintsUDP->ai_family = AF_INET6;
568 
569  useIPV4 = false;
570 
571 // Inform NetUtils that we changed mode
572 //
574 }

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
locpointer to the structure that describes the location. See XrdnetAddrInfo for the definition of the stucture.

Definition at line 580 of file XrdNetAddr.cc.

581 {
582 // Copy in the new location information but preserve the flags
583 //
584  addrLoc = loc;
585 }

References XrdNetAddrInfo::addrLoc.

Referenced by XrdLinkXeq::setLocation().

+ Here is the caller graph for this function:

◆ SetTLS()

void XrdNetAddr::SetTLS ( bool  val)

Set the location's TLS state.

Parameters
valTrue if TLS is being used, false otherwise.

Definition at line 591 of file XrdNetAddr.cc.

592 {
593  if (val) protFlgs |= isTLS;
594  else protFlgs &= ~isTLS;
595 }
unsigned char protFlgs
static const char isTLS
Location using TLS.

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

Referenced by XrdHttpProtocol::Match(), and XrdLinkXeq::setTLS().

+ 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
hSpec0 -> 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(), and Set().


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