00001 #ifndef __XRDNET_H__ 00002 #define __XRDNET_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d N e t . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <stdlib.h> 00033 #include <string.h> 00034 #ifndef WIN32 00035 #include <strings.h> 00036 #include <unistd.h> 00037 #include <netinet/in.h> 00038 #include <sys/socket.h> 00039 #else 00040 #include <Winsock2.h> 00041 #endif 00042 00043 #include "XrdNet/XrdNetOpts.hh" 00044 00045 class XrdNetAddr; 00046 class XrdNetBufferQ; 00047 class XrdNetPeer; 00048 class XrdNetSecurity; 00049 class XrdSysError; 00050 00051 class XrdNet 00052 { 00053 public: 00054 00055 //------------------------------------------------------------------------------ 00069 //------------------------------------------------------------------------------ 00070 00071 int Accept(XrdNetAddr &myAddr, 00072 int opts=0, 00073 int timeout=-1); 00074 00075 //------------------------------------------------------------------------------ 00093 //------------------------------------------------------------------------------ 00094 00095 int Accept(XrdNetPeer &myPeer, 00096 int opts=0, 00097 int timeout=-1); 00098 00099 //------------------------------------------------------------------------------ 00107 //------------------------------------------------------------------------------ 00108 00109 int Bind( int port, // Port number 00110 const char *contype="tcp" // "tcp" or "udp" 00111 ); 00112 00113 //------------------------------------------------------------------------------ 00122 //------------------------------------------------------------------------------ 00123 00124 int Bind( char *path, // Unix path < |109| 00125 const char *contype="stream" // stream | datagram 00126 ); 00127 00128 //------------------------------------------------------------------------------ 00146 //------------------------------------------------------------------------------ 00147 00148 int Connect(XrdNetAddr &myAddr, 00149 const char *dest, // Destination host or ip address 00150 int port=-1, // Port number 00151 int opts=0, // Options 00152 int timeout=-1 // Second timeout 00153 ); 00154 00155 //------------------------------------------------------------------------------ 00175 //------------------------------------------------------------------------------ 00176 00177 int Connect(XrdNetPeer &myPeer, 00178 const char *dest, // Destination host or ip address 00179 int port=-1, // Port number 00180 int opts=0, // Options 00181 int timeout=-1 // Second timeout 00182 ); 00183 00184 //------------------------------------------------------------------------------ 00189 //------------------------------------------------------------------------------ 00190 00191 int Port() {return Portnum;} 00192 00193 // Relay() creates a UDP socket and optionally decomposes a destination 00194 // of the form host:port. Upon success it fills in the Peer object 00195 // and return true (1). Upon failure, it returns false (0). 00196 // 00197 int Relay(XrdNetPeer &Peer, // Peer object to be initialized 00198 const char *dest, // Optional destination 00199 int opts=0 // Optional options as above 00200 ); 00201 00202 int Relay(const char *dest); // Optional destination 00203 00204 //------------------------------------------------------------------------------ 00210 //------------------------------------------------------------------------------ 00211 00212 virtual void Secure(XrdNetSecurity *secp); 00213 00214 //------------------------------------------------------------------------------ 00221 //------------------------------------------------------------------------------ 00222 00223 void setDefaults(int options, int buffsz=0) 00224 {netOpts = options; Windowsz = buffsz;} 00225 00226 //------------------------------------------------------------------------------ 00231 //------------------------------------------------------------------------------ 00232 00233 void setDomain(const char *dname) 00234 {if (Domain) free(Domain); 00235 Domain = strdup(dname); 00236 Domlen = strlen(dname); 00237 } 00238 00239 //------------------------------------------------------------------------------ 00243 //------------------------------------------------------------------------------ 00244 00245 void Trim(char *hname); 00246 00247 //------------------------------------------------------------------------------ 00249 //------------------------------------------------------------------------------ 00250 00251 void unBind(); 00252 00253 //------------------------------------------------------------------------------ 00259 //------------------------------------------------------------------------------ 00260 00261 int WSize(); 00262 00263 //------------------------------------------------------------------------------ 00271 //------------------------------------------------------------------------------ 00272 00273 XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0); 00274 00275 //------------------------------------------------------------------------------ 00277 //------------------------------------------------------------------------------ 00278 00279 virtual ~XrdNet(); 00280 00281 protected: 00282 00283 XrdSysError *eDest; 00284 XrdNetSecurity *Police; 00285 char *Domain; 00286 int Domlen; 00287 int iofd; 00288 int Portnum; 00289 int PortType; 00290 int Windowsz; 00291 int netOpts; 00292 int BuffSize; 00293 XrdNetBufferQ *BuffQ; 00294 00295 private: 00296 00297 int do_Accept_TCP(XrdNetAddr &myAddr, int opts); 00298 int do_Accept_TCP(XrdNetPeer &myPeer, int opts); 00299 int do_Accept_UDP(XrdNetPeer &myPeer, int opts); 00300 }; 00301 #endif