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

#include <XrdNetAddrInfo.hh>

+ Inheritance diagram for XrdNetAddrInfo:
+ Collaboration diagram for XrdNetAddrInfo:

Classes

struct  LocInfo
 

Public Types

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

Public Member Functions

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

Static Public Member Functions

static bool isHostName (const char *name)
 

Static Public Attributes

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

Protected Member Functions

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

Protected Attributes

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

Static Protected Attributes

static XrdNetCachednsCache = 0
 
static const char isTLS = 0x01
 Location using TLS.
 

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

327 {hostName = 0;
328 unixPipe = 0;
329 *this = oP;
330 }

References hostName.

◆ XrdNetAddrInfo() [2/3]

XrdNetAddrInfo::XrdNetAddrInfo ( )
inline

Constructor.

Definition at line 336 of file XrdNetAddrInfo.hh.

336 : hostName(0), addrSize(0), protType(0),
337 protFlgs(0), sockNum(0), protName(0)
338 {IP.Addr.sa_family = 0;
339 sockAddr = &IP.Addr;
340 }
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 342 of file XrdNetAddrInfo.hh.

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

◆ ~XrdNetAddrInfo()

XrdNetAddrInfo::~XrdNetAddrInfo ( )
inline

Destructor.

Definition at line 348 of file XrdNetAddrInfo.hh.

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

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)

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

279{
280 const char *dot;
281 int dnum;
282
283// First check for Iv6 format or hostname
284//
285 if (*name == '[') return false;
286 if (!isdigit(*name)) return true;
287
288// The IPv4 case is more complicated. The fastest way here is this is a
289// host name if there are no dots or if the last component is not a digit
290// according to the RFC spec.
291//
292 if (!(dot = rindex(name, '.')) || !isdigit(*(dot+1))) return true;
293
294// We are not out of the woods yet. Now we need to do a full check.
295//
296 name++; dnum = 0;
297 while(*name)
298 {if (*name == '.') dnum++;
299 else if (!isdigit(*name)) return true;
300 name++;
301 }
302 return (dnum == 3 ? false : true);
303}

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

+ Here is the caller graph for this function:

◆ isIPType()

bool XrdNetAddrInfo::isIPType ( IPType ipType) const
inline

Definition at line 146 of file XrdNetAddrInfo.hh.

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:

◆ isLoopback()

bool XrdNetAddrInfo::isLoopback ( )

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

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

Definition at line 181 of file XrdNetAddrInfo.cc.

182{
183
184// Check for loopback address
185//
186 if (IP.Addr.sa_family == AF_INET)
187 return !memcmp(&IP.v4.sin_addr.s_addr, &lbVal[12], 1);
188
189 if (IP.Addr.sa_family == AF_INET6)
190 return !memcmp(&IP.v6.sin6_addr, &in6addr_loopback, sizeof(in6_addr))
191 || !memcmp(&IP.v6.sin6_addr, lbVal, sizeof(lbVal));
192
193 return false;
194}

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

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

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

201{
202 unsigned char *ipV4 = 0;
203
204// For IPV6 addresses we will use the macro unless it is mapped
205//
206 if (IP.Addr.sa_family == AF_INET6)
207 {if ((IN6_IS_ADDR_V4MAPPED(&IP.v6.sin6_addr)))
208 ipV4 = (unsigned char *)&IP.v6.sin6_addr.s6_addr32[3];
209 else {if ((IN6_IS_ADDR_LINKLOCAL(&IP.v6.sin6_addr))
210 || (IN6_IS_ADDR_SITELOCAL(&IP.v6.sin6_addr))
211 || (IN6_IS_ADDR_UNIQLOCAL(&IP.v6.sin6_addr))
212 || (IN6_IS_ADDR_LOOPBACK (&IP.v6.sin6_addr))) return true;
213 return false;
214 }
215 }
216
217// If this is not an IPV4 address then we will consider it private
218//
219 if (!ipV4)
220 {if (IP.Addr.sa_family != AF_INET) return true;
221 ipV4 = (unsigned char *)&IP.v4.sin_addr.s_addr;
222 }
223
224// For IPV4 we use the RFC definition of private. Note that this includes
225// mapped addresses which, as odd as it is, we could get.
226//
227 if (ipV4[0] == 10
228 || (ipV4[0] == 172 && ipV4[1] >= 16 && ipV4[1] <= 31)
229 || (ipV4[0] == 192 && ipV4[1] == 168)
230 || (ipV4[0] == 169 && ipV4[1] == 254)
231 || ipV4[0] == 127) return true;
232
233// Not a local address
234//
235 return false;
236}
#define IN6_IS_ADDR_UNIQLOCAL(a)

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

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

+ Here is the caller graph for this function:

◆ isRegistered()

bool XrdNetAddrInfo::isRegistered ( )

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

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

Definition at line 242 of file XrdNetAddrInfo.cc.

