VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

A DtSocket that implements network sending and receiving function using IP/UDP broadcast, multicast or unicast. More...

+ Inheritance diagram for DtNetSocket:
+ Collaboration diagram for DtNetSocket:

Public Member Functions

 DtNetSocket (int port=DtDEFAULT_PORT, DtU8 flags=DtReadWrite, DtIpv4Addr devAddr=0)
 Constructor. More...
 
 DtNetSocket (int port, DtIpv4Addr destAddr, DtU8 flags, DtIpv4Addr devAddr=0)
 Constructor. More...
 
 DtNetSocket (char *dummy, int sockfd, DtU8 flags=DtReadWrite)
 Allows you to create a DtNetSocket that uses a pre-existing socket. More...
 
virtual ~DtNetSocket ()
 Destructor. More...
 
virtual int sendTo (caddr_t packet, size_t size, DtIpv4Addr addr)
 Virtual function override. More...
 
virtual int DtRecv (caddr_t *buffptr, int *status=NULL)
 DtNetSocket implements DtRecv by calling a system call to recvfrom on its UDP socket. More...
 
virtual int DtRecv (caddr_t buff, size_t)
 DtNetSocket implements DtRecv by calling a system call to recvfrom on its UDP socket. More...
 
virtual DtIpv4Addr lastSourceInetAddr ()
 Return the IP address of the sender of the last packet we've received. More...
 
virtual void DtBecomeNonBlocking (void)
 Make the socket non-blocking. More...
 
virtual int readFd ()
 Return read/write file descriptor of the UDP socket being used for sending and receiving. More...
 
virtual int writeFd ()
 
virtual bool isOk () const
 Returns 1 if the socket's constructor initialization was successful, 0 otherwise. More...
 
virtual int setMcastTtl (int ttl)
 Set the TTL (time to live) value for multicast packets. More...
 
virtual void setFilterPort (const int &port)
 
virtual void setSendPort (const int &port)
 
Bundling Functions.
virtual void setBundling (int maxBundleSize, bool enableUnbundling, int minPacketSize, int sizeOffset, int sizeLength, bool testDisHeader)
 Set all bundling parameters Disables bundling if max. More...
 
virtual void setBundling (int maxBundleSize)
 Call through to DtSocket::setBundling to prevent compiler warnings. More...
 
virtual void setUnbundling (int onOff)
 Pass 0 to setUnbundling to turn unbundling off, 1 to turn it on. More...
 
virtual int isUnbundling ()
 Set all bundling parameters Disables bundling if max. More...
 
Get/Set minimum valid packet size.

If not set manually, the min.

size is based on DtNetPduHeader for backwards compatibility. Currently used only when Unbundling is enabled

virtual int minPacketSize ()
 
virtual void setMinPacketSize (int size)
 
Get/Set the offset to PacketSize within the packet header.

If not set manually, the offset is based on DtNetPduHeader for backwards compatibility.

Currently used only when Unbundling is enabled

virtual int sizeOffset ()
 
virtual void setSizeOffset (int offset)
 
Get/Set the length of the PacketSize field within the packet header.

If not set manually, the length is based on DtNetPduHeader for backwards compatibility.

Currently used only when Unbundling is enabled

virtual int sizeLength ()
 
virtual void setSizeLength (int length)
 
Enable/Disable test of DIS header fields for valid packets within

bundles.

Must be disabled for non-DIS network sockets if bundling is desired. If not set manually, the test is enabled for backwards compatibility. Currently used only when Unbundling is enabled

virtual bool testDisHeader ()
 
virtual void enableDisHeaderTest (bool shouldTest)
 
Add/drop subscription to a particular multicast address on

the specified network interface.

virtual int listenToMulticastGroup (DtIpv4Addr multicastAddr, DtIpv4Addr netInterface=DtUSE_DEFAULT_IP_ADDR)
 
virtual int dropMulticastGroup (DtIpv4Addr multicastAddr, DtIpv4Addr netInterface=DtUSE_DEFAULT_IP_ADDR)
 
