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 //------------------------------------------------------------------------------ 00097 //------------------------------------------------------------------------------ 00098 00099 static const int PortInSpec = (int)0x80000000; 00100 00101 const char *Set(const char *hSpec, int pNum=PortInSpec); 00102 00103 //------------------------------------------------------------------------------ 00131 //------------------------------------------------------------------------------ 00132 00133 const char *Set(const char *hSpec, int &numIP, int maxIP, 00134 int pNum=PortInSpec, bool forUDP=false); 00135 00136 //------------------------------------------------------------------------------ 00146 //------------------------------------------------------------------------------ 00147 00148 const char *Set(const struct sockaddr *sockP, int sockFD=-1); 00149 00150 //------------------------------------------------------------------------------ 00161 //------------------------------------------------------------------------------ 00162 00163 const char *Set(int sockFD, bool peer=true); 00164 00165 //------------------------------------------------------------------------------ 00175 //------------------------------------------------------------------------------ 00176 00177 const char *Set(struct addrinfo *rP, int port, bool mapit=false); 00178 00179 //------------------------------------------------------------------------------ 00182 //------------------------------------------------------------------------------ 00183 00184 static void SetCache(int keeptime); 00185 00186 //------------------------------------------------------------------------------ 00191 //------------------------------------------------------------------------------ 00192 00193 static void SetDynDNS(bool onoff); 00194 00195 //------------------------------------------------------------------------------ 00200 //------------------------------------------------------------------------------ 00201 00202 static void SetIPV4(); 00203 00204 //------------------------------------------------------------------------------ 00210 //------------------------------------------------------------------------------ 00211 00212 static void SetIPV6(); 00213 00214 //------------------------------------------------------------------------------ 00219 //------------------------------------------------------------------------------ 00220 00221 void SetLocation(XrdNetAddrInfo::LocInfo &loc) {addrLoc = loc;} 00222 00223 //------------------------------------------------------------------------------ 00225 //------------------------------------------------------------------------------ 00226 00227 //------------------------------------------------------------------------------ 00234 //------------------------------------------------------------------------------ 00235 00236 XrdNetAddr() : XrdNetAddrInfo() {} 00237 00238 XrdNetAddr(const XrdNetAddr *addr) : XrdNetAddrInfo(addr) {} 00239 00240 XrdNetAddr(const sockaddr *addr) : XrdNetAddrInfo() 00241 {Set(addr);} 00242 00243 XrdNetAddr(const sockaddr_in *addr) : XrdNetAddrInfo() 00244 {Set((sockaddr *)addr);} 00245 00246 XrdNetAddr(const sockaddr_in6 *addr) : XrdNetAddrInfo() 00247 {Set((sockaddr *)addr);} 00248 00249 XrdNetAddr(int port); 00250 00251 //------------------------------------------------------------------------------ 00253 //------------------------------------------------------------------------------ 00254 00255 ~XrdNetAddr() {} 00256 private: 00257 static struct addrinfo *Hints(int htype, int stype); 00258 bool Map64(); 00259 00260 static struct addrinfo *hostHints; 00261 static struct addrinfo *huntHintsTCP; 00262 static struct addrinfo *huntHintsUDP; 00263 static bool useIPV4; 00264 static bool dynDNS; 00265 }; 00266 #endif