XRootD
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. 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 LocInfoLocation ()
 
const char * Name (const char *eName=0, const char **eText=0)
 
const XrdNetSockAddrNetAddr ()
 
XrdNetAddrInfooperator= (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 isHostName (const char *name)
 

Static Public Attributes

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

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 XrdNetCachednsCache = 0
 
static const char isTLS = 0x01
 Location using TLS. More...
 

Detailed Description

Definition at line 53 of file XrdNetAddrInfo.hh.

Member Enumeration Documentation

◆ 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
bAddraddress of buffer for result
bLenlength of buffer
fmtTypespecifies the type of format desired via fmtUse enum.
fmtOptsadditional 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.

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

◆ IPType

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

Parameters
ipTypeThe 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.

144 {IPv4 = AF_INET, IPv6 = AF_INET6, IPuX = AF_UNIX};

Constructor & Destructor Documentation

◆ XrdNetAddrInfo() [1/3]

XrdNetAddrInfo::XrdNetAddrInfo ( XrdNetAddrInfo const &  oP)
inline

Copy constructor.

Definition at line 335 of file XrdNetAddrInfo.hh.

336  {hostName = 0;
337  unixPipe = 0;
338  *this = oP;
339  }

References hostName.

◆ XrdNetAddrInfo() [2/3]

XrdNetAddrInfo::XrdNetAddrInfo ( )
inline

Constructor.

Definition at line 345 of file XrdNetAddrInfo.hh.

345  : hostName(0), addrSize(0), protType(0),
346  protFlgs(0), sockNum(0), protName(0)
347  {IP.Addr.sa_family = 0;
348  sockAddr = &IP.Addr;
349  }
struct sockaddr Addr
const char * protName
unsigned char protFlgs
XrdNetSockAddr IP
unsigned char protType
unsigned short addrSize

References XrdNetSockAddr::Addr, and IP.

◆ XrdNetAddrInfo() [3/3]

XrdNetAddrInfo::XrdNetAddrInfo ( const XrdNetAddrInfo addr)
inline

Definition at line 351 of file XrdNetAddrInfo.hh.

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

◆ ~XrdNetAddrInfo()

XrdNetAddrInfo::~XrdNetAddrInfo ( )
inline

Destructor.

Definition at line 357 of file XrdNetAddrInfo.hh.

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

References XrdNetSockAddr::Addr, 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.

65 {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.

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

References XrdNetSockAddr::Addr, and IP.

Referenced by XrdCl::AsyncSocketHandler::Connect().

+ Here is the caller graph for this function:

◆ Format()

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

Definition at line 81 of file XrdNetAddrInfo.cc.

82 {
83  const char *pFmt = "]:%d";
84  int totLen, n, pNum, addBrak = 0;
85  int omitP = (fmtOpts & (noPort|noPortRaw));
86  int ipRaw = (fmtOpts & noPortRaw);
87  int ipOld = fmtOpts & (old6Map4 | prefipv4);
88 
89 // Handle the degenerative case first
90 //
91  if (IP.Addr.sa_family == AF_UNIX)
92  {n = (omitP ? snprintf(bAddr, bLen, "localhost")
93  : snprintf(bAddr, bLen, "localhost:%s", unixPipe->sun_path));
94  return (n < bLen ? n : QFill(bAddr, bLen));
95  }
96 
97 // Grab the potr. The port number is the same position and same size regardless
98 // of address type.
99 //
100  pNum = ntohs(IP.v4.sin_port);
101 
102 // Resolve address if need be and return result if possible
103 //
104  if (theFmt == fmtName || theFmt == fmtAuto)
105  {if (!hostName && dnsCache && !(hostName = dnsCache->Find(this))
106  && theFmt == fmtName) Resolve();
107  if (hostName)
108  {n = (omitP ? snprintf(bAddr, bLen, "%s", hostName)
109  : snprintf(bAddr, bLen, "%s:%d", hostName, pNum));
110  return (n < bLen ? n : QFill(bAddr, bLen));
111  }
112  theFmt = fmtAddr;
113  }
114 
115 // Check if we can now produce an address format quickly. We used assume that
116 // the hostname was an address if it started with a non-alpha. But this does
117 // not correspond to RFC 1178 and RFC 3696, among others. We now only use
118 // the optimization path if the name is actually an IPV6/mapped4 address.
119 //
120  if (hostName && *hostName == '[' && !ipOld)
121  {n = (omitP ? snprintf(bAddr, bLen, "%s", hostName)
122  : snprintf(bAddr, bLen, "%s:%d", hostName, pNum));
123  return (n < bLen ? n : QFill(bAddr, bLen));
124  }
125 
126 // Format address
127 //
128  if (IP.Addr.sa_family == AF_INET6)
129  {if (bLen < (INET6_ADDRSTRLEN+2)) return QFill(bAddr, bLen);
130  if (ipOld && IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr))
131  { if (fmtOpts & prefipv4) {n = 0; pFmt = ":%d";}
132  else if (ipRaw) {strcpy(bAddr, "::"); n = 2;}
133  else {strcpy(bAddr, "[::"); n = 3; addBrak=1;}
134  if (!inet_ntop(AF_INET, &IP.v6.sin6_addr.s6_addr32[3],
135  bAddr+n, bLen-n)) return QFill(bAddr, bLen);
136  } else {
137  if (!ipRaw) {*bAddr = '['; n = 1; addBrak = 1;}
138  else n = 0;
139  if (!inet_ntop(AF_INET6,&(IP.v6.sin6_addr),bAddr+n,bLen-n))
140  return QFill(bAddr, bLen);
141  }
142  }
143  else if (IP.Addr.sa_family == AF_INET)
144  {if (theFmt != fmtAdv6) {n = 0; pFmt = ":%d";}
145  else {if (bLen < (INET_ADDRSTRLEN+9)) return QFill(bAddr, bLen);
146  if (fmtOpts & old6Map4) {strcpy(bAddr, "[::"); n = 3;}
147  else {strcpy(bAddr, "[::ffff:"); n = 8;}
148  if (ipRaw) {strcpy(bAddr, bAddr+1); n--;}
149  addBrak = 1;
150  }
151  if (!inet_ntop(AF_INET, &(IP.v4.sin_addr),bAddr+n,bLen-n))
152  return QFill(bAddr, bLen);
153  }
154  else return QFill(bAddr, bLen);
155 
156 // Recalculate buffer position and length
157 //
158  totLen = strlen(bAddr); bAddr += totLen; bLen -= totLen;
159 
160 // Process when no port number wanted
161 //
162  if (omitP)
163  {if (addBrak)
164  {if (bLen < 2) return QFill(bAddr, bLen);
165  *bAddr++ = ']'; *bAddr = 0; totLen++;
166  }
167  return totLen;
168  }
169 
170 // Add the port number and return result
171 //
172  if ((n = snprintf(bAddr, bLen, pFmt, pNum)) >= bLen)
173  return QFill(bAddr, bLen);
174  return totLen+n;
175 }
struct sockaddr_in6 v6
struct sockaddr_in v4
static XrdNetCache * dnsCache
static const int noPort
Do not add port number.
static const int old6Map4
Use deprecated IPV6 mapped format.
static const int noPortRaw
Use raw address format (no port)
static const int prefipv4
Use if mapped IPV4 actual format.
int QFill(char *bAddr, int bLen)
char * Find(XrdNetAddrInfo *hAddr)
Definition: XrdNetCache.cc:148

References XrdNetSockAddr::Addr, dnsCache, XrdNetCache::Find(), fmtAddr, fmtAdv6, fmtAuto, fmtName, hostName, IP, noPort, noPortRaw, old6Map4, prefipv4, QFill(), Resolve(), XrdNetSockAddr::v4, and XrdNetSockAddr::v6.

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

+ 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
nameThe 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 314 of file XrdNetAddrInfo.cc.

315 {
316  const char *dot;
317  int dnum;
318 
319 // First check for Iv6 format or hostname
320 //
321  if (*name == '[') return false;
322  if (!isdigit(*name)) return true;
323 
324 // The IPv4 case is more complicated. The fastest way here is this is a
325 // host name if there are no dots or if the last component is not a digit
326 // according to the RFC spec.
327 //
328  if (!(dot = rindex(name, '.')) || !isdigit(*(dot+1))) return true;
329 
330 // We are not out of the woods yet. Now we need to do a full check.
331 //
332  name++; dnum = 0;
333  while(*name)
334  {if (*name == '.') dnum++;
335  else if (!isdigit(*name)) return true;
336  name++;
337  }
338  return (dnum == 3 ? false : true);
339 }

Referenced by XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdNetPMarkCfg::Begin(), getMyFQN(), 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.

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

References XrdNetSockAddr::Addr, and IP.

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

+ Here is the caller graph for this function:

◆ isLocal()

bool XrdNetAddrInfo::isLocal ( )

Indicate whether or not our address is local.

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

Definition at line 181 of file XrdNetAddrInfo.cc.

182 {
183  unsigned char *ipV4 = nullptr;
184 
185 // For IPv6, return true for link-local (fe80::/10) and loopback (::1)
186 //
187  if (IP.Addr.sa_family == AF_INET6)
188  {if ((IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr)))
189  ipV4 = (unsigned char *)&IP.v6.sin6_addr.s6_addr32[3];
190  else {if ((IN6_IS_ADDR_LINKLOCAL(&IP.v6.sin6_addr))
191  || (IN6_IS_ADDR_LOOPBACK (&IP.v6.sin6_addr))) return true;
192  return false;
193  }
194  }
195 
196 // If this is not an IPv4 address, consider it local (e.g. AF_UNIX)
197 //
198  if (!ipV4)
199  {if (IP.Addr.sa_family != AF_INET) return true;
200  ipV4 = (unsigned char *)&IP.v4.sin_addr.s_addr;
201  }
202 
203 // For IPV4, return true for link-local (169.254.0.0/16) and loopback (127.0.0.0/8)
204 //
205  if ((ipV4[0] == 169 && ipV4[1] == 254) || ipV4[0] == 127)
206  return true;
207 
208 // Not a local address
209 //
210  return false;
211 }
if(Avsz)