Set/Get device for multicast traffic
virtual void setMcastDevice (DtIpv4Addr devAddr)
 
virtual DtIpv4Addr mcastDevice () const
 
- Public Member Functions inherited from DtSocket
 DtSocket ()
 Default constructor. More...
 
virtual ~DtSocket ()
 Default Destructor. More...
 
virtual int DtSend (caddr_t packet, size_t size, DtIpv4Addr addr=DtUSE_DEFAULT_IP_ADDR)
 DtSend is called when someone wants to send a packet to this "Socket", in other words, all outgoing messages are passed to this socket via DtSend(). More...
 
caddr_t DtRecv ()
 
virtual DtFlushStatus flush ()
 Send buffered messages. More...
 
virtual DtFlushStatus flush (long &byteCount)
 Send buffered messages. More...
 
virtual void setReceiveBufferSize (int newsize)
 Change the socket's receive buffer size that the OS uses to collect incoming data from the network. More...
 
virtual void setSendBufferSize (int newsize)
 Change the socket's send buffer size that the OS uses when writing data to the network. More...
 
virtual int isBundling ()
 
virtual int DtReportPktsRcvd (void)
 
virtual void notifyMe ()
 
virtual DtFilterTestexerciseId ()
 
virtual DtFilterTestprotocolVersion ()
 
virtual DtFilterTestpduKind ()
 
virtual DtFilterTestipAddr ()
 

Static Public Member Functions

static int isMulticastAddr (DtIpv4Addr addr)
 Returns 1 if addr is a multicast address, 0 otherwise. More...
 
static int enableBroadcast (int sockfd)
 Make sockfd capable of broadcasting. More...
 
static void makeNonBlocking (int sockfd)
 Make sockfd non-blocking. More...
 
static int makeReusable (int sockfd)
 Make port/address reusable by other sockets. More...
 
static void setRetryOnSend (unsigned int numRetries, double waitPeriod)
 Make socket retry numRetries times ( waiting for waitPeriod between ) when sendto fails ( numRetries = 0 means message will be dropped ) More...
 
static DtIpv4Addr inetBroadcastOfDevice (const char *device=NULL)
 Obtain information about a device. More...
 
static DtIpv4Addr inetAddrOfDevice (const char *device=NULL)
 
static DtIpv4Addr netMaskOfDevice (const char *device=NULL)
 
static DtIpv4Addr firstHostInetAddr ()
 
static void setInetAddr (sockaddr_in &s, u_long addr, int port)
 Fill out a sockaddr_in structure. More...
 
- Static Public Member Functions inherited from DtSocket
static void initializeNetwork ()
 
static void setQuietSockets (bool quietVal)
 These functions determine whether a socket will print messages, informative or error. More...
 
static bool areQuietSockets ()
 

Static Public Attributes

static DtInitErrorAction initErrorAction
 

Protected Member Functions

void init (int port, DtIpv4Addr dest_addr, DtU8 flags, DtIpv4Addr devAddr=0)
 Called from all constructors. More...
 
virtual int dataLeftInCurrentBundle ()
 Is there still data left in the last received packet? More...
 
virtual int retrySendTo (caddr_t packet, size_t size, sockaddr_in &dest)
 If retry is enabled, retry failed packet send theMaxSendRetries times. More...
 
virtual int recvWithStatus (caddr_t *buffptr, int *status)
 Sets buffptr to point to the next packet (might be next in bundle, might require a read from net) and returns size. More...
 
virtual int recvFromNet (caddr_t *buffptr)
 Grabs the next packet from the network, and puts it into myPktBuff. More...
 
virtual int recvWithUnbundling (caddr_t *buffptr)
 Used by recvWithStatus if unbundling is on. More...
 
int initSocket ()
 Initialize the socket. More...
 
int initWrite (DtIpv4Addr dest)
 Initialize for writing. More...
 
int initRead (DtIpv4Addr dest)
 Initialize for reading, including performing bind. More...
 
