XRootD
Loading...
Searching...
No Matches
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#include <sstream>
36#include <cstdint>
37
38#include "XrdOuc/XrdOucEnum.hh"
39
40class XrdOucTList;
41class XrdNetAddr;
42union XrdNetSockAddr;
43
44namespace XrdNetSpace {struct hpSpec;}
45
47{
48public:
49
50//------------------------------------------------------------------------------
60//------------------------------------------------------------------------------
61
62static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen);
63
64//------------------------------------------------------------------------------
76//------------------------------------------------------------------------------
77
78static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1);
79
80
81//------------------------------------------------------------------------------
123//------------------------------------------------------------------------------
124
127 prefAuto= 16, order46 = 32, order64 = 64,
129 };
130
131static const int PortInSpec = (int)0x80000000;
132static const int NoPortRaw = (int)0xC0000000;
133
134static
135const char *GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN,
136 AddrOpts opts=allIPMap, int pNum=PortInSpec);
137
138//------------------------------------------------------------------------------
153//------------------------------------------------------------------------------
154
155static
156const char *GetAddrs(const std::string &hSpec, std::vector<XrdNetAddr> &aVec,
157 int *ordn=0, AddrOpts opts=allIPMap, int pNum=PortInSpec);
158
159//------------------------------------------------------------------------------
177//------------------------------------------------------------------------------
178
179static
180const char *GetAddrs(std::vector<std::string> &hSVec,
181 std::vector<XrdNetAddr> &aVec,
182 int *ordn=0, AddrOpts opts=allIPMap,
183 unsigned int rotNum=0, bool force=false);
184
185//------------------------------------------------------------------------------
204//------------------------------------------------------------------------------
205
206static
207int GetSokInfo(int fd, char *theAddr, int theALen, char &theType);
208
209//------------------------------------------------------------------------------
229//------------------------------------------------------------------------------
230
231static
232XrdOucTList *Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0,
233 const char **eText=0);
234
235//------------------------------------------------------------------------------
253//------------------------------------------------------------------------------
254
255static const int noPort = 1;
256static const int oldFmt = 2;
257
258static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0);
259
260//------------------------------------------------------------------------------
280//------------------------------------------------------------------------------
281
282static int IPFormat(int fd, char *bP, int bL, int opts=0);
283
284//------------------------------------------------------------------------------
300//------------------------------------------------------------------------------
301
302static bool Match(const char *hName, const char *pattern);
303
304//------------------------------------------------------------------------------
317//------------------------------------------------------------------------------
318
319static char *MyHostName(const char *eName="*unknown*", const char **eText=0);
320
321//------------------------------------------------------------------------------
331//------------------------------------------------------------------------------
332
333enum NetProt {hasNone = 0,
334 hasIPv4 = 1, //<! Has only IPv4 capability
335 hasIPv6 = 2, //<! Has only IPv6 capability
336 hasIP64 = 3, //<! Has IPv4 IPv6 capability (dual stack)
337 hasPub4 = 4, //<! Has IPv4 public address (or'd with above)
338 hasPub6 = 8 //<! Has IPv6 public address (or'd with above)
339 };
340
341enum NetType {qryINET = 0,
343 };
344
345static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0);
346
347//------------------------------------------------------------------------------
363//------------------------------------------------------------------------------
364
365static bool Parse(const char *hSpec, const char **hName, const char **hNend,
366 const char **hPort, const char **hPend);
367
368//------------------------------------------------------------------------------
376//------------------------------------------------------------------------------
377
378static int Port(int fd, const char **eText=0);
379
380//------------------------------------------------------------------------------
386//------------------------------------------------------------------------------
387
388static int ProtoID(const char *pName);
389
390//------------------------------------------------------------------------------
399//------------------------------------------------------------------------------
400
401static int ServPort(const char *sName, bool isUDP=false, const char **eText=0);
402
403//------------------------------------------------------------------------------
414//------------------------------------------------------------------------------
415
416static int SetAuto(AddrOpts aOpts=allIPMap);
417
418//------------------------------------------------------------------------------
426//------------------------------------------------------------------------------
427
428static bool Singleton(const char *hSpec, const char **eText=0);
429
430static bool ConnectWithTimeout(int sockfd, const struct sockaddr* clientAddr, size_t clientAddrLen,uint32_t timeout_sec, std::stringstream & errMsg);
431
432//------------------------------------------------------------------------------
434//------------------------------------------------------------------------------
435
437
438//------------------------------------------------------------------------------
440//------------------------------------------------------------------------------
441
443private:
444
445static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec,
446 int *ordn=0, unsigned int rotNum=0);
447static
448const char *GetAInfo(XrdNetSpace::hpSpec &aBuff);
449static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts);
450static
451const char *GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum);
452static
453const char *getMyFQN(const char *&myDom);
454static int setET(const char **errtxt, int rc);
455static bool SetSockBlocking(int sockfd, bool blocking, std::stringstream & errMsg);
456static int autoFamily;
457static int autoHints;
458};
459
461
462#endif
#define XRDOUC_ENUM_OPERATORS(T)
Definition XrdOucEnum.hh:22
static String ProtoID
struct myOpts opts
static const int NoPortRaw
static bool Match(const char *hName, const char *pattern)
@ qryINET
Only consider internet protocols via DNS.
@ qryINIF
Only consider internet protocols via ifconfig.
static char * MyHostName(const char *eName="*unknown*", const char **eText=0)
static int GetSokInfo(int fd, char *theAddr, int theALen, char &theType)
static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1)
@ hasNone
Unable to determine available protocols.
static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0)
static bool Singleton(const char *hSpec, const char **eText=0)
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)
static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0)
static const int PortInSpec
static bool ConnectWithTimeout(int sockfd, const struct sockaddr *clientAddr, size_t clientAddrLen, uint32_t timeout_sec, std::stringstream &errMsg)
static int Port(int fd, const char **eText=0)
~XrdNetUtils()
Destructor.
static const int oldFmt
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
static XrdOucTList * Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0, const char **eText=0)
XrdNetUtils()
Constructor.
static const int noPort
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
static int SetAuto(AddrOpts aOpts=allIPMap)