VR-Link API Documentation for HLA Evolved
vlNetSocket.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992, 1997 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: vlNetSocket.h,v $ $Revision: 1.3.6.1 $ $State: Exp $
7 *********************************************************************/
8 #ifndef vlNetSocket_H_
9 #define vlNetSocket_H_
10 
15 
16 #include <vlutil/vlMachineTypes.h>
17 #include <vlutil/vlNetTypes.h>
18 #include "vlSocket.h"
19 #include <vlutil/vlUtil.h>
20 
21 struct sockaddr_in;
22 struct ifreq;
23 
24 #if defined(__solaris__) || defined(__sgi__)
25 
26 
27 #define DtRead ((DtU8) 0x01)
28 
29 #define DtWrite ((DtU8) 0x02)
30 
31 #define DtReadWrite (DtRead | DtWrite)
32 
33 
34 #define DtBindToDestAddr ((DtU8) 0x08)
35 
36 #define DtQuiet ((DtU8) 0x10)
37 #else
38 #include <vlutil/vlInetSocket.h>
39 #endif
40 
41 #ifdef DtUSE_UTILITIES_NAMESPACE
42 namespace DtUSE_UTILITIES_NAMESPACE
43 {
44 #endif
45 
47 
48 DT_DLL_NETCOMPAT DtIpv4Addr DtInetAddrOfDevice( const char* device );
49 
50 DT_DLL_NETCOMPAT DtIpv4Addr DtNetMaskOfDevice( const char* device );
51 
53 
55 
60 {
64 };
65 
73 {
74 public:
75 
81  DtNetSocket(int port = DtDEFAULT_PORT, DtU8 flags = DtReadWrite, DtIpv4Addr devAddr = 0);
82 
88  DtNetSocket(int port, DtIpv4Addr destAddr, DtU8 flags, DtIpv4Addr devAddr = 0);
89 
92  DtNetSocket(char* dummy, int sockfd, DtU8 flags = DtReadWrite);
93 
95  virtual ~DtNetSocket();
96 
100  virtual int sendTo(caddr_t packet, size_t size, DtIpv4Addr addr);
101 
104  virtual int DtRecv(caddr_t* buffptr, int* status = NULL);
105 
108  virtual int DtRecv(caddr_t buff, size_t);
109 
111  virtual DtIpv4Addr lastSourceInetAddr();
112 
114  virtual void DtBecomeNonBlocking(void);
115 
116 
117 
120 
123  virtual void setBundling( int maxBundleSize, bool enableUnbundling,
124  int minPacketSize, int sizeOffset, int sizeLength, bool testDisHeader );
125 
127  virtual void setBundling( int maxBundleSize);
128 
133  virtual void setUnbundling(int onOff);
134  virtual int isUnbundling();
136 
141  virtual int minPacketSize();
142  virtual void setMinPacketSize( int size );
144 
149  virtual int sizeOffset();
150  virtual void setSizeOffset( int offset );
152 
157  virtual int sizeLength();
158  virtual void setSizeLength( int length );
160 
167  virtual bool testDisHeader();
168  virtual void enableDisHeaderTest( bool shouldTest );
170 
174  virtual int readFd();
175  virtual int writeFd();
176 
179  virtual bool isOk() const;
180 
184  virtual int listenToMulticastGroup(
185  DtIpv4Addr multicastAddr, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR );
186  virtual int dropMulticastGroup(
187  DtIpv4Addr multicastAddr, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR );
189 
191  virtual int setMcastTtl(int ttl);
192 
195  virtual void setMcastDevice(DtIpv4Addr devAddr);
196  virtual DtIpv4Addr mcastDevice() const;
198 
199  virtual void setFilterPort(const int& port);
200 
201  virtual void setSendPort(const int& port);
202 
203 public:
204 
206  static int isMulticastAddr(DtIpv4Addr addr);
207 
209  static int enableBroadcast(int sockfd);
210 
212  static void makeNonBlocking(int sockfd);
213 
215  static int makeReusable(int sockfd);
216 
219  static void setRetryOnSend(unsigned int numRetries, double waitPeriod);
220 
222  static DtIpv4Addr inetBroadcastOfDevice(const char *device = NULL);
223  static DtIpv4Addr inetAddrOfDevice(const char *device = NULL);
224  static DtIpv4Addr netMaskOfDevice(const char *device = NULL);
225  static DtIpv4Addr firstHostInetAddr();
226 
228  static void setInetAddr(sockaddr_in &s, u_long addr, int port);
229 
230 #ifdef _WIN32
231 
232  static DtIpv4Addr envNetMask();
233 
236  static void netMaskFromReg(char* tszNetMask);
237 
239  static DtIpv4Addr systemNetMask();
240 #endif
241 
242 public:
243 
245 
246 protected:
247 
249  void init(int port, DtIpv4Addr dest_addr, DtU8 flags, DtIpv4Addr devAddr = 0);
250 
252  virtual int dataLeftInCurrentBundle();
253 
255  virtual int retrySendTo( caddr_t packet, size_t size, sockaddr_in& dest );
256 
261  virtual int recvWithStatus(caddr_t* buffptr, int* status);
262 
266  virtual int recvFromNet(caddr_t* buffptr);
267 
272  virtual int recvWithUnbundling(caddr_t* buffptr);
273 
275  int initSocket();
276 
279  int initWrite(DtIpv4Addr dest);
280 
282  int initRead(DtIpv4Addr dest);
283 
285  virtual int privateListenToMulticastGroup(DtIpv4Addr multicastAddr,
286  int on_init = 0, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR );
287 
292  virtual void findNextPacket();
293 
298  virtual unsigned int getNextPacketSize();
299 
301  virtual unsigned int currentHeaderMatchesFirstInBundle();
302 
303 protected:
304 
307  static ifreq* findIfr(
308  const char* device, int sock, ifconf* ifc);
309 
311  static DtIpv4Addr netMaskOfIfr(ifreq *ifr, int sock);
312  static DtIpv4Addr inetAddrOfIfr(ifreq *ifr, int sock);
313  static DtIpv4Addr inetBroadcastOfIfr(ifreq *ifr, int sock);
314  static bool capableOfIpBroadcast(ifreq* ifr, int sock);
315 
316 
317 protected:
318 
322  unsigned int mySourcePort;
323  char* myPktBuff;
331 
332  int sizeLeft;
333 
334 
340 
345 
346  bool myOkFlag;
347  sockaddr_in* destSockAddr;
348  sockaddr_in* sourceSockAddr;
350 
351 protected:
352 
353  static unsigned int theMaxSendRetries;
354  static double theSendRetryPeriod;
355 
356 protected:
357 
359  DtNetSocket(const DtNetSocket &);
360 
362  DtNetSocket &operator=(const DtNetSocket &);
363 
364 };
365 
366 inline void DtNetSocket::setBundling( int maxBundleSize)
367 {
368  DtSocket::setBundling(maxBundleSize);
369 }
370 
371 
372 #ifdef DtUSE_UTILITIES_NAMESPACE
373 }
374 #endif
375 
376 #endif
377 

Document ID: Generated on Wed Oct 23 22:25:48 EDT 2013 from SVN revision 132765
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)