References XrdNetSockAddr::Addr, if(), IP, and XrdNetSockAddr::v6.

+ Here is the call 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 217 of file XrdNetAddrInfo.cc.

218 {
219 
220 // Check for loopback address
221 //
222  if (IP.Addr.sa_family == AF_INET)
223  return !memcmp(&IP.v4.sin_addr.s_addr, &lbVal[12], 1);
224 
225  if (IP.Addr.sa_family == AF_INET6)
226  return !memcmp(&IP.v6.sin6_addr, &in6addr_loopback, sizeof(in6_addr))
227  || !memcmp(&IP.v6.sin6_addr, lbVal, sizeof(lbVal));
228 
229  return false;
230 }

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

◆ 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 164 of file XrdNetAddrInfo.hh.

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

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

Referenced by XrdCl::AsyncSocketHandler::GetIpStack(), 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 236 of file XrdNetAddrInfo.cc.

237 {
238  unsigned char *ipV4 = 0;
239 
240 // For IPV6 addresses we will use the macro unless it is mapped
241 //
242  if (IP.Addr.sa_family == AF_INET6)
243  {if ((IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr)))
244  ipV4 = (unsigned char *)&IP.v6.sin6_addr.s6_addr32[3];
245  else {if ((IN6_IS_ADDR_LINKLOCAL(&IP.v6.sin6_addr))
246  || (IN6_IS_ADDR_SITELOCAL(&IP.v6.sin6_addr))
247  || (IN6_IS_ADDR_UNIQLOCAL(&IP.v6.sin6_addr))
248  || (IN6_IS_ADDR_LOOPBACK (&IP.v6.sin6_addr))) return true;
249  return false;
250  }
251  }
252 
253 // If this is not an IPV4 address then we will consider it private
254 //
255  if (!ipV4)
256  {if (IP.Addr.sa_family != AF_INET) return true;
257  ipV4 = (unsigned char *)&IP.v4.sin_addr.s_addr;
258  }
259 
260 // For IPV4 we use the RFC definition of private. Note that this includes
261 // mapped addresses which, as odd as it is, we could get.
262 //
263  if (ipV4[0] == 10
264  || (ipV4[0] == 172 && ipV4[1] >= 16 && ipV4[1] <= 31)
265  || (ipV4[0] == 192 && ipV4[1] == 168)
266  || (ipV4[0] == 169 && ipV4[1] == 254)
267  || ipV4[0] == 127) return true;
268 
269 // Not a local address
270 //
271  return false;
272 }
#define IN6_IS_ADDR_UNIQLOCAL(a)

