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 //------------------------------------------------------------------------------
203 //------------------------------------------------------------------------------
204 
205 static
206 XrdOucTList *Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0,
207  const char **eText=0);
208 
209 //------------------------------------------------------------------------------
227 //------------------------------------------------------------------------------
228 
229 static const int noPort = 1;
230 static const int oldFmt = 2;
231 
232 static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0);
233 
234 //------------------------------------------------------------------------------
254 //------------------------------------------------------------------------------
255 
256 static int IPFormat(int fd, char *bP, int bL, int opts=0);
257 
258 //------------------------------------------------------------------------------
274 //------------------------------------------------------------------------------
275 
276 static bool Match(const char *hName, const char *pattern);
277 
278 //------------------------------------------------------------------------------
291 //------------------------------------------------------------------------------
292 
293 static char *MyHostName(const char *eName="*unknown*", const char **eText=0);
294 
295 //------------------------------------------------------------------------------
305 //------------------------------------------------------------------------------
306 
307 enum NetProt {hasNone = 0,
308  hasIPv4 = 1, //<! Has only IPv4 capability
309  hasIPv6 = 2, //<! Has only IPv6 capability
310  hasIP64 = 3, //<! Has IPv4 IPv6 capability (dual stack)
311  hasPub4 = 4, //<! Has IPv4 public address (or'd with above)
312  hasPub6 = 8 //<! Has IPv6 public address (or'd with above)
313  };
314 
315 enum NetType {qryINET = 0,
316  qryINIF = 1
317  };
318 
319 static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0);
320 
321 //------------------------------------------------------------------------------
337 //------------------------------------------------------------------------------
338 
339 static bool Parse(const char *hSpec, const char **hName, const char **hNend,
340  const char **hPort, const char **hPend);
341 
342 //------------------------------------------------------------------------------
350 //------------------------------------------------------------------------------
351 
352 static int Port(int fd, const char **eText=0);
353 
354 //------------------------------------------------------------------------------
361 //------------------------------------------------------------------------------
362 
363 static int ProtoID(const char *pName);
364 
365 //------------------------------------------------------------------------------
374 //------------------------------------------------------------------------------
375 
376 static int ServPort(const char *sName, bool isUDP=false, const char **eText=0);
377 
378 //------------------------------------------------------------------------------
389 //------------------------------------------------------------------------------
390 
391 static int SetAuto(AddrOpts aOpts=allIPMap);
392 
393 //------------------------------------------------------------------------------
401 //------------------------------------------------------------------------------
402 
403 static bool Singleton(const char *hSpec, const char **eText=0);
404 
405 //------------------------------------------------------------------------------
407 //------------------------------------------------------------------------------
408 
410 
411 //------------------------------------------------------------------------------
413 //------------------------------------------------------------------------------
414 
416 private:
417 
418 static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec,
419  int *ordn=0, unsigned int rotNum=0);
420 static
421 const char *GetAInfo(XrdNetSpace::hpSpec &aBuff);
422 static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts);
423 static
424 const char *GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum);
425 static int setET(const char **errtxt, int rc);
426 static int autoFamily;
427 static int autoHints;
428 };
429 
431 
432 #endif
static const char * GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum)
Definition: XrdNetUtils.hh:123
static const int PortInSpec
Definition: XrdNetUtils.hh:129
static int autoFamily
Definition: XrdNetUtils.hh:426
static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec, int *ordn=0, unsigned int rotNum=0)
static int ProtoID(const char *pName)
Definition: XrdNetUtils.hh:309
Definition: XrdNetUtils.hh:125
Definition: XrdNetUtils.hh:308
Definition: XrdNetUtils.hh:123
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1)
Definition: XrdNetUtils.hh:124
Definition: XrdNetUtils.hh:312
static bool Singleton(const char *hSpec, const char **eText=0)
static int Port(int fd, const char **eText=0)
NetType
Definition: XrdNetUtils.hh:315
~XrdNetUtils()
Destructor.
Definition: XrdNetUtils.hh:415
Definition: XrdNetAddr.hh:41
Definition: XrdNetUtils.hh:44
Definition: XrdNetUtils.hh:311
Definition: XrdNetSockAddr.hh:43
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)
static int autoHints
Definition: XrdNetUtils.hh:427
Definition: XrdNetUtils.hh:310
static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts)
AddrOpts
Definition: XrdNetUtils.hh:123
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
Definition: XrdNetUtils.hh:124
static int SetAuto(AddrOpts aOpts=allIPMap)
Only consider internet protocols via ifconfig.
Definition: XrdNetUtils.hh:316
Definition: XrdNetUtils.hh:42
static char * MyHostName(const char *eName="*unknown*", const char **eText=0)
Definition: XrdOucTList.hh:41
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
static XrdOucTList * Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0, const char **eText=0)
Unable to determine available protocols.
Definition: XrdNetUtils.hh:307
static const char * GetAInfo(XrdNetSpace::hpSpec &aBuff)
static const int noPort
Definition: XrdNetUtils.hh:229
Definition: XrdNetUtils.hh:125
static const int NoPortRaw
Definition: XrdNetUtils.hh:130
Definition: XrdNetUtils.hh:125
Definition: XrdNetUtils.hh:124
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
Definition: XrdNetUtils.hh:126
NetProt
Definition: XrdNetUtils.hh:307
static const int oldFmt
Definition: XrdNetUtils.hh:230
static bool Match(const char *hName, const char *pattern)
XrdNetUtils()
Constructor.
Definition: XrdNetUtils.hh:409
static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0)
Definition: XrdNetUtils.hh:123
static int setET(const char **errtxt, int rc)
Only consider internet protocols via DNS.
Definition: XrdNetUtils.hh:315
static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0)