VR-Link API Documentation for DIS
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:

List of all members.

Public Member Functions

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

Static Public Member Functions

static int isMulticastAddr (DtIpv4Addr addr)
 Returns 1 if addr is a multicast address, 0 otherwise.
static int enableBroadcast (int sockfd)
 Make sockfd capable of broadcasting.
static void makeNonBlocking (int sockfd)
 Make sockfd non-blocking.
static int makeReusable (int sockfd)
 Make port/address reusable by other sockets.
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 )
static DtIpv4Addr inetBroadcastOfDevice (const char *device=NULL)
 Obtain information about a device.
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.

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.
virtual int dataLeftInCurrentBundle ()
 Is there still data left in the last received packet?
virtual int retrySendTo (caddr_t packet, size_t size, sockaddr_in &dest)
 If retry is enabled, retry failed packet send theMaxSendRetries times.
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.
virtual int recvFromNet (caddr_t *buffptr)
 Grabs the next packet from the network, and puts it into myPktBuff.
virtual int recvWithUnbundling (caddr_t *buffptr)
 Used by recvWithStatus if unbundling is on.
int initSocket ()
 Initialize the socket.
int initWrite (DtIpv4Addr dest)
 Initialize for writing.
int initRead (DtIpv4Addr dest)
 Initialize for reading, including performing bind.
virtual int privateListenToMulticastGroup (DtIpv4Addr multicastAddr, int on_init=0, DtIpv4Addr netInterface=DtUSE_DEFAULT_IP_ADDR)
 Helper function for listenToMulticastGroup.
virtual void findNextPacket ()
 Sets myNextPacket to point to the next packet.
virtual unsigned int getNextPacketSize ()
 Gets the size of the next packet pointed to by myNextPacket.
virtual unsigned int currentHeaderMatchesFirstInBundle ()
 DIS-specific function to help decide if unbundling is successful.
 DtNetSocket (const DtNetSocket &)
 Not Implemented.
DtNetSocketoperator= (const DtNetSocket &)
 Not Implemented.

Static Protected Member Functions

static ifreq * findIfr (const char *device, int sock, ifconf *ifc)
 Find a device.
static DtIpv4Addr netMaskOfIfr (ifreq *ifr, int sock)
 Obtain information about a device. Dummy socket needed for ioctls.
static DtIpv4Addr inetAddrOfIfr (ifreq *ifr, int sock)
static DtIpv4Addr inetBroadcastOfIfr (ifreq *ifr, int sock)
static bool capableOfIpBroadcast (ifreq *ifr, int sock)

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

Static Protected Attributes

static unsigned int theMaxSendRetries
static double theSendRetryPeriod

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 
) [static, protected]
virtual unsigned int DtNetSocket::currentHeaderMatchesFirstInBundle ( ) [protected, virtual]

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

virtual int DtNetSocket::dataLeftInCurrentBundle ( ) [protected, virtual]

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 
) [static, protected]

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 ( ) [protected, virtual]

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.

virtual unsigned int DtNetSocket::getNextPacketSize ( ) [protected, virtual]

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 
) [static, protected]
static DtIpv4Addr DtNetSocket::inetBroadcastOfDevice ( const char *  device = NULL) [static]

Obtain information about a device.

static DtIpv4Addr DtNetSocket::inetBroadcastOfIfr ( ifreq *  ifr,
int  sock 
) [static, protected]
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)

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 
) [static, protected]

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 
) [protected, virtual]

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) [protected, virtual]

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 
) [protected, virtual]

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) [protected, virtual]

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 
) [protected, virtual]

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) [inline, virtual]

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

sockaddr_in* DtNetSocket::destSockAddr [protected]
int DtNetSocket::firstExId [protected]
int DtNetSocket::firstInBundle [protected]
int DtNetSocket::firstProtocol [protected]
int DtNetSocket::myFilterPort [protected]
void* DtNetSocket::myNextPacket [protected]
bool DtNetSocket::myOkFlag [protected]
char* DtNetSocket::myPktBuff [protected]
int DtNetSocket::myPktMinSize [protected]
int DtNetSocket::mySendPort [protected]
unsigned int DtNetSocket::mySourcePort [protected]
int DtNetSocket::myUdpPort [protected]
char* DtNetSocket::myUnbundleBuff [protected]
int DtNetSocket::myUnbundling [protected]
int DtNetSocket::sizeLeft [protected]
sockaddr_in* DtNetSocket::sourceSockAddr [protected]
unsigned int DtNetSocket::theMaxSendRetries [static, protected]
double DtNetSocket::theSendRetryPeriod [static, protected]

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

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)