References XrdNetSockAddr::Addr, if(), IN6_IS_ADDR_UNIQLOCAL, IP, and XrdNetSockAddr::v6.

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

+ Here is the call graph for this function:
+ 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 278 of file XrdNetAddrInfo.cc.

279 {
280  const char *hName;
281 
282 // Simply see if we can resolve this name
283 //
284  if (!(hName = Name())) return false;
285  return isHostName(hName);
286 }
static bool isHostName(const char *name)
const char * Name(const char *eName=0, const char **eText=0)

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 292 of file XrdNetAddrInfo.cc.

293 {
294  return (protFlgs & isTLS) != 0;
295 }
static const char isTLS
Location using TLS.

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 219 of file XrdNetAddrInfo.hh.

219 {return (addrLoc.Country[0] ? &addrLoc : 0);}
unsigned char Country[2]
Two letter TLD country code.

References addrLoc, and XrdNetAddrInfo::LocInfo::Country.

◆ LowCase()

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

Definition at line 301 of file XrdNetAddrInfo.cc.

302 {
303  unsigned char *sp = (unsigned char*)str;
304 
305  while(*sp) {if (isupper((int)*sp)) *sp = (char)tolower((int)*sp); sp++;}
306 
307  return str;
308 }

Referenced by Resolve(), 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
eNamevalue to return when the name cannot be determined.
eTextwhen 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 345 of file XrdNetAddrInfo.cc.

