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 IPV4Set() {return useIPV4;} 00053 00054 //------------------------------------------------------------------------------ 00062 //------------------------------------------------------------------------------ 00063 00064 int Port(int pNum=-1); 00065 00066 //------------------------------------------------------------------------------ 00088 //------------------------------------------------------------------------------ 00089 00090 static const int PortInSpec = (int)0x80000000; 00091 00092 const char *Set(const char *hSpec, int pNum=PortInSpec); 00093 00094 //------------------------------------------------------------------------------ 00122 //------------------------------------------------------------------------------ 00123 00124 const char *Set(const char *hSpec, int &numIP, int maxIP, 00125 int pNum=PortInSpec, bool forUDP=false); 00126 00127 //------------------------------------------------------------------------------ 00137 //------------------------------------------------------------------------------ 00138 00139 const char *Set(const struct sockaddr *sockP, int sockFD=-1); 00140 00141 //------------------------------------------------------------------------------ 00152 //------------------------------------------------------------------------------ 00153 00154 const char *Set(int sockFD, bool peer=true); 00155 00156 //------------------------------------------------------------------------------ 00166 //------------------------------------------------------------------------------ 00167 00168 const char *Set(struct addrinfo *rP, int port, bool mapit=false); 00169 00170 //------------------------------------------------------------------------------ 00173 //------------------------------------------------------------------------------ 00174 00175 static void SetCache(int keeptime); 00176 00177 //------------------------------------------------------------------------------ 00182 //------------------------------------------------------------------------------ 00183 00184 static void SetIPV4(); 00185 00186 //------------------------------------------------------------------------------ 00192 //------------------------------------------------------------------------------ 00193 00194 static void SetIPV6(); 00195 00196 //------------------------------------------------------------------------------ 00201 //------------------------------------------------------------------------------ 00202 00203 void SetLocation(XrdNetAddrInfo::LocInfo &loc) {addrLoc = loc;} 00204 00205 //------------------------------------------------------------------------------ 00207 //------------------------------------------------------------------------------ 00208 00209 //------------------------------------------------------------------------------ 00216 //------------------------------------------------------------------------------ 00217 00218 XrdNetAddr() : XrdNetAddrInfo() {} 00219 00220 XrdNetAddr(const XrdNetAddr *addr) : XrdNetAddrInfo(addr) {} 00221 00222 XrdNetAddr(const sockaddr *addr) : XrdNetAddrInfo() 00223 {Set(addr);} 00224 00225 XrdNetAddr(const sockaddr_in *addr) : XrdNetAddrInfo() 00226 {Set((sockaddr *)addr);} 00227 00228 XrdNetAddr(const sockaddr_in6 *addr) : XrdNetAddrInfo() 00229 {Set((sockaddr *)addr);} 00230 00231 XrdNetAddr(int port); 00232 00233 //------------------------------------------------------------------------------ 00235 //------------------------------------------------------------------------------ 00236 00237 ~XrdNetAddr() {} 00238 private: 00239 static struct addrinfo *Hints(int htype, int stype); 00240 bool Map64(); 00241 00242 static struct addrinfo *hostHints; 00243 static struct addrinfo *huntHintsTCP; 00244 static struct addrinfo *huntHintsUDP; 00245 static bool useIPV4; 00246 }; 00247 #endif