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