virtual int privateListenToMulticastGroup (DtIpv4Addr multicastAddr, int on_init=0, DtIpv4Addr netInterface=DtUSE_DEFAULT_IP_ADDR)
 Helper function for listenToMulticastGroup. More...
 
virtual void findNextPacket ()
 Sets myNextPacket to point to the next packet. More...
 
virtual unsigned int getNextPacketSize ()
 Gets the size of the next packet pointed to by myNextPacket. More...
 
virtual unsigned int currentHeaderMatchesFirstInBundle ()
 DIS-specific function to help decide if unbundling is successful. More...
 
 DtNetSocket (const DtNetSocket &)
 Not Implemented. More...
 
DtNetSocketoperator= (const DtNetSocket &)
 Not Implemented. More...
 
- Protected Member Functions inherited from DtSocket
virtual bool accept (char *buf, DtIpv4Addr iaddr)
 

Static Protected Member Functions

static ifreq * findIfr (const char *device, int sock, ifconf *ifc)
 Find a device. More...
 
static DtIpv4Addr netMaskOfIfr (ifreq *ifr, int sock)
 Obtain information about a device. Dummy socket needed for ioctls. More...
 
static DtIpv4Addr inetAddrOfIfr (ifreq *ifr, int sock)
 
static DtIpv4Addr inetBroadcastOfIfr (ifreq *ifr, int sock)
 
static bool capableOfIpBroadcast (ifreq *ifr, int sock)
 
- Static Protected Member Functions inherited from DtSocket
static int getConfig (const char *device, int sock, ifconf *ifc)
 Get ifconfig information by filling in ifc. More...
 

Protected Attributes

int myUdpPort
 
int myFilterPort
 
int mySendPort
 
unsigned int mySourcePort
 
char * myPktBuff
 
char * myUnbundleBuff
 
void * myNextPacket
 
int myUsingExternalSocket
 
DtIpv4Addr myExtSockAddr
 
DtIpv4Addr myDestInetAddr
 
DtIpv4Addr myDevAddr
 
int myUnbundling
 
int sizeLeft
 
int myPktMinSize
 
int myPktSizeOffset
 
int myPktSizeLength
 
int myMaxPacketSize
 
bool myTestingDisHeader
 
int boundToDestAddr
 
int firstInBundle
 
int firstExId
 
int firstProtocol
 
bool myOkFlag
 
sockaddr_in * destSockAddr
 
sockaddr_in * sourceSockAddr
 
DtU8 myFlags
 
- Protected Attributes inherited from DtSocket
BufferMap myBufferMap
 
int myBundlingFlag
 
int myMaxBundleSize
 
int mySockFd
 

Static Protected Attributes

static unsigned int theMaxSendRetries
 
static double theSendRetryPeriod
 
- Static Protected Attributes inherited from DtSocket
static bool theAreQuietSockets
 Should a socket print messages, informative or error. More...
 

Additional Inherited Members

- Public Attributes inherited from DtSocket
int myBlockingFlag
 
int pkts_rcvd
 
- Protected Types inherited from DtSocket
typedef std::vector< char > Buffer
 
typedef std::map< DtIpv4Addr,
Buffer
BufferMap
 

Detailed Description

A DtSocket that implements network sending and receiving function using IP/UDP broadcast, multicast or unicast.

The class provides a platform-independent interface to a network connection capable of sending and receiving arbitrary datagrams.

Deprecated:
This class is replaced by DtInetSocket and other classes as of VR-Link 3.13

Constructor & Destructor Documentation

DtNetSocket::DtNetSocket ( int  port = DtDEFAULT_PORT,
DtU8  flags = DtReadWrite,
DtIpv4Addr  devAddr = 0 
)

Constructor.

Takes a UDP port number, and a flags bitfield. All UDP sockets must use the same port number in order to communicate with each other. A default destination address (address to which is to send outgoing packets) is used - the broadcast address of the host's primary network device.

DtNetSocket::DtNetSocket ( int  port,
DtIpv4Addr  destAddr,
DtU8  flags,
DtIpv4Addr  devAddr = 0 
)

