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
Definition: XrdNetUtils.hh:121
static const int PortInSpec
Definition: XrdNetUtils.hh:126
static int autoFamily
Definition: XrdNetUtils.hh:357
static int ProtoID(const char *pName)
Definition: XrdNetUtils.hh:259
Definition: XrdNetUtils.hh:123
Definition: XrdNetUtils.hh:258
Definition: XrdNetUtils.hh:121
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:122
Definition: XrdNetUtils.hh:262
NetType
Definition: XrdNetUtils.hh:265
~XrdNetUtils()
Destructor.
Definition: XrdNetUtils.hh:353
Definition: XrdNetAddr.hh:41
Definition: XrdNetUtils.hh:39
Definition: XrdNetUtils.hh:261
Definition: XrdNetSockAddr.hh:43
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)
static int autoHints
Definition: XrdNetUtils.hh:358
Definition: XrdNetUtils.hh:260
AddrOpts
Definition: XrdNetUtils.hh:121
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
Definition: XrdNetUtils.hh:122
static int SetAuto(AddrOpts aOpts=allIPMap)
Only consider internet protocols via ifconfig.
Definition: XrdNetUtils.hh:266
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:257
static const int noPort
Definition: XrdNetUtils.hh:179
static int setET(char **errtxt, int rc)
static const int NoPortRaw
Definition: XrdNetUtils.hh:127
Definition: XrdNetUtils.hh:122
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
Definition: XrdNetUtils.hh:123
NetProt
Definition: XrdNetUtils.hh:257
static const int oldFmt
Definition: XrdNetUtils.hh:180
static bool Match(const char *hName, const char *pattern)
XrdNetUtils()
Constructor.
Definition: XrdNetUtils.hh:347
static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0)
Definition: XrdNetUtils.hh:121
Only consider internet protocols via DNS.
Definition: XrdNetUtils.hh:265
static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0)
static int Port(int fd, char **eText=0)