346 {
347  int rc;
348 
349 // Preset errtxt to zero
350 //
351  if (eText) *eText = 0;
352 
353 // Check for unix family which is equal to localhost.
354 //
355  if (IP.Addr.sa_family == AF_UNIX) return "localhost";
356 
357 // If we already translated this name, just return the translation
358 //
359  if (hostName || (dnsCache && (hostName = dnsCache->Find(this))))
360  return hostName;
361 
362 // Try to resolve this address
363 //
364  if (!(rc = Resolve())) return hostName;
365 
366 // We failed resolving this address
367 //
368  if (eText) *eText = gai_strerror(rc);
369  return eName;
370 }

References XrdNetSockAddr::Addr, dnsCache, XrdNetCache::Find(), 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(), XrdCl::AsyncSocketHandler::GetHostName(), getMyFQN(), XrdSecServer::getParms(), XrdNetUtils::Hosts(), XrdNetIF::InDomain(), XrdSsiFileResource::Init(), XrdOucReqID::isMine(), isRegistered(), main(), XrdNetSocket::Peername(), XrdCmsManager::Rerun(), XrdAccAccess::Resolve(), XrdNetMsg::retErr(), XrdMpxOut::Run(), XrdOfsTPCInfo::Set(), XrdNetIF::SetIF(), XrdNetSocket::SockData(), 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 246 of file XrdNetAddrInfo.hh.

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

References IP.

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

+ Here is the caller graph for this function:

◆ operator=()

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

Assignment operator.

Definition at line 312 of file XrdNetAddrInfo.hh.

313  {if (&rhs != this)
314  {memmove(&IP, &rhs.IP, sizeof(IP));
315  addrSize = rhs.addrSize; sockNum = rhs.sockNum;
316  protType = rhs.protType;
317  protFlgs = rhs.protFlgs;
318  protName = rhs.protName;
319  if (hostName) free(hostName);
320  hostName = (rhs.hostName ? strdup(rhs.hostName):0);
321  addrLoc = rhs.addrLoc;
322  if (rhs.sockAddr != &rhs.IP.Addr)
323  {if (!unixPipe || sockAddr == &IP.Addr)
324  unixPipe = new sockaddr_un;
325  memcpy(unixPipe, rhs.unixPipe, sizeof(sockaddr_un));
326  } else sockAddr = &IP.Addr;
327  }
328  return *this;
329  }

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

