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 "XrdOuc/XrdOucEnum.hh"
34 
35 class XrdOucTList;
36 class XrdNetAddr;
37 union XrdNetSockAddr;
38 
40 {
41 public:
42 
43 //------------------------------------------------------------------------------
53 //------------------------------------------------------------------------------
54 
55 static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen);
56 
57 //------------------------------------------------------------------------------
69 //------------------------------------------------------------------------------
70 
71 static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1);
72 
73 
74 //------------------------------------------------------------------------------
119 //------------------------------------------------------------------------------
120 
123  prefAuto= 16, onlyUDP =128
124  };
125 
126 static const int PortInSpec = (int)0x80000000;
127 static const int NoPortRaw = (int)0xC0000000;
128 
129 static
130 const char *GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN,
131  AddrOpts opts=allIPMap, int pNum=PortInSpec);
132 
133 //------------------------------------------------------------------------------
153 //------------------------------------------------------------------------------
154 
155 static
156 XrdOucTList *Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0,
157  const char **eText=0);
158 
159 //------------------------------------------------------------------------------
177 //------------------------------------------------------------------------------
178 
179 static const int noPort = 1;
180 static const int oldFmt = 2;
181 
182 static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0);
183 
184 //------------------------------------------------------------------------------
204 //------------------------------------------------------------------------------
205 
206 static int IPFormat(int fd, char *bP, int bL, int opts=0);
207 
208 //------------------------------------------------------------------------------
224 //------------------------------------------------------------------------------
225 
226 static bool Match(const char *hName, const char *pattern);
227 
228 //------------------------------------------------------------------------------
241 //------------------------------------------------------------------------------
242 
243 static char *MyHostName(const char *eName="*unknown*", const char **eText=0);
244 
245 //------------------------------------------------------------------------------
255 //------------------------------------------------------------------------------
256 
257 enum NetProt {hasNone = 0,
258  hasIPv4 = 1, //<! Has only IPv4 capability
259  hasIPv6 = 2, //<! Has only IPv6 capability
260  hasIP64 = 3, //<! Has IPv4 IPv6 capability (dual stack)
261  hasPub4 = 4, //<! Has IPv4 public address (or'd with above)
262  hasPub6 = 8 //<! Has IPv6 public address (or'd with above)
263  };
264 
265 enum NetType {qryINET = 0,
266  qryINIF = 1
267  };
268 
269 static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0);
270 
271 //------------------------------------------------------------------------------
287 //------------------------------------------------------------------------------
288 
289 static bool Parse(const char *hSpec, const char **hName, const char **hNend,
290  const char **hPort, const char **hPend);
291 
292 //------------------------------------------------------------------------------
300 //------------------------------------------------------------------------------
301 
302 static int Port(int fd, char **eText=0);
303 
304 //------------------------------------------------------------------------------
311 //------------------------------------------------------------------------------
312 
313 static int ProtoID(const char *pName);
314 
315 //------------------------------------------------------------------------------
324 //------------------------------------------------------------------------------
325 
326 static int ServPort(const char *sName, bool isUDP=false, const char **eText=0);
327 
328 //------------------------------------------------------------------------------
339 //------------------------------------------------------------------------------
340 
341 static int SetAuto(AddrOpts aOpts=allIPMap);
342 
343 //------------------------------------------------------------------------------
345 //------------------------------------------------------------------------------
346 
348 
349 //------------------------------------------------------------------------------
351 //------------------------------------------------------------------------------
352 
354 private:
355 
356 static int setET(char **errtxt, int rc);
357 static int autoFamily;
358 static int autoHints;
359 };
360 
362 
363 #endif
XrdNetUtils::NetConfig
static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0)
XrdNetUtils::allV4Map
@ allV4Map
Definition: XrdNetUtils.hh:121
XrdNetUtils::GetAddrs
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
XrdNetUtils::Encode
static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1)
XrdNetUtils::autoFamily
static int autoFamily
Definition: XrdNetUtils.hh:357
XrdNetUtils::prefIPv6
@ prefIPv6
Definition: XrdNetUtils.hh:122
XrdNetUtils::NetType
NetType
Definition: XrdNetUtils.hh:265
XrdNetUtils::hasIPv4
@ hasIPv4
Definition: XrdNetUtils.hh:258
XrdNetUtils::PortInSpec
static const int PortInSpec
Definition: XrdNetUtils.hh:126
XrdNetUtils::~XrdNetUtils
~XrdNetUtils()
Destructor.
Definition: XrdNetUtils.hh:353
XrdNetUtils::allIPv64
@ allIPv64
Definition: XrdNetUtils.hh:121
XrdNetUtils::hasIPv6
@ hasIPv6
Definition: XrdNetUtils.hh:259
XrdNetUtils::ProtoID
static int ProtoID(const char *pName)
XrdNetUtils::Decode
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)
XrdOucEnum.hh
XrdNetUtils::hasPub4
@ hasPub4
Definition: XrdNetUtils.hh:261
XrdNetUtils::onlyIPv6
@ onlyIPv6
Definition: XrdNetUtils.hh:122
XrdNetUtils::hasPub6
@ hasPub6
Definition: XrdNetUtils.hh:262
XrdNetUtils::prefAuto
@ prefAuto
Definition: XrdNetUtils.hh:123
XrdNetUtils::ServPort
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
XrdNetUtils::autoHints
static int autoHints
Definition: XrdNetUtils.hh:358
XRDOUC_ENUM_OPERATORS
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
XrdNetUtils::Parse
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
XrdNetUtils::Hosts
static XrdOucTList * Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0, const char **eText=0)
XrdNetUtils::AddrOpts
AddrOpts
Definition: XrdNetUtils.hh:121
XrdNetUtils::SetAuto
static int SetAuto(AddrOpts aOpts=allIPMap)
XrdNetUtils::MyHostName
static char * MyHostName(const char *eName="*unknown*", const char **eText=0)
XrdNetSockAddr
Definition: XrdNetSockAddr.hh:43
XrdNetUtils::hasNone
@ hasNone
Unable to determine available protocols.
Definition: XrdNetUtils.hh:257
XrdNetUtils::onlyIPv4
@ onlyIPv4
Definition: XrdNetUtils.hh:122
XrdNetUtils::NoPortRaw
static const int NoPortRaw
Definition: XrdNetUtils.hh:127
XrdNetUtils
Definition: XrdNetUtils.hh:39
XrdNetUtils::hasIP64
@ hasIP64
Definition: XrdNetUtils.hh:260
XrdNetUtils::allIPMap
@ allIPMap
Definition: XrdNetUtils.hh:121
XrdNetUtils::qryINIF
@ qryINIF
Only consider internet protocols via ifconfig.
Definition: XrdNetUtils.hh:266
XrdNetUtils::noPort
static const int noPort
Definition: XrdNetUtils.hh:179
XrdNetUtils::qryINET
@ qryINET
Only consider internet protocols via DNS.
Definition: XrdNetUtils.hh:265
XrdNetUtils::setET
static int setET(char **errtxt, int rc)
XrdNetUtils::onlyUDP
@ onlyUDP
Definition: XrdNetUtils.hh:123
XrdNetUtils::IPFormat
static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0)
XrdNetAddr
Definition: XrdNetAddr.hh:41
XrdNetUtils::Port
static int Port(int fd, char **eText=0)
XrdOucTList
Definition: XrdOucTList.hh:41
XrdNetUtils::NetProt
NetProt
Definition: XrdNetUtils.hh:257
XrdNetUtils::oldFmt
static const int oldFmt
Definition: XrdNetUtils.hh:180
XrdNetUtils::Match
static bool Match(const char *hName, const char *pattern)
XrdNetUtils::XrdNetUtils
XrdNetUtils()
Constructor.
Definition: XrdNetUtils.hh:347