243{
244 const char *hName;
245
246// Simply see if we can resolve this name
247//
248 if (!(hName = Name())) return false;
249 return isHostName(hName);
250}
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 256 of file XrdNetAddrInfo.cc.

257{
258 return (protFlgs & isTLS) != 0;
259}
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 210 of file XrdNetAddrInfo.hh.

210{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 265 of file XrdNetAddrInfo.cc.

266{
267 char *sp = str;
268
269 while(*sp) {if (isupper((int)*sp)) *sp = (char)tolower((int)*sp); sp++;}
270
271 return str;
272}

Referenced by Resolve().

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

310{
311 int rc;
312
313// Preset errtxt to zero
314//
315 if (eText) *eText = 0;
316
317// Check for unix family which is equal to localhost.
318//
319 if (IP.Addr.sa_family == AF_UNIX) return "localhost";
320
321// If we already translated this name, just return the translation
322//
323 if (hostName || (dnsCache && (hostName = dnsCache->Find(this))))
324 return hostName;
325
326// Try to resolve this address
327//
328 if (!(rc = Resolve())) return hostName;
329
330// We failed resolving this address
331//
332 if (eText) *eText = gai_strerror(rc);
333 return eName;
334}

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(), XrdSecServer::getParms(), XrdNetUtils::Hosts(), XrdNetIF::InDomain(), XrdSsiFileResource::Init(), XrdOucReqID::isMine(), isRegistered(), main(), XrdNetSocket::Peername(), XrdCmsManager::Rerun(), XrdAccAccess::Resolve(), XrdNetMsg::retErr(), XrdNetMsg::retErr(), XrdMpxOut::Run(), XrdOfsTPCInfo::Set(), XrdNetIF::SetIF(), XrdTlsNotary::Validate(), XrdOfsTPC::Verify(), XrdFfsMisc_get_list_of_data_servers(), XrdFfsMisc_getNameByAddr(), and XrdSecProtocolsssObject().

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

◆ NetAddr()

const XrdNetSockAddr * XrdNetAddrInfo::NetAddr ( )
inline

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

Definition at line 237 of file XrdNetAddrInfo.hh.

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

References IP.

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

+ Here is the caller graph for this function:

◆ operator=()

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

Assignment operator.

Definition at line 303 of file XrdNetAddrInfo.hh.

304 {if (&rhs != this)
305 {memmove(&IP, &rhs.IP, sizeof(IP));
306 addrSize = rhs.addrSize; sockNum = rhs.sockNum;
307 protType = rhs.protType;
308 protFlgs = rhs.protFlgs;
309 protName = rhs.protName;
310 if (hostName) free(hostName);
311 hostName = (rhs.hostName ? strdup(rhs.hostName):0);
312 addrLoc = rhs.addrLoc;
313 if (rhs.sockAddr != &rhs.IP.Addr)
314 {if (!unixPipe || sockAddr == &IP.Addr)
315 unixPipe = new sockaddr_un;
316 memcpy(unixPipe, rhs.unixPipe, sizeof(sockaddr_un));
317 } else sockAddr = &IP.Addr;
318 }
319 return *this;
320 }

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

341{
342// Make sure we have a proper address family here
343//
344 if (IP.Addr.sa_family != AF_INET && IP.Addr.sa_family != AF_INET6)
345 return -1;
346
347// Return port number
348//
349 return ntohs(IP.v6.sin6_port);
350}

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

255{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 356 of file XrdNetAddrInfo.cc.

357{
358 static const char quests[] = "????????";
359
360// Insert up to 8 question marks
361//
362 if (bLen)
363 {strncpy(bAddr, quests, bLen);
364 bAddr[bLen-1] = 0;
365 }
366 return 0;
367}

Referenced by Format().

+ Here is the caller graph for this function:

◆ Resolve()

int XrdNetAddrInfo::Resolve ( )
protected

Definition at line 373 of file XrdNetAddrInfo.cc.

374{
375 char hBuff[NI_MAXHOST];
376 int n, rc;
377
378// Free up hostname here
379//
380 if (hostName) {free(hostName); hostName = 0;}
381
382// Determine the actual size of the address structure
383//
384 if (IP.Addr.sa_family == AF_INET ) n = sizeof(IP.v4);
385 else if (IP.Addr.sa_family == AF_INET6) n = sizeof(IP.v6);
386 else if (IP.Addr.sa_family == AF_UNIX )
387 {hostName = strdup("localhost");
388 return 0;
389 }
390 else return EAI_FAMILY;
391
392// Do lookup of canonical name. If an error is returned we simply assume that
393// the name is not resolvable and return the address as the host name.
394//
395 if ((rc = getnameinfo(&IP.Addr, n, hBuff+1, sizeof(hBuff)-2, 0, 0, 0)))
396 {int ec = errno;
397 if (Format(hBuff, sizeof(hBuff), fmtAddr, noPort))
398 {hostName = strdup(hBuff); return 0;}
399 errno = ec;
400 return rc;
401 }
402
403// Handle the case when the mapping returned an actual name or an address
404// We always want numeric ipv6 addresses surrounded by brackets. Additionally,
405// some implementations of getnameinfo() return the scopeid when a numeric
406// address is returned. We check and remove it.
407//
408 if (!index(hBuff+1, ':')) hostName = strdup(LowCase(hBuff+1));
409 else {char *perCent = index(hBuff+1, '%');
410 if (perCent) *perCent = 0;
411 n = strlen(hBuff+1);
412 hBuff[0] = '['; hBuff[n+1] = ']'; hBuff[n+2] = 0;
413 hostName = strdup(hBuff);
414 }
415
416// Add the entry to the cache and return success
417//
418 if (dnsCache) dnsCache->Add(this, hostName);
419 return 0;
420}
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
char * LowCase(char *str)
void Add(XrdNetAddrInfo *hAddr, const char *hName)

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

433{
434 static const int ipv4ASZ = sizeof(IP.v4.sin_addr);
435
436 bool isINet = IS_INET(MY_FAMILY) && IS_INET(UR_FAMILY);
437
438// Do port comparison if requested and makes sense to do it
439//
440 if (plusPort && isINet)
441 {in_port_t port1, port2;
442 port1 = (MY_FAMILY == AF_INET ? IP.v4.sin_port : IP.v6.sin6_port);
443 port2 = (UR_FAMILY == AF_INET ? ipAddr->IP.v4.sin_port
444 : ipAddr->IP.v6.sin6_port);
445 if (port1 != port2) return 0;
446 }
447
448// If address families do not match, they are the same if the hostnames match.
449// If we don't have a hostname and the addresses are convertable, we can
450// compare the actual addresses.
451//
452 if (MY_FAMILY != UR_FAMILY)
453 {if (!isINet) return 0;
454 if (hostName && ipAddr->hostName)
455 return !strcmp(hostName,ipAddr->hostName);
456 if (MY_FAMILY == AF_INET && ipAddr->isMapped())
457 return !memcmp(&IP.v4.sin_addr,
458 &(ipAddr->IP.v6.sin6_addr.s6_addr32[3]), ipv4ASZ);
459 if (isMapped() && UR_FAMILY == AF_INET)
460 return !memcmp(&IP.v6.sin6_addr.s6_addr32[3],
461 &(ipAddr->IP.v4.sin_addr), ipv4ASZ);
462 return 0;
463 }
464
465// Now process to do the match
466//
467 if (MY_FAMILY == AF_INET)
468 return !memcmp(&IP.v4.sin_addr, &(ipAddr->IP.v4.sin_addr), ipv4ASZ);
469 else if (MY_FAMILY == AF_INET6)
470 return !memcmp(&IP.v6.sin6_addr, &(ipAddr->IP.v6.sin6_addr),
471 sizeof(IP.v6.sin6_addr));
472 else if (MY_FAMILY == AF_UNIX)
473 return !strcmp(unixPipe->sun_path, ipAddr->unixPipe->sun_path);
474
475 return 0;
476}
#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(), XrdCmsNode::isNode(), XrdNetAddr::Register(), and XrdCmsNode::setName().

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

◆ SockAddr()

const sockaddr * XrdNetAddrInfo::SockAddr ( )
inline

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

Definition at line 280 of file XrdNetAddrInfo.hh.

280{return sockAddr;}

Referenced by XrdConfig::Configure(), XrdCl::Socket::ConnectToAddress(), 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 297 of file XrdNetAddrInfo.hh.

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

References sockNum.

Referenced by XrdInet::Accept(), XrdLinkCtl::Alloc(), XrdTpc::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 289 of file XrdNetAddrInfo.hh.

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

References addrSize, and SOCKLEN_t.

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

+ Here is the caller graph for this function:

Member Data Documentation

◆ [union]

union { ... } XrdNetAddrInfo

◆ addrLoc

LocInfo XrdNetAddrInfo::addrLoc
protected

Definition at line 364 of file XrdNetAddrInfo.hh.

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

◆ addrSize

unsigned short XrdNetAddrInfo::addrSize
protected

◆ dnsCache

XrdNetCache * XrdNetAddrInfo::dnsCache = 0
staticprotected

Definition at line 357 of file XrdNetAddrInfo.hh.

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

◆ hostName

◆ IP

◆ isTLS

const char XrdNetAddrInfo::isTLS = 0x01
staticprotected

Location using TLS.

Definition at line 373 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 367 of file XrdNetAddrInfo.hh.

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

◆ protName

const char* XrdNetAddrInfo::protName
protected

Definition at line 369 of file XrdNetAddrInfo.hh.

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

◆ protType

unsigned char XrdNetAddrInfo::protType
protected

◆ sockNum

int XrdNetAddrInfo::sockNum
protected

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