Constructor.

Similar to above, but allows you to specify a destination address other than the default broadcast address. destAddr can be a unicast, broadcast or multicast address. A value of 0 for destAddr means use the default broadcast address. The flags argument is required to disambiguate from other constructors.

DtNetSocket::DtNetSocket ( char *  dummy,
int  sockfd,
DtU8  flags = DtReadWrite 
)

Allows you to create a DtNetSocket that uses a pre-existing socket.

Dummy is currently ignored.

virtual DtNetSocket::~DtNetSocket ( )
virtual

Destructor.

DtNetSocket::DtNetSocket ( const DtNetSocket )
protected

Not Implemented.

Member Function Documentation

static bool DtNetSocket::capableOfIpBroadcast ( ifreq *  ifr,
int  sock 
)
staticprotected
virtual unsigned int DtNetSocket::currentHeaderMatchesFirstInBundle ( )
protectedvirtual

DIS-specific function to help decide if unbundling is successful.

virtual int DtNetSocket::dataLeftInCurrentBundle ( )
protectedvirtual

Is there still data left in the last received packet?

virtual int DtNetSocket::dropMulticastGroup ( DtIpv4Addr  multicastAddr,
DtIpv4Addr  netInterface = DtUSE_DEFAULT_IP_ADDR 
)
virtual

Reimplemented from DtSocket.

virtual void DtNetSocket::DtBecomeNonBlocking ( void  )
virtual

Make the socket non-blocking.

Reimplemented from DtSocket.

virtual int DtNetSocket::DtRecv ( caddr_t *  buffptr,
int status = NULL 
)
virtual

DtNetSocket implements DtRecv by calling a system call to recvfrom on its UDP socket.

Implements DtSocket.

virtual int DtNetSocket::DtRecv ( caddr_t  buff,
size_t   
)
virtual

DtNetSocket implements DtRecv by calling a system call to recvfrom on its UDP socket.

Implements DtSocket.

static int DtNetSocket::enableBroadcast ( int  sockfd)
static

Make sockfd capable of broadcasting.

virtual void DtNetSocket::enableDisHeaderTest ( bool  shouldTest)
virtual
static ifreq* DtNetSocket::findIfr ( const char *  device,
int  sock,
ifconf *  ifc 
)
staticprotected

Find a device.

If device is NULL, returns the ifreq of the first device capable of broadcast. Dummy socket needed for ioctls.

virtual void DtNetSocket::findNextPacket ( )
protectedvirtual

Sets myNextPacket to point to the next packet.

This may or may not require a recvFromNet. Packets less than myMinPktSize bytes long cause the rest of a packet to be discarded, and the following packet is found. If no packets, myNextPacket is set to NULL.

static DtIpv4Addr DtNetSocket::firstHostInetAddr ( )
static
virtual unsigned int DtNetSocket::getNextPacketSize ( )
protectedvirtual

Gets the size of the next packet pointed to by myNextPacket.

Assumes myNextPacket was set via findNextPacket. Uses sizeLength() and sizeOffset() to determine which bytes represent packet size. Returns 0 if myNextPacket does not point to a valid packet.

static DtIpv4Addr DtNetSocket::inetAddrOfDevice ( const char *  device = NULL)
static
static DtIpv4Addr DtNetSocket::inetAddrOfIfr ( ifreq *  ifr,
int  sock 
)
staticprotected
static DtIpv4Addr DtNetSocket::inetBroadcastOfDevice ( const char *  device = NULL)
static

Obtain information about a device.

static DtIpv4Addr DtNetSocket::inetBroadcastOfIfr ( ifreq *  ifr,
int  sock 
)
staticprotected
void DtNetSocket::init ( int  port,
DtIpv4Addr  dest_addr,
DtU8  flags,
DtIpv4Addr  devAddr = 0 
)
protected

Called from all constructors.

int DtNetSocket::initRead ( DtIpv4Addr  dest)
protected

Initialize for reading, including performing bind.

int DtNetSocket::initSocket ( )
protected

