![]() |
XRootD
|
#include <XrdNetUtils.hh>
Public Types | |
enum | AddrOpts { allIPMap = 0 , allIPv64 = 1 , allV4Map = 2 , onlyIPv6 = 3 , onlyIPv4 = 4 , prefIPv6 = 8 , prefAuto = 16 , order46 = 32 , order64 = 64 , onlyUDP =128 } |
enum | NetProt { hasNone = 0 , hasIPv4 = 1 , hasIPv6 = 2 , hasIP64 = 3 , hasPub4 = 4 , hasPub6 = 8 } |
enum | NetType { qryINET = 0 , qryINIF = 1 } |
Public Member Functions | |
XrdNetUtils () | |
Constructor. More... | |
~XrdNetUtils () | |
Destructor. More... | |
Static Public Member Functions | |
static bool | ConnectWithTimeout (int sockfd, const struct sockaddr *clientAddr, size_t clientAddrLen, uint32_t timeout_sec, std::stringstream &errMsg) |
static int | Decode (XrdNetSockAddr *sadr, const char *buff, int blen) |
static int | Encode (const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1) |
static const char * | GetAddrs (const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec) |
static const char * | GetAddrs (const std::string &hSpec, std::vector< XrdNetAddr > &aVec, int *ordn=0, AddrOpts opts=allIPMap, int pNum=PortInSpec) |
static const char * | GetAddrs (std::vector< std::string > &hSVec, std::vector< XrdNetAddr > &aVec, int *ordn=0, AddrOpts opts=allIPMap, unsigned int rotNum=0, bool force=false) |
static int | GetSokInfo (int fd, char *theAddr, int theALen, char &theType) |
static XrdOucTList * | Hosts (const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0, const char **eText=0) |
static int | IPFormat (const struct sockaddr *sAddr, char *bP, int bL, int opts=0) |
static int | IPFormat (int fd, char *bP, int bL, int opts=0) |
static bool | Match (const char *hName, const char *pattern) |
static char * | MyHostName (const char *eName="*unknown*", const char **eText=0) |
static NetProt | NetConfig (NetType netquery=qryINET, const char **eText=0) |
static bool | Parse (const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend) |
static int | Port (int fd, const char **eText=0) |
static int | ProtoID (const char *pName) |
static int | ServPort (const char *sName, bool isUDP=false, const char **eText=0) |
static int | SetAuto (AddrOpts aOpts=allIPMap) |
static bool | Singleton (const char *hSpec, const char **eText=0) |
Static Public Attributes | |
static const int | noPort = 1 |
static const int | NoPortRaw = (int)0xC0000000 |
static const int | oldFmt = 2 |
static const int | PortInSpec = (int)0x80000000 |
Definition at line 46 of file XrdNetUtils.hh.
Version 1: Return multiple addresses associated with a host or IP address.
hSpec | -> convert specification to addresses. Valid formats: IP.v4: nnn.nnn.nnn.nnn[:<port>] IP.v6: [ipv6_addr][:<port>] IP.xx: name[:port] xx is determined by getaddrinfo() |
aListP | place where the pointer to the returned array of XrdNetAddr objects is to be placed. Set to zero if none returned. The caller must delete this array when no longer needed. |
aListN | place where the number of elements in aListP are to be returned. |
opts | Options on what to return. Choose one of: allIPMap - all IPv6 and mapped IPv4 addrs (default) allIPv64 - all IPv6 and unmapped IPv4 addrs allV4Map - all mapped IPV4 addrs. onlyIPv6 - only IPv6 addrs onlyIPv4 - only unmapped IPv4 addrs prefIPv6 - only IPv6 addrs; if none, mapped IPv4 addrs prefAuto - Returns addresses based on configured non-local interfaces. The returned addresses will be normally useable on this host and may be IPv4, IPv6, mapped IPv4, or a mixture. The above may be or'd with one or more of the following: onlyUDP - only addrs valid for UDP connections else TCP order46 - List IPv4 addresses (mapped or native) first. order64 - List IPv6 addresses first. |
pNum | >= 0 uses the value as the port number regardless of what is in hSpec, should it be supplied. However, if is present, it must be a valid port number. < 0 uses the positive value as the port number if the port number has not been specified in hSpec. **** When set to PortInSpec(the default, see below) the port number/name must be specified in hSpec. If it is not, an error is returned. **** When set to NoPortRaw then hSpec does not contain a port number and is a host name, IPv4 address, or an IPv6 address without surrounding brackets. |
Enumerator | |
---|---|
allIPMap | |
allIPv64 | |
allV4Map | |
onlyIPv6 | |
onlyIPv4 | |
prefIPv6 | |
prefAuto | |
order46 | |
order64 | |
onlyUDP |
Definition at line 125 of file XrdNetUtils.hh.
enum XrdNetUtils::NetProt |
Get the supported network protocols.
netqry | An NetType enum specifying the protocol to inspect. |
eText | When not nil, is where to place error message text. |
Enumerator | |
---|---|
hasNone | Unable to determine available protocols. |
hasIPv4 | |
hasIPv6 | |
hasIP64 | |
hasPub4 | |
hasPub6 |
Definition at line 333 of file XrdNetUtils.hh.
enum XrdNetUtils::NetType |
Enumerator | |
---|---|
qryINET | Only consider internet protocols via DNS. |
qryINIF | Only consider internet protocols via ifconfig. |
Definition at line 341 of file XrdNetUtils.hh.
|
inline |
|
inline |
|
static |
Definition at line 946 of file XrdNetUtils.cc.
References close.
Referenced by XrdTpc::PMarkManager::connect().
|
static |
Decode an "encoded" ipv6/4 address and place it "sockaddr" type structure.
sadr | address of the union that will hold the results. |
buff | address of buffer that holds the encoding. |
blen | length of the string (it need not be null terminated). |
Definition at line 70 of file XrdNetUtils.cc.
References XrdNetSockAddr::v4, and XrdNetSockAddr::v6.
Referenced by XrdOucReqID::isMine().
|
static |
Encode the address and return it in a supplied buffer.
sadr | address of the union that holds the IPV4/6 address. |
buff | address of buffer to hold the null terminated encoding. |
blen | length of the buffer. It6 should be at least 40 bytes. |
port | optional port value to use as opposed to the one present in sockaddr sadr. The port must be in host order. |
Definition at line 120 of file XrdNetUtils.cc.
References XrdNetSockAddr::Addr, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.
Referenced by XrdOucReqID::XrdOucReqID(), and XrdOssPath::InitPrefix().
|
static |
Definition at line 239 of file XrdNetUtils.cc.
References XrdNetSpace::hpSpec::aNum4, XrdNetSpace::hpSpec::aNum6, and opts.
Referenced by XrdNetRegistry::GetAddrs(), XrdCl::Utils::GetHostAddresses(), XrdNetAddr::Register(), and XrdNetIF::SetIF().
|
static |
Version 2: Return multiple addresses associated with a host or IP address.
hSpec | Reference to address specification (see version 1). |
aVec | Reference to the vector to contain addresses. |
ordn | Pointer to where the partition ordinal is to be stored. |
opts | Options on what to return (see version 1). |
pNum | Port number argument (see version 1). |
Definition at line 276 of file XrdNetUtils.cc.
References XrdNetSpace::hpSpec::aNum4, XrdNetSpace::hpSpec::aNum6, XrdNetRegistry::GetAddrs(), opts, and XrdNetRegistry::pfx.
|
static |
Version 3: Return multiple addresses associated with a list of host or IP addresses.
hSVec | vector of address specification (see version 1). Note that this version requires hSVec entries to have a port number. |
aVec | Reference to the vector to contain addresses. |
ordn | Pointer to where the partition ordinal is to be stored. |
opts | Options on what to return (see version 1). |
rotNum | The rotation factor to order addresses in the result. |
force | When true resolution errors are ignored. |
Definition at line 319 of file XrdNetUtils.cc.
References XrdNetSpace::hpSpec::aNum4, XrdNetSpace::hpSpec::aNum6, and opts.
|
static |
Obtain connection information from a socket.
fd | The file descriptor of the socket whose address is to be converted. The sign of the fd indicates which address: fd > 0 the peer address is used (i.e. getpeername) fd < 0 the local address is used (i.e. getsockname) |
theAddr | pointer to a buffer of theAlen bytes where the text version of the IP address is to be returned. The text uses the actual native address format. If theAddr is nil or theAlen is not positive, only the port and address type are returned. |
theALen | length of the theAddr buffer. |
theType | either the character 4 (IPv4) or 6 (IPv6) is returned. corrresponding to the address family. Note that should be AF_INET6 but the address is mapped, '4' is returned. |
Definition at line 498 of file XrdNetUtils.cc.
References XrdNetSockAddr::Addr, XrdNetAddrInfo::fmtAddr, XrdNetAddrInfo::Format(), XrdNetAddrInfo::IPv4, XrdNetAddrInfo::isIPType(), XrdNetAddrInfo::isMapped(), XrdNetAddrInfo::noPortRaw, XrdNetAddrInfo::prefipv4, XrdNetAddr::Set(), SOCKLEN_t, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.
Referenced by XrdNetPMarkFF::Start().
|
static |
Obtain an easily digestable list of hosts. This is the list of up to eight unique aliases (i.e. with different addresses) assigned to a base hostname.
hSpec | the host specification suitable for XrdNetAddr.Set(). |
hPort | When >= 0 specified the port to use regardless of hSpec. When < 0 the port must be present in hSpec. |
hWant | Maximum number of list entries wanted. If hWant is greater that eight it is set eigth. |
sPort | If not nil, the *sPort will be set to hPort if and only if the IP address in one of the entries matches the host address. Otherwise, the value is unchanged. |
eText | When not nil, is where to place error message text. |
Definition at line 541 of file XrdNetUtils.cc.
References XrdNetAddrInfo::Name(), XrdNetAddr::Port(), and XrdNetAddr::PortInSpec.
Referenced by XrdCmsUtils::ParseMan().
|
static |
Definition at line 584 of file XrdNetUtils.cc.
References XrdNetAddrInfo::fmtAdv6, XrdNetAddrInfo::Format(), XrdNetAddrInfo::noPort, XrdNetAddrInfo::old6Map4, opts, and XrdNetAddr::Set().
Referenced by XrdSecProtocolsss::getCredentials(), XrdCl::Socket::GetPeerName(), and XrdCl::Socket::GetSockName().
|
static |
Convert an IP socket address/port (V4 or V6) into the standard V6 RFC ASCII representation: "[address]:port".
fd | The file descriptor of the socket whose address is to be converted. The sign of the fd indicates which address: fd > 0 the peer address is used (i.e. getpeername) fd < 0 the local address is used (i.e. getsockname) |
bP | points to a buffer large enough to hold the result. A buffer 64 characters long will always be big enough. |
bL | the actual size of the buffer. |
opts | Formating options: noPort - does not suffix the port number with ":port". oldFmt - use the deprecated format for an IPV4 mapped address: [::d.d.d.d] vs [::ffff:d.d.d.d]. |
Definition at line 602 of file XrdNetUtils.cc.
References XrdNetSockAddr::Addr, opts, and SOCKLEN_t.
|
static |
Determine if a hostname matches a pattern.
hName | the name of the host. |
pattern | the pattern to match against. The pattern may contain one If the pattern contains a single asterisk, then the prefix of hName is compared with the characters before the '*' and the suffix of hName is compared with the character after. If the pattern ends with a plus, the all then pattern is taken as a hostname (less '+') and expanded to all possible hostnames and each one is compared with hName. If the pattern contains both, the asterisk rule is used first. If it contains neither then strict equality is used. |
Definition at line 623 of file XrdNetUtils.cc.
Referenced by XrdOucUtils::doIf().
|
static |
Get the fully qualified name of the current host.
eName | The name to be returned when the host name or its true address could not be returned. The pointer may be nil. |
eText | When supplied will hold 0 if no errors occurred or error message text, in persistent storage, describing why the error-triggered alternate name was returned. If it contains neither then strict equality is used. |
Definition at line 667 of file XrdNetUtils.cc.
References XrdNetIdentity::FQN().
Referenced by XrdNetPMarkCfg::Config(), XrdSecProtocolsss::Load_Client(), and XrdSecProtocolkrb5Init().
|
static |
Definition at line 681 of file XrdNetUtils.cc.
References eMsg, XrdNetIF::GetIF(), XrdNetIF::haveIPv4, XrdNetIF::haveIPv6, XrdNetIF::havePub4, XrdNetIF::havePub6, XrdNetAddrInfo::IPv4, XrdNetAddrInfo::IPv6, and XrdOucUtils::toLower().
Referenced by XrdCl::Stream::Stream().
|
static |
Parse an IP or host name specification.
hSpec | the name or IP address of the host. As one of the following "[<ipv6>]:<port>", "<ipv4>:<port>", or "<name>:<port>". |
hName | place where the starting address of the host is placed. |
hNend | place where the ending address+1 is placed. This will point to either ']', ':', or a null byte. |
hPort | place where the starting address of the port is placed. If no ":port" was found, this will contain *hNend. |
hPend | place where the ending address+1 is placed. If no port If no ":port" was found, this will contain *hNend. |
Definition at line 745 of file XrdNetUtils.cc.
Referenced by XrdOucUtils::isFWD(), XrdNetAddr::Set(), and XrdFfsMisc_get_list_of_data_servers().
|
static |
Obtain the numeric port associated with a file descriptor.
fd | the file descriptor number. |
eText | when not null, the reason for a failure is returned. |
Definition at line 780 of file XrdNetUtils.cc.
References XrdNetSockAddr::Addr, SOCKLEN_t, and XrdNetSockAddr::v6.
Referenced by XrdNet::Bind().
|
static |
Obtain the protocol identifier.
pName | the name of the protocol (e.g. "tcp"). |
Definition at line 803 of file XrdNetUtils.cc.
References IPPROTO_TCP, XrdSysMutex::Lock(), and XrdSysMutex::UnLock().
Referenced by XrdNetSocket::setOpts().
|
static |
Obtain the numeric port corresponding to a symbolic name.
sName | the name of the service or a numeric port number. |
isUDP | if true, returns the UDP service port o/w the TCP service |
eText | when not null, the reason for a failure is returned. |
Definition at line 839 of file XrdNetUtils.cc.
References SIN_PORT.
Referenced by XrdOuca2x::a2p(), XrdCmsUtils::ParseMan(), and XrdNetAddr::Set().
|
static |
Set the family and hints to be used in GetAddrs() with prefAuto. This is used within this class and by XrdNetAddr when the IP mode changes. It is meant for internal use only.
aOpts | Is one of the following from the AddrOpts enum: allIPMap - Use IPv6 and mapped IPv4 addrs (default) onlyIPv4 - Use only IPv4 addresses. prefAuto - Determine proper options based on configuration. |
Definition at line 880 of file XrdNetUtils.cc.
References XrdNetIF::GetIF(), XrdNetIF::haveIPv4, and XrdNetIF::haveIPv6.
Referenced by XrdNetAddr::SetIPV4(), and XrdNetAddr::SetIPV6().
|
static |
Check if whether or not a host name represents more than one unique host.
hSpec | the host specification suitable for XrdNetAddr.Set(). |
eText | When not nil, is where to place error message text. |
Definition at line 921 of file XrdNetUtils.cc.
References XrdOucTList::next.
Referenced by XrdSsiClientProvider::GetService().
|
static |
Convert an IP address/port (V4 or V6) into the standard V6 RFC ASCII representation: "[address]:port".
sAddr | Address to convert. This is either sockaddr_in or sockaddr_in6 cast to struct sockaddr. |
bP | points to a buffer large enough to hold the result. A buffer 64 characters long will always be big enough. |
bL | the actual size of the buffer. |
opts | Formating options: noPort - does not suffix the port number with ":port". oldFmt - use the deprecated format for an IPV4 mapped address: [::d.d.d.d] vs [::ffff:d.d.d.d]. |
Definition at line 255 of file XrdNetUtils.hh.
|
static |
Definition at line 132 of file XrdNetUtils.hh.
Referenced by XrdNetAddr::Register().
|
static |
Definition at line 256 of file XrdNetUtils.hh.
Referenced by XrdSecProtocolsss::getCredentials().
|
static |
Definition at line 131 of file XrdNetUtils.hh.