![]() |
VR-Link API Documentation for HLA Evolved
|
00001 /********************************************************************* 00002 ** Copyright (c) 1992, 1997 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: vlNetSocket.h,v $ $Revision: 1.3.6.1 $ $State: Exp $ 00007 *********************************************************************/ 00008 #ifndef vlNetSocket_H_ 00009 #define vlNetSocket_H_ 00010 00015 00016 #include <vlutil/vlMachineTypes.h> 00017 #include <vlutil/vlNetTypes.h> 00018 #include "vlSocket.h" 00019 #include <vlutil/vlUtil.h> 00020 00021 struct sockaddr_in; 00022 struct ifreq; 00023 00024 #if defined(__solaris__) || defined(__sgi__) 00025 00026 00027 #define DtRead ((DtU8) 0x01) 00028 00029 #define DtWrite ((DtU8) 0x02) 00030 00031 #define DtReadWrite (DtRead | DtWrite) 00032 00033 00034 #define DtBindToDestAddr ((DtU8) 0x08) 00035 00036 #define DtQuiet ((DtU8) 0x10) 00037 #else 00038 #include <vlutil/vlInetSocket.h> 00039 #endif 00040 00041 #ifdef DtUSE_UTILITIES_NAMESPACE 00042 namespace DtUSE_UTILITIES_NAMESPACE 00043 { 00044 #endif 00045 00046 DT_DLL_NETCOMPAT DtIpv4Addr DtInetBroadcastOfDevice( const char* device ); 00047 00048 DT_DLL_NETCOMPAT DtIpv4Addr DtInetAddrOfDevice( const char* device ); 00049 00050 DT_DLL_NETCOMPAT DtIpv4Addr DtNetMaskOfDevice( const char* device ); 00051 00052 DT_DLL_NETCOMPAT DtIpv4Addr DtFirstHostInetAddr(); 00053 00054 DT_DLL_NETCOMPAT int DtIsMulticastAddr( DtIpv4Addr addr ); 00055 00059 enum DtInitErrorAction 00060 { 00061 DtInitErrorFatal, 00062 DtInitErrorWarn, 00063 DtInitErrorIgnore 00064 }; 00065 00072 class DT_DLL_NETCOMPAT DtNetSocket : public DtSocket 00073 { 00074 public: 00075 00081 DtNetSocket(int port = DtDEFAULT_PORT, DtU8 flags = DtReadWrite, DtIpv4Addr devAddr = 0); 00082 00088 DtNetSocket(int port, DtIpv4Addr destAddr, DtU8 flags, DtIpv4Addr devAddr = 0); 00089 00092 DtNetSocket(char* dummy, int sockfd, DtU8 flags = DtReadWrite); 00093 00095 virtual ~DtNetSocket(); 00096 00100 virtual int sendTo(caddr_t packet, size_t size, DtIpv4Addr addr); 00101 00104 virtual int DtRecv(caddr_t* buffptr, int* status = NULL); 00105 00108 virtual int DtRecv(caddr_t buff, size_t); 00109 00111 virtual DtIpv4Addr lastSourceInetAddr(); 00112 00114 virtual void DtBecomeNonBlocking(void); 00115 00116 00117 00120 00123 virtual void setBundling( int maxBundleSize, bool enableUnbundling, 00124 int minPacketSize, int sizeOffset, int sizeLength, bool testDisHeader ); 00125 00127 virtual void setBundling( int maxBundleSize); 00128 00133 virtual void setUnbundling(int onOff); 00134 virtual int isUnbundling(); 00136 00141 virtual int minPacketSize(); 00142 virtual void setMinPacketSize( int size ); 00144 00149 virtual int sizeOffset(); 00150 virtual void setSizeOffset( int offset ); 00152 00157 virtual int sizeLength(); 00158 virtual void setSizeLength( int length ); 00160 00167 virtual bool testDisHeader(); 00168 virtual void enableDisHeaderTest( bool shouldTest ); 00170 00174 virtual int readFd(); 00175 virtual int writeFd(); 00176 00179 virtual bool isOk() const; 00180 00184 virtual int listenToMulticastGroup( 00185 DtIpv4Addr multicastAddr, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR ); 00186 virtual int dropMulticastGroup( 00187 DtIpv4Addr multicastAddr, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR ); 00189 00191 virtual int setMcastTtl(int ttl); 00192 00195 virtual void setMcastDevice(DtIpv4Addr devAddr); 00196 virtual DtIpv4Addr mcastDevice() const; 00198 00199 virtual void setFilterPort(const int& port); 00200 00201 virtual void setSendPort(const int& port); 00202 00203 public: 00204 00206 static int isMulticastAddr(DtIpv4Addr addr); 00207 00209 static int enableBroadcast(int sockfd); 00210 00212 static void makeNonBlocking(int sockfd); 00213 00215 static int makeReusable(int sockfd); 00216 00219 static void setRetryOnSend(unsigned int numRetries, double waitPeriod); 00220 00222 static DtIpv4Addr inetBroadcastOfDevice(const char *device = NULL); 00223 static DtIpv4Addr inetAddrOfDevice(const char *device = NULL); 00224 static DtIpv4Addr netMaskOfDevice(const char *device = NULL); 00225 static DtIpv4Addr firstHostInetAddr(); 00226 00228 static void setInetAddr(sockaddr_in &s, u_long addr, int port); 00229 00230 #ifdef _WIN32 00231 00232 static DtIpv4Addr envNetMask(); 00233 00236 static void netMaskFromReg(char* tszNetMask); 00237 00239 static DtIpv4Addr systemNetMask(); 00240 #endif 00241 00242 public: 00243 00244 static DtInitErrorAction initErrorAction; 00245 00246 protected: 00247 00249 void init(int port, DtIpv4Addr dest_addr, DtU8 flags, DtIpv4Addr devAddr = 0); 00250 00252 virtual int dataLeftInCurrentBundle(); 00253 00255 virtual int retrySendTo( caddr_t packet, size_t size, sockaddr_in& dest ); 00256 00261 virtual int recvWithStatus(caddr_t* buffptr, int* status); 00262 00266 virtual int recvFromNet(caddr_t* buffptr); 00267 00272 virtual int recvWithUnbundling(caddr_t* buffptr); 00273 00275 int initSocket(); 00276 00279 int initWrite(DtIpv4Addr dest); 00280 00282 int initRead(DtIpv4Addr dest); 00283 00285 virtual int privateListenToMulticastGroup(DtIpv4Addr multicastAddr, 00286 int on_init = 0, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR ); 00287 00292 virtual void findNextPacket(); 00293 00298 virtual unsigned int getNextPacketSize(); 00299 00301 virtual unsigned int currentHeaderMatchesFirstInBundle(); 00302 00303 protected: 00304 00307 static ifreq* findIfr( 00308 const char* device, int sock, ifconf* ifc); 00309 00311 static DtIpv4Addr netMaskOfIfr(ifreq *ifr, int sock); 00312 static DtIpv4Addr inetAddrOfIfr(ifreq *ifr, int sock); 00313 static DtIpv4Addr inetBroadcastOfIfr(ifreq *ifr, int sock); 00314 static bool capableOfIpBroadcast(ifreq* ifr, int sock); 00315 00316 00317 protected: 00318 00319 int myUdpPort; 00320 int myFilterPort; 00321 int mySendPort; 00322 unsigned int mySourcePort; 00323 char* myPktBuff; 00324 char* myUnbundleBuff; 00325 void* myNextPacket; 00326 int myUsingExternalSocket; 00327 DtIpv4Addr myExtSockAddr; 00328 DtIpv4Addr myDestInetAddr; 00329 DtIpv4Addr myDevAddr; 00330 int myUnbundling; 00331 00332 int sizeLeft; 00333 00334 00335 int myPktMinSize; 00336 int myPktSizeOffset; 00337 int myPktSizeLength; 00338 int myMaxPacketSize; 00339 bool myTestingDisHeader; 00340 00341 int boundToDestAddr; 00342 int firstInBundle; 00343 int firstExId; 00344 int firstProtocol; 00345 00346 bool myOkFlag; 00347 sockaddr_in* destSockAddr; 00348 sockaddr_in* sourceSockAddr; 00349 DtU8 myFlags; 00350 00351 protected: 00352 00353 static unsigned int theMaxSendRetries; 00354 static double theSendRetryPeriod; 00355 00356 protected: 00357 00359 DtNetSocket(const DtNetSocket &); 00360 00362 DtNetSocket &operator=(const DtNetSocket &); 00363 00364 }; 00365 00366 inline void DtNetSocket::setBundling( int maxBundleSize) 00367 { 00368 DtSocket::setBundling(maxBundleSize); 00369 } 00370 00371 00372 #ifdef DtUSE_UTILITIES_NAMESPACE 00373 } 00374 #endif 00375 00376 #endif 00377