Initialize the socket.

int DtNetSocket::initWrite ( DtIpv4Addr  dest)
protected

Initialize for writing.

If dest is 0, use default broadcast address. Actual destination address used is stored in myDestInetAddr.

static int DtNetSocket::isMulticastAddr ( DtIpv4Addr  addr)
static

Returns 1 if addr is a multicast address, 0 otherwise.

virtual bool DtNetSocket::isOk ( ) const
virtual

Returns 1 if the socket's constructor initialization was successful, 0 otherwise.

Reimplemented from DtSocket.

virtual int DtNetSocket::isUnbundling ( )
virtual

Set all bundling parameters Disables bundling if max.

bundle size = 0 (as does base socket setBundling)

virtual DtIpv4Addr DtNetSocket::lastSourceInetAddr ( )
virtual

Return the IP address of the sender of the last packet we've received.

Reimplemented from DtSocket.

virtual int DtNetSocket::listenToMulticastGroup ( DtIpv4Addr  multicastAddr,
DtIpv4Addr  netInterface = DtUSE_DEFAULT_IP_ADDR 
)
virtual

Reimplemented from DtSocket.

static void DtNetSocket::makeNonBlocking ( int  sockfd)
static

Make sockfd non-blocking.

static int DtNetSocket::makeReusable ( int  sockfd)
static

Make port/address reusable by other sockets.

virtual DtIpv4Addr DtNetSocket::mcastDevice ( ) const
virtual
virtual int DtNetSocket::minPacketSize ( )
virtual
static DtIpv4Addr DtNetSocket::netMaskOfDevice ( const char *  device = NULL)
static
static DtIpv4Addr DtNetSocket::netMaskOfIfr ( ifreq *  ifr,
int  sock 
)
staticprotected

Obtain information about a device. Dummy socket needed for ioctls.

DtNetSocket& DtNetSocket::operator= ( const DtNetSocket )
protected

Not Implemented.

virtual int DtNetSocket::privateListenToMulticastGroup ( DtIpv4Addr  multicastAddr,
int  on_init = 0,
DtIpv4Addr  netInterface = DtUSE_DEFAULT_IP_ADDR 
)
protectedvirtual

Helper function for listenToMulticastGroup.

virtual int DtNetSocket::readFd ( )
virtual

Return read/write file descriptor of the UDP socket being used for sending and receiving.

Returns -1 if the socket is not readable/writable.

Reimplemented from DtSocket.

virtual int DtNetSocket::recvFromNet ( caddr_t *  buffptr)
protectedvirtual

Grabs the next packet from the network, and puts it into myPktBuff.

If there is a packet, sets buffptr to point to myPktBuff, and returns size of packet. If not, buffptr = 0, and return 0.

Reimplemented in DtAsyncNetSocket.

virtual int DtNetSocket::recvWithStatus ( caddr_t *  buffptr,
int status 
)
protectedvirtual

Sets buffptr to point to the next packet (might be next in bundle, might require a read from net) and returns size.

If no packet, or if the packet is filtered out, buffptr is NULL, and 0 is returned. Status is DtSOCKET_NO_PACKET, DtSOCKET_PACKET, or DtSOCKET_FILTERED_PACKET.

virtual int DtNetSocket::recvWithUnbundling ( caddr_t *  buffptr)
protectedvirtual

Used by recvWithStatus if unbundling is on.

Finds next packet, and sets buffptr to point to it. If no packet, returns 0 and sets buffptr to NULL. Will never return a size larger than the number of remaining bytes in a packet.

virtual int DtNetSocket::retrySendTo ( caddr_t  packet,
size_t  size,
sockaddr_in &  dest 
)
protectedvirtual

If retry is enabled, retry failed packet send theMaxSendRetries times.

virtual int DtNetSocket::sendTo ( caddr_t  packet,
size_t  size,
DtIpv4Addr  addr 
)
virtual

Virtual function override.

DtNetSocket implements sendTo by sending the packet to the indicated address through its UDP socket, using the system call sendto.

