xrootd
XrdNetUtils.hh
Go to the documentation of this file.
1 #ifndef __XRDNETUTILS_HH__
2 #define __XRDNETUTILS_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d N e t U t i l s . h h */
6 /* */
7 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <string>
34 #include <vector>
35 
36 #include "XrdOuc/XrdOucEnum.hh"
37 
38 class XrdOucTList;
39 class XrdNetAddr;
40 union XrdNetSockAddr;
41 
42 namespace XrdNetSpace {struct hpSpec;}
43 
45 {
46 public:
47 
48 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 
60 static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen);
61 
62 //------------------------------------------------------------------------------
74 //------------------------------------------------------------------------------
75 
76 static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1);
77 
78 
79 //------------------------------------------------------------------------------
121 //------------------------------------------------------------------------------
122 
125  prefAuto= 16, order46 = 32, order64 = 64,
126  onlyUDP =128
127  };
128 
129 static const int PortInSpec = (int)0x80000000;
130 static const int NoPortRaw = (int)0xC0000000;
131 
132 static
133 const char *GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN,
134  AddrOpts opts=allIPMap, int pNum=PortInSpec);
135 
136 //------------------------------------------------------------------------------
151 //------------------------------------------------------------------------------
152 
153 static
154 const char *GetAddrs(const std::string &hSpec, std::vector<XrdNetAddr> &aVec,
155  int *ordn=0, AddrOpts opts=allIPMap, int pNum=PortInSpec);
156 
157 //------------------------------------------------------------------------------
175 //------------------------------------------------------------------------------
176 
177 static
178 const char *GetAddrs(std::vector<std::string> &hSVec,
179  std::vector<XrdNetAddr> &aVec,
180  int *ordn=0, AddrOpts opts=allIPMap,
181  unsigned int rotNum=0, bool force=false);
182 
183 //------------------------------------------------------------------------------
202 //------------------------------------------------------------------------------
203 
204 static
205 int GetSokInfo(int fd, char *theAddr, int theALen, char &theType);
206 
207 //------------------------------------------------------------------------------
227 //------------------------------------------------------------------------------
228 
229 static
230 XrdOucTList *Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0,
231  const char **eText=0);
232 
233 //------------------------------------------------------------------------------
251 //------------------------------------------------------------------------------
252 
253 static const int noPort = 1;
254 static const int oldFmt = 2;
255 
256 static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0);
257 
258 //------------------------------------------------------------------------------
278 //------------------------------------------------------------------------------
279 
280 static int IPFormat(int fd, char *bP, int bL, int opts=0);
281 
282 //------------------------------------------------------------------------------
298 //------------------------------------------------------------------------------
299 
300 static bool Match(const char *hName, const char *pattern);
301 
302 //------------------------------------------------------------------------------
315 //------------------------------------------------------------------------------
316 
317 static char *MyHostName(const char *eName="*unknown*", const char **eText=0);
318 
319 //------------------------------------------------------------------------------
329 //------------------------------------------------------------------------------
330 
331 enum NetProt {hasNone = 0,
332  hasIPv4 = 1, //<! Has only IPv4 capability
333  hasIPv6 = 2, //<! Has only IPv6 capability
334  hasIP64 = 3, //<! Has IPv4 IPv6 capability (dual stack)
335  hasPub4 = 4, //<! Has IPv4 public address (or'd with above)
336  hasPub6 = 8 //<! Has IPv6 public address (or'd with above)
337  };
338 
339 enum NetType {qryINET = 0,
340  qryINIF = 1
341  };
342 
343 static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0);
344 
345 //------------------------------------------------------------------------------
361 //------------------------------------------------------------------------------
362 
363 static bool Parse(const char *hSpec, const char **hName, const char **hNend,
364  const char **hPort, const char **hPend);
365 
366 //------------------------------------------------------------------------------
374 //------------------------------------------------------------------------------
375 
376 static int Port(int fd, const char **eText=0);
377 
378 //------------------------------------------------------------------------------
384 //------------------------------------------------------------------------------
385 
386 static int ProtoID(const char *pName);
387 
388 //------------------------------------------------------------------------------
397 //------------------------------------------------------------------------------
398 
399 static int ServPort(const char *sName, bool isUDP=false, const char **eText=0);
400 
401 //------------------------------------------------------------------------------
412 //------------------------------------------------------------------------------
413 
414 static int SetAuto(AddrOpts aOpts=allIPMap);
415 
416 //------------------------------------------------------------------------------
424 //------------------------------------------------------------------------------
425 
426 static bool Singleton(const char *hSpec, const char **eText=0);
427 
428 //------------------------------------------------------------------------------
430 //------------------------------------------------------------------------------
431 
433 
434 //------------------------------------------------------------------------------
436 //------------------------------------------------------------------------------
437 
439 private:
440 
441 static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec,
442  int *ordn=0, unsigned int rotNum=0);
443 static
444 const char *GetAInfo(XrdNetSpace::hpSpec &aBuff);
445 static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts);
446 static
447 const char *GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum);
448 static
449 const char *getMyFQN(const char *&myDom);
450 static int setET(const char **errtxt, int rc);
451 static int autoFamily;
452 static int autoHints;
453 };
454 
456 
457 #endif
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
Definition: XrdNetAddr.hh:42
Definition: XrdNetUtils.hh:45
static const int NoPortRaw
Definition: XrdNetUtils.hh:130
NetType
Definition: XrdNetUtils.hh:339
@ qryINET
Only consider internet protocols via DNS.
Definition: XrdNetUtils.hh:339
@ qryINIF
Only consider internet protocols via ifconfig.
Definition: XrdNetUtils.hh:340
static int autoFamily
Definition: XrdNetUtils.hh:451
static int Port(int fd, const char **eText=0)
static int ProtoID(const char *pName)
static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1)
NetProt
Definition: XrdNetUtils.hh:331
@ hasPub4
Definition: XrdNetUtils.hh:335
@ hasIP64
Definition: XrdNetUtils.hh:334
@ hasPub6
Definition: XrdNetUtils.hh:336
@ hasIPv6
Definition: XrdNetUtils.hh:333
@ hasNone
Unable to determine available protocols.
Definition: XrdNetUtils.hh:331
@ hasIPv4
Definition: XrdNetUtils.hh:332
static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts)
static char * MyHostName(const char *eName="*unknown*", const char **eText=0)
static const char * getMyFQN(const char *&myDom)
static int setET(const char **errtxt, int rc)
static XrdOucTList * Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0, const char **eText=0)
static const int PortInSpec
Definition: XrdNetUtils.hh:129
static bool Singleton(const char *hSpec, const char **eText=0)
static int IPFormat(int fd, char *bP, int bL, int opts=0)
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
static const char * GetAddrs(const std::string &hSpec, std::vector< XrdNetAddr > &aVec, int *ordn=0, AddrOpts opts=allIPMap, int pNum=PortInSpec)
static int autoHints
Definition: XrdNetUtils.hh:452
~XrdNetUtils()
Destructor.
Definition: XrdNetUtils.hh:438
static const int oldFmt
Definition: XrdNetUtils.hh:254
static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0)
static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec, int *ordn=0, unsigned int rotNum=0)
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
static const char * GetAInfo(XrdNetSpace::hpSpec &aBuff)
static int SetAuto(AddrOpts aOpts=allIPMap)
XrdNetUtils()
Constructor.
Definition: XrdNetUtils.hh:432
static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0)
static const int noPort
Definition: XrdNetUtils.hh:253
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)
static bool Match(const char *hName, const char *pattern)
static const char * GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum)
static int GetSokInfo(int fd, char *theAddr, int theALen, char &theType)
AddrOpts
Definition: XrdNetUtils.hh:123
@ prefAuto
Definition: XrdNetUtils.hh:125
@ allIPv64
Definition: XrdNetUtils.hh:123
@ prefIPv6
Definition: XrdNetUtils.hh:124
@ allV4Map
Definition: XrdNetUtils.hh:123
@ onlyUDP
Definition: XrdNetUtils.hh:126
@ order46
Definition: XrdNetUtils.hh:125
@ allIPMap
Definition: XrdNetUtils.hh:123
@ order64
Definition: XrdNetUtils.hh:125
@ onlyIPv4
Definition: XrdNetUtils.hh:124
@ onlyIPv6
Definition: XrdNetUtils.hh:124
static const char * GetAddrs(std::vector< std::string > &hSVec, std::vector< XrdNetAddr > &aVec, int *ordn=0, AddrOpts opts=allIPMap, unsigned int rotNum=0, bool force=false)
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
Definition: XrdOucTList.hh:42
Definition: XrdNetUtils.hh:42
Definition: XrdNetSockAddr.hh:43