00001 #ifndef __XRDNETADDR_HH__ 00002 #define __XRDNETADDR_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d N e t A d d r . 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 "XrdNet/XrdNetAddrInfo.hh" 00034 00035 //------------------------------------------------------------------------------ 00037 //------------------------------------------------------------------------------ 00038 00039 struct addrinfo; 00040 00041 class XrdNetAddr : public XrdNetAddrInfo 00042 { 00043 public: 00044 00045 //------------------------------------------------------------------------------ 00050 //------------------------------------------------------------------------------ 00051 00052 static bool DynDNS() {return dynDNS;} 00053 00054 //------------------------------------------------------------------------------ 00059 //------------------------------------------------------------------------------ 00060 00061 static bool IPV4Set() {return useIPV4;} 00062 00063 //------------------------------------------------------------------------------ 00071 //------------------------------------------------------------------------------ 00072 00073 int Port(int pNum=-1); 00074 00075 //------------------------------------------------------------------------------ 00084 //------------------------------------------------------------------------------ 00085 00086 bool Register(const char *hName); 00087 00088 //------------------------------------------------------------------------------ 00110 //------------------------------------------------------------------------------ 00111 00112 static const int PortInSpec = (int)0x80000000; 00113 00114 const char *Set(const char *hSpec, int pNum=PortInSpec); 00115 00116 //------------------------------------------------------------------------------ 00144 //------------------------------------------------------------------------------ 00145 00146 const char *Set(const char *hSpec, int &numIP, int maxIP, 00147 int pNum=PortInSpec, bool forUDP=false); 00148 00149 //------------------------------------------------------------------------------ 00159 //------------------------------------------------------------------------------ 00160 00161 const char *Set(const struct sockaddr *sockP, int sockFD=-1); 00162 00163 //------------------------------------------------------------------------------ 00174 //------------------------------------------------------------------------------ 00175 00176 const char *Set(int sockFD, bool peer=true); 00177 00178 //------------------------------------------------------------------------------ 00188 //------------------------------------------------------------------------------ 00189 00190 const char *Set(struct addrinfo *rP, int port, bool mapit=false); 00191 00192 //------------------------------------------------------------------------------ 00195 //------------------------------------------------------------------------------ 00196 00197 static void SetCache(int keeptime); 00198 00199 //------------------------------------------------------------------------------ 00203 //------------------------------------------------------------------------------ 00204 00205 void SetDialect(const char *dP) {protName = dP;} 00206 00207 //------------------------------------------------------------------------------ 00212 //------------------------------------------------------------------------------ 00213 00214 static void SetDynDNS(bool onoff); 00215 00216 //------------------------------------------------------------------------------ 00221 //------------------------------------------------------------------------------ 00222 00223 static void SetIPV4(); 00224 00225 //------------------------------------------------------------------------------ 00231 //------------------------------------------------------------------------------ 00232 00233 static void SetIPV6(); 00234 00235 //------------------------------------------------------------------------------ 00240 //------------------------------------------------------------------------------ 00241 00242 void SetLocation(XrdNetAddrInfo::LocInfo &loc); 00243 00244 //------------------------------------------------------------------------------ 00248 //------------------------------------------------------------------------------ 00249 00250 void SetTLS(bool val); 00251 00252 //------------------------------------------------------------------------------ 00254 //------------------------------------------------------------------------------ 00255 00256 //------------------------------------------------------------------------------ 00263 //------------------------------------------------------------------------------ 00264 00265 XrdNetAddr() : XrdNetAddrInfo() {} 00266 00267 XrdNetAddr(const XrdNetAddr *addr) : XrdNetAddrInfo(addr) {} 00268 00269 XrdNetAddr(const sockaddr *addr) : XrdNetAddrInfo() 00270 {Set(addr);} 00271 00272 XrdNetAddr(const sockaddr_in *addr) : XrdNetAddrInfo() 00273 {Set((sockaddr *)addr);} 00274 00275 XrdNetAddr(const sockaddr_in6 *addr) : XrdNetAddrInfo() 00276 {Set((sockaddr *)addr);} 00277 00278 XrdNetAddr(int port); 00279 00280 //------------------------------------------------------------------------------ 00282 //------------------------------------------------------------------------------ 00283 00284 ~XrdNetAddr() {} 00285 private: 00286 static struct addrinfo *Hints(int htype, int stype); 00287 bool Map64(); 00288 00289 static struct addrinfo *hostHints; 00290 static struct addrinfo *huntHintsTCP; 00291 static struct addrinfo *huntHintsUDP; 00292 static bool useIPV4; 00293 static bool dynDNS; 00294 }; 00295 #endif