00001 #ifndef __XRDNETUTILS_HH__ 00002 #define __XRDNETUTILS_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d N e t U t i l s . h h */ 00006 /* */ 00007 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include "XrdOuc/XrdOucEnum.hh" 00034 00035 class XrdOucTList; 00036 class XrdNetAddr; 00037 union XrdNetSockAddr; 00038 00039 class XrdNetUtils 00040 { 00041 public: 00042 00043 //------------------------------------------------------------------------------ 00053 //------------------------------------------------------------------------------ 00054 00055 static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen); 00056 00057 //------------------------------------------------------------------------------ 00069 //------------------------------------------------------------------------------ 00070 00071 static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1); 00072 00073 00074 //------------------------------------------------------------------------------ 00119 //------------------------------------------------------------------------------ 00120 00121 enum AddrOpts {allIPMap= 0, allIPv64= 1, allV4Map= 2, 00122 onlyIPv6= 3, onlyIPv4= 4, prefIPv6= 8, 00123 prefAuto= 16, onlyUDP =128 00124 }; 00125 00126 static const int PortInSpec = (int)0x80000000; 00127 static const int NoPortRaw = (int)0xC0000000; 00128 00129 static 00130 const char *GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, 00131 AddrOpts opts=allIPMap, int pNum=PortInSpec); 00132 00133 //------------------------------------------------------------------------------ 00153 //------------------------------------------------------------------------------ 00154 00155 static 00156 XrdOucTList *Hosts(const char *hSpec, int hPort=-1, int hWant=8, int *sPort=0, 00157 const char **eText=0); 00158 00159 //------------------------------------------------------------------------------ 00177 //------------------------------------------------------------------------------ 00178 00179 static const int noPort = 1; 00180 static const int oldFmt = 2; 00181 00182 static int IPFormat(const struct sockaddr *sAddr, char *bP, int bL, int opts=0); 00183 00184 //------------------------------------------------------------------------------ 00204 //------------------------------------------------------------------------------ 00205 00206 static int IPFormat(int fd, char *bP, int bL, int opts=0); 00207 00208 //------------------------------------------------------------------------------ 00224 //------------------------------------------------------------------------------ 00225 00226 static bool Match(const char *hName, const char *pattern); 00227 00228 //------------------------------------------------------------------------------ 00241 //------------------------------------------------------------------------------ 00242 00243 static char *MyHostName(const char *eName="*unknown*", const char **eText=0); 00244 00245 //------------------------------------------------------------------------------ 00255 //------------------------------------------------------------------------------ 00256 00257 enum NetProt {hasNone = 0, 00258 hasIPv4 = 1, //<! Has only IPv4 capability 00259 hasIPv6 = 2, //<! Has only IPv6 capability 00260 hasIP64 = 3, //<! Has IPv4 IPv6 capability (dual stack) 00261 hasPub4 = 4, //<! Has IPv4 public address (or'd with above) 00262 hasPub6 = 8 //<! Has IPv6 public address (or'd with above) 00263 }; 00264 00265 enum NetType {qryINET = 0, 00266 qryINIF = 1 00267 }; 00268 00269 static NetProt NetConfig(NetType netquery=qryINET, const char **eText=0); 00270 00271 //------------------------------------------------------------------------------ 00287 //------------------------------------------------------------------------------ 00288 00289 static bool Parse(const char *hSpec, const char **hName, const char **hNend, 00290 const char **hPort, const char **hPend); 00291 00292 //------------------------------------------------------------------------------ 00300 //------------------------------------------------------------------------------ 00301 00302 static int Port(int fd, const char **eText=0); 00303 00304 //------------------------------------------------------------------------------ 00311 //------------------------------------------------------------------------------ 00312 00313 static int ProtoID(const char *pName); 00314 00315 //------------------------------------------------------------------------------ 00324 //------------------------------------------------------------------------------ 00325 00326 static int ServPort(const char *sName, bool isUDP=false, const char **eText=0); 00327 00328 //------------------------------------------------------------------------------ 00339 //------------------------------------------------------------------------------ 00340 00341 static int SetAuto(AddrOpts aOpts=allIPMap); 00342 00343 //------------------------------------------------------------------------------ 00345 //------------------------------------------------------------------------------ 00346 00347 XrdNetUtils() {} 00348 00349 //------------------------------------------------------------------------------ 00351 //------------------------------------------------------------------------------ 00352 00353 ~XrdNetUtils() {} 00354 private: 00355 00356 static int setET(const char **errtxt, int rc); 00357 static int autoFamily; 00358 static int autoHints; 00359 }; 00360 00361 XRDOUC_ENUM_OPERATORS(XrdNetUtils::AddrOpts) 00362 00363 #endif