xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 //------------------------------------------------------------------------------
385 //------------------------------------------------------------------------------
386 
387 static int ProtoID(const char *pName);
388 
389 //------------------------------------------------------------------------------
398 //------------------------------------------------------------------------------
399 
400 static int ServPort(const char *sName, bool isUDP=false, const char **eText=0);
401 
402 //------------------------------------------------------------------------------
413 //------------------------------------------------------------------------------
414 
415 static int SetAuto(AddrOpts aOpts=allIPMap);
416 
417 //------------------------------------------------------------------------------
425 //------------------------------------------------------------------------------
426 
427 static bool Singleton(const char *hSpec, const char **eText=0);
428 
429 //------------------------------------------------------------------------------
431 //------------------------------------------------------------------------------
432 
434 
435 //------------------------------------------------------------------------------
437 //------------------------------------------------------------------------------
438 
440 private:
441 
442 static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec,
443  int *ordn=0, unsigned int rotNum=0);
444 static
445 const char *GetAInfo(XrdNetSpace::hpSpec &aBuff);
446 static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts);
447 static
448 const char *GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum);
449 static
450 const char *getMyFQN(const char *&myDom);
451 static int setET(const char **errtxt, int rc);
452 static int autoFamily;
453 static int autoHints;
454 };
455 
457 
458 #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:452
static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec, int *ordn=0, unsigned int rotNum=0)
static int ProtoID(const char *pName)
Definition: XrdNetUtils.hh:333
Definition: XrdNetUtils.hh:125
Definition: XrdNetUtils.hh:332
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:336
static bool Singleton(const char *hSpec, const char **eText=0)
static int Port(int fd, const char **eText=0)
NetType
Definition: XrdNetUtils.hh:339
~XrdNetUtils()
Destructor.
Definition: XrdNetUtils.hh:439
Definition: XrdNetAddr.hh:41
Definition: XrdNetUtils.hh:44
Definition: XrdNetUtils.hh:335
Definition: XrdNetSockAddr.hh:43
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)
static int autoHints
Definition: XrdNetUtils.hh:453
Definition: XrdNetUtils.hh:334
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:340
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:331
static const char * GetAInfo(XrdNetSpace::hpSpec &aBuff)
static const int noPort
Definition: XrdNetUtils.hh:253
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:331
static const int oldFmt
Definition: XrdNetUtils.hh:254
static bool Match(const char *hName, const char *pattern)
XrdNetUtils()
Constructor.
Definition: XrdNetUtils.hh:433
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:339
static const char * getMyFQN(const char *&myDom)
static int GetSokInfo(int fd, char *theAddr, int theALen, char &theType)
static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0)