◆ 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 376 of file XrdNetAddrInfo.cc.

377 {
378 // Make sure we have a proper address family here
379 //
380  if (IP.Addr.sa_family != AF_INET && IP.Addr.sa_family != AF_INET6)
381  return -1;
382 
383 // Return port number
384 //
385  return ntohs(IP.v6.sin6_port);
386 }

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

Referenced by XrdNetAddr::Set().

+ Here is the caller graph for this function:

◆ 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 264 of file XrdNetAddrInfo.hh.

264 {return static_cast<int>(protType);}

References protType.

Referenced by XrdNetSocket::Open().

+ Here is the caller graph for this function:

◆ QFill()

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

Definition at line 392 of file XrdNetAddrInfo.cc.

393 {
394  static const char quests[] = "????????";
395 
396 // Insert up to 8 question marks
397 //
398  if (bLen)
399  {strncpy(bAddr, quests, bLen);
400  bAddr[bLen-1] = 0;
401  }
402  return 0;
403 }

Referenced by Format().

+ Here is the caller graph for this function:

◆ Resolve()

int XrdNetAddrInfo::Resolve ( )
protected

Definition at line 409 of file XrdNetAddrInfo.cc.

410 {
411  char hBuff[NI_MAXHOST];
412  int n, rc;
413 
414 // Free up hostname here
415 //
416  if (hostName) {free(hostName); hostName = 0;}
417 
418 // Determine the actual size of the address structure
419 //
420  if (IP.Addr.sa_family == AF_INET ) n = sizeof(IP.v4);
421  else if (IP.Addr.sa_family == AF_INET6) n = sizeof(IP.v6);
422  else if (IP.Addr.sa_family == AF_UNIX )
423  {hostName = strdup("localhost");
424  return 0;
425  }
426  else return EAI_FAMILY;
427 
428 // Do lookup of canonical name. If an error is returned we simply assume that
429 // the name is not resolvable and return the address as the host name.
430 //
431  if ((rc = getnameinfo(&IP.Addr, n, hBuff+1, sizeof(hBuff)-2, 0, 0, 0)))
432  {int ec = errno;
433  if (Format(hBuff, sizeof(hBuff), fmtAddr, noPort))
434  {hostName = strdup(hBuff); return 0;}
435  errno = ec;
436  return rc;
437  }
438 
439 // Handle the case when the mapping returned an actual name or an address
440 // We always want numeric ipv6 addresses surrounded by brackets. Additionally,
441 // some implementations of getnameinfo() return the scopeid when a numeric
442 // address is returned. We check and remove it.
443 //
444  if (!index(hBuff+1, ':')) hostName = strdup(LowCase(hBuff+1));
445  else {char *perCent = index(hBuff+1, '%');
446  if (perCent) *perCent = 0;
447  n = strlen(hBuff+1);
448  hBuff[0] = '['; hBuff[n+1] = ']'; hBuff[n+2] = 0;
449  hostName = strdup(hBuff);
450  }
451 
452 // Add the entry to the cache and return success
453 //
454  if (dnsCache) dnsCache->Add(this, hostName);
455  return 0;
456 }
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
char * LowCase(char *str)
void Add(XrdNetAddrInfo *hAddr, const char *hName)
Definition: XrdNetCache.cc:63

References XrdNetCache::Add(), XrdNetSockAddr::Addr, dnsCache, ec, fmtAddr, Format(), hostName, IP, LowCase(), noPort, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.

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
ipAddrpoints to the network address object to compare.
plusPortwhen 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 468 of file XrdNetAddrInfo.cc.

