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) 2025 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//------------------------------------------------------------------------------
61//------------------------------------------------------------------------------
62
64
65static
66IPComp Compare(XrdNetSockAddr& ip1, XrdNetSockAddr& ip2, bool* psame=0);
67
68//------------------------------------------------------------------------------
78//------------------------------------------------------------------------------
79
80static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen);
81
82//------------------------------------------------------------------------------
94//------------------------------------------------------------------------------
95
96static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1);
97
98
99//------------------------------------------------------------------------------
141//------------------------------------------------------------------------------
142
145 prefAuto= 16, order46 = 32, order64 = 64,
147 };
148
149static const int PortInSpec = (int)0x80000000;
150static const int NoPortRaw = (int)0xC0000000;
151
152static
153const char *GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN,
154 AddrOpts opts=allIPMap, int pNum=PortInSpec);
155
156//------------------------------------------------------------------------------
171//------------------------------------------------------------------------------
172
173static
174const char *GetAddrs(const std::string &hSpec, std::vector<XrdNetAddr> &aVec,
175 int *ordn=0, AddrOpts opts=allIPMap, int pNum=PortInSpec);
176
177//------------------------------------------------------------------------------
195//------------------------------------------------------------------------------
196
197static
198const char *GetAddrs(std::vector<std::string> &hSVec,
199 std::vector<XrdNetAddr> &aVec,
200 int *ordn=0, AddrOpts opts=allIPMap,
201 unsigned int rotNum=0, bool force=false);
202
203//------------------------------------------------------------------------------
222//------------------------------------------------------------------------------
223
224static
225int GetSokInfo(int fd, char *theAddr, int theALen, char &theType);
226
227//------------------------------------------------------------------------------
247//------------------------------------------------------------------------------
248
249static
250XrdOucTList *Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0,
251 const char **eText=0);
252
253//------------------------------------------------------------------------------
271//------------------------------------------------------------------------------
272
273static const int noPort = 1;
274static const int oldFmt = 2;
275
276static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0);
277
278//------------------------------------------------------------------------------
298//------------------------------------------------------------------------------
299
300static int IPFormat(int fd, char *bP, int bL, int opts=0);
301
302//------------------------------------------------------------------------------
318//------------------------------------------------------------------------------
319
320static bool Match(const char *hName, const char *pattern);
321
322//------------------------------------------------------------------------------
335//------------------------------------------------------------------------------
336
337static char *MyHostName(const char *eName="*unknown*", const char **eText=0);
338
339//------------------------------------------------------------------------------
349//------------------------------------------------------------------------------
350
351enum NetProt {hasNone = 0,
352 hasIPv4 = 1, //<! Has only IPv4 capability
353 hasIPv6 = 2, //<! Has only IPv6 capability
354 hasIP64 = 3, //<! Has IPv4 IPv6 capability (dual stack)
355 hasPub4 = 4, //<! Has IPv4 public address (or'd with above)
356 hasPub6 = 8 //<! Has IPv6 public address (or'd with above)
357 };
358
359enum NetType {qryINET = 0,
361 };
362
363static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0);
364
365//------------------------------------------------------------------------------
381//------------------------------------------------------------------------------
382
383static bool Parse(const char *hSpec, const char **hName, const char **hNend,
384 const char **hPort, const char **hPend);
385
386//------------------------------------------------------------------------------
394//------------------------------------------------------------------------------
395
396static int Port(int fd, const char **eText=0);
397
398//------------------------------------------------------------------------------
404//------------------------------------------------------------------------------
405
406static int ProtoID(const char *pName);
407
408//------------------------------------------------------------------------------
417//------------------------------------------------------------------------------
418
419static int ServPort(const char *sName, bool isUDP=false, const char **eText=0);
420
421//------------------------------------------------------------------------------
432//------------------------------------------------------------------------------
433
434static int SetAuto(AddrOpts aOpts=allIPMap);
435
436//------------------------------------------------------------------------------
444//------------------------------------------------------------------------------
445
446static bool Singleton(const char *hSpec, const char **eText=0);
447
448static bool ConnectWithTimeout(int sockfd, const struct sockaddr* clientAddr, size_t clientAddrLen,uint32_t timeout_sec, std::stringstream & errMsg);
449
450//------------------------------------------------------------------------------
452//------------------------------------------------------------------------------
453
455
456//------------------------------------------------------------------------------
458//------------------------------------------------------------------------------
459
461private:
462
463static void FillAddr(XrdNetSpace::hpSpec &aBuff, XrdNetAddr *aVec,
464 int *ordn=0, unsigned int rotNum=0);
465static
466const char *GetAInfo(XrdNetSpace::hpSpec &aBuff);
467static void GetHints(XrdNetSpace::hpSpec &aBuff, AddrOpts opts);
468static
469const char *GetHostPort(XrdNetSpace::hpSpec &aBuff, const char *hSpec, int pNum);
470static
471const char *getMyFQN(const char *&myDom);
472static int setET(const char **errtxt, int rc);
473static bool SetSockBlocking(int sockfd, bool blocking, std::stringstream & errMsg);
474static int autoFamily;
475static int autoHints;
476};
477
479
480#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)
static IPComp Compare(XrdNetSockAddr &ip1, XrdNetSockAddr &ip2, bool *psame=0)
@ 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)