Implements DtSocket.

Reimplemented in DtAsyncNetSocket.

virtual void DtNetSocket::setBundling ( int  maxBundleSize,
bool  enableUnbundling,
int  minPacketSize,
int  sizeOffset,
int  sizeLength,
bool  testDisHeader 
)
virtual

Set all bundling parameters Disables bundling if max.

bundle size = 0 (as does base socket setBundling)

void DtNetSocket::setBundling ( int  maxBundleSize)
inlinevirtual

Call through to DtSocket::setBundling to prevent compiler warnings.

Reimplemented from DtSocket.

References DtSocket::setBundling().

virtual void DtNetSocket::setFilterPort ( const int port)
virtual
static void DtNetSocket::setInetAddr ( sockaddr_in &  s,
u_long  addr,
int  port 
)
static

Fill out a sockaddr_in structure.

virtual void DtNetSocket::setMcastDevice ( DtIpv4Addr  devAddr)
virtual

Reimplemented from DtSocket.

virtual int DtNetSocket::setMcastTtl ( int  ttl)
virtual

Set the TTL (time to live) value for multicast packets.

Reimplemented from DtSocket.

virtual void DtNetSocket::setMinPacketSize ( int  size)
virtual
static void DtNetSocket::setRetryOnSend ( unsigned int  numRetries,
double  waitPeriod 
)
static

Make socket retry numRetries times ( waiting for waitPeriod between ) when sendto fails ( numRetries = 0 means message will be dropped )

virtual void DtNetSocket::setSendPort ( const int port)
virtual
virtual void DtNetSocket::setSizeLength ( int  length)
virtual
virtual void DtNetSocket::setSizeOffset ( int  offset)
virtual
virtual void DtNetSocket::setUnbundling ( int  onOff)
virtual

Pass 0 to setUnbundling to turn unbundling off, 1 to turn it on.

Use isUnbundling to find out the current status of this option. Bundling of outgoing packets is controlled through the base class's (DtSocket's) member functions.

Reimplemented from DtSocket.

virtual int DtNetSocket::sizeLength ( )
virtual
virtual int DtNetSocket::sizeOffset ( )
virtual
virtual bool DtNetSocket::testDisHeader ( )
virtual
virtual int DtNetSocket::writeFd ( )
virtual

Reimplemented from DtSocket.

Member Data Documentation

int DtNetSocket::boundToDestAddr
protected
sockaddr_in* DtNetSocket::destSockAddr
protected
int DtNetSocket::firstExId
protected
int DtNetSocket::firstInBundle
protected
int DtNetSocket::firstProtocol
protected
DtInitErrorAction DtNetSocket::initErrorAction
static
DtIpv4Addr DtNetSocket::myDestInetAddr
protected
DtIpv4Addr DtNetSocket::myDevAddr
protected
DtIpv4Addr DtNetSocket::myExtSockAddr
protected
int DtNetSocket::myFilterPort
protected
DtU8 DtNetSocket::myFlags
protected
int DtNetSocket::myMaxPacketSize
protected
void* DtNetSocket::myNextPacket
protected
bool DtNetSocket::myOkFlag
protected
char* DtNetSocket::myPktBuff
protected
int DtNetSocket::myPktMinSize
protected
int DtNetSocket::myPktSizeLength
protected
int DtNetSocket::myPktSizeOffset
protected
int DtNetSocket::mySendPort
protected
unsigned int DtNetSocket::mySourcePort
protected
bool DtNetSocket::myTestingDisHeader
protected
int DtNetSocket::myUdpPort
protected
char* DtNetSocket::myUnbundleBuff
protected
int DtNetSocket::myUnbundling
protected
int DtNetSocket::myUsingExternalSocket
protected
int DtNetSocket::sizeLeft
protected
sockaddr_in* DtNetSocket::sourceSockAddr
protected
unsigned int DtNetSocket::theMaxSendRetries
staticprotected
double DtNetSocket::theSendRetryPeriod
staticprotected

The documentation for this class was generated from the following file:

Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)