469 {
470  static const int ipv4ASZ = sizeof(IP.v4.sin_addr);
471 
472  bool isINet = IS_INET(MY_FAMILY) && IS_INET(UR_FAMILY);
473 
474 // Do port comparison if requested and makes sense to do it
475 //
476  if (plusPort && isINet)
477  {in_port_t port1, port2;
478  port1 = (MY_FAMILY == AF_INET ? IP.v4.sin_port : IP.v6.sin6_port);
479  port2 = (UR_FAMILY == AF_INET ? ipAddr->IP.v4.sin_port
480  : ipAddr->IP.v6.sin6_port);
481  if (port1 != port2) return 0;
482  }
483 
484 // If address families do not match, they are the same if the hostnames match.
485 // If we don't have a hostname and the addresses are convertable, we can
486 // compare the actual addresses.
487 //
488  if (MY_FAMILY != UR_FAMILY)
489  {if (!isINet) return 0;
490  if (hostName && ipAddr->hostName)
491  return !strcmp(hostName,ipAddr->hostName);
492  if (MY_FAMILY == AF_INET && ipAddr->isMapped())
493  return !memcmp(&IP.v4.sin_addr,
494  &(ipAddr->IP.v6.sin6_addr.s6_addr32[3]), ipv4ASZ);
495  if (isMapped() && UR_FAMILY == AF_INET)
496  return !memcmp(&IP.v6.sin6_addr.s6_addr32[3],
497  &(ipAddr->IP.v4.sin_addr), ipv4ASZ);
498  return 0;
499  }
500 
501 // Now process to do the match
502 //
503  if (MY_FAMILY == AF_INET)
504  return !memcmp(&IP.v4.sin_addr, &(ipAddr->IP.v4.sin_addr), ipv4ASZ);
505  else if (MY_FAMILY == AF_INET6)
506  return !memcmp(&IP.v6.sin6_addr, &(ipAddr->IP.v6.sin6_addr),
507  sizeof(IP.v6.sin6_addr));
508  else if (MY_FAMILY == AF_UNIX)
509  return !strcmp(unixPipe->sun_path, ipAddr->unixPipe->sun_path);
510 
511  return 0;
512 }
#define UR_FAMILY
#define IS_INET(x)
#define MY_FAMILY
bool isMapped() const

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

Referenced by XrdCmsNode::isNode(), and 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 289 of file XrdNetAddrInfo.hh.

289 {return sockAddr;}

Referenced by XrdConfig::Configure(), XrdNetSocket::Open(), XrdNetSocket::Peername(), 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 306 of file XrdNetAddrInfo.hh.

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

References sockNum.

Referenced by XrdInet::Accept(), XrdLinkCtl::Alloc(), XrdHttpTpc::PMarkManager::beginPMarks(), XrdInet::Connect(), XrdSecProtocolsss::getCredentials(), XrdHttpProtocol::Process(), 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 298 of file XrdNetAddrInfo.hh.

298 {return static_cast<SOCKLEN_t>(addrSize);}
#define SOCKLEN_t

References addrSize, and SOCKLEN_t.

Referenced by XrdNetSocket::Open(), XrdNetSocket::Peername(), and XrdNetMsg::Send().

+ Here is the caller graph for this function:

Member Data Documentation

◆ 

union { ... }

◆ addrLoc

LocInfo XrdNetAddrInfo::addrLoc
protected

Definition at line 373 of file XrdNetAddrInfo.hh.

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

◆ addrSize

unsigned short XrdNetAddrInfo::addrSize
protected

Definition at line 374 of file XrdNetAddrInfo.hh.

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

◆ dnsCache

XrdNetCache * XrdNetAddrInfo::dnsCache = 0
staticprotected

Definition at line 366 of file XrdNetAddrInfo.hh.

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

◆ hostName

char* XrdNetAddrInfo::hostName
protected

◆ IP

◆ isTLS

const char XrdNetAddrInfo::isTLS = 0x01
staticprotected

Location using TLS.

Definition at line 382 of file XrdNetAddrInfo.hh.

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

◆ noPort

◆ 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 376 of file XrdNetAddrInfo.hh.

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

◆ protName

const char* XrdNetAddrInfo::protName
protected

Definition at line 378 of file XrdNetAddrInfo.hh.

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

◆ protType

unsigned char XrdNetAddrInfo::protType
protected

Definition at line 375 of file XrdNetAddrInfo.hh.

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

◆ sockNum

int XrdNetAddrInfo::sockNum
protected

Definition at line 377 of file XrdNetAddrInfo.hh.

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


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