The DIS Netdump example is a simple program that prints all received PDUs to a console.
VR-Link includes this as a tool that can be used to monitor the information sent over the network. It particularly comes in handy as a debug tool, allowing users to see if packets are sent correctly, if there's anything flooding the network, and more.
#if DtDIS
#include <vcPdu.h>
#include <stdio.h>
#include <iostream>
#include <vector>
char* vb = 0;
char* clearScreen = (char *)"";
int numBetweenStdinChecks = 100;
#if defined(_WIN32) || defined(__solaris__)
#else
unsigned int defaultReceiveBufferSize(UINT_MAX);
#endif
DtCmdLine::ValueArg<int> receiveBufferSize(
"",
"receiveBufferSize",
"Receive Buffer Size",
false, defaultReceiveBufferSize,
"integer");
#if VXWORKS
#define main realMain
#endif
int main( int argc, char* argv[] )
{
signal( SIGFPE, SIG_IGN );
DtInfo(
"Using VR-Link version %s\n",
#if defined( DT_HAVE_64BIT_LONGS ) || defined( _WIN64 )
DtInfo(
"Built on %s with %s - %s\n",
#else
DtInfo(
"Built on %s with %s - %s\n",
#endif
#ifndef _GT_
setvbuf( stdout, NULL, _IOFBF, BUFSIZ );
#endif
cmdLine.add(destAddrString);
cmdLine.add(netmaskString);
cmdLine.add(deviceAddrString);
cmdLine.add(disPort);
cmdLine.add(siteId);
cmdLine.add(appNumber);
cmdLine.add(verbose);
cmdLine.add(useIpv6);
cmdLine.add(errorChecking);
cmdLine.add(receiveBufferSize);
cmdLine.add(clearScreenFlag);
cmdLine.add(mcastAddrs);
cmdLine.add(printRaw);
cmdLine.parse(argc, argv);
if (clearScreenFlag)
{
clearScreen = (char *)"\033[H\033[2J";
}
if (deviceAddrString.isSet())
{
if (netDevice.isOk())
{
netDeviceToUse = &netDevice;
}
else
{
DtWarn(
"Invalid device address: \"%s\" Using default.\n",
}
}
if (netmaskString.isSet())
{
destAddr =
DtInetAddr(destAddrString.getValue(), netmaskString.getValue());
}
if (destAddrString.isSet())
{
}
else
{
if (bcastAddr)
{
}
else
{
}
}
{
DtWarn(
"Netdump socket OK to: %s\n",
}
else
{
}
if (receiveBufferSize.isSet())
{
if (receiveBufferSize <= 0)
{
DtWarn(
"Invalid receive buffer size: %s must be > 0.\n",
DtToString(receiveBufferSize.getValue()).c_str());
}
else
{
}
}
std::vector <DtString>::const_iterator pos = mcastAddrs.getValue().begin();
for (; pos != mcastAddrs.getValue().end(); ++pos)
{
}
pduFactory = &fact;
pduFactory->DtADD_PDU_CREATOR(ViewControl);
fflush( stdout );
if ( verbose )
{
vb =(char *)"************************************************************\n";
}
else
{
vb = (char *)"";
}
int forever = 1;
while( forever )
{
int numBeforeStdinCheck = 0;
do
{
if ( numBeforeStdinCheck == 0 )
{
numBeforeStdinCheck = numBetweenStdinChecks;
{
return 0;
}
}
else
{
--numBeforeStdinCheck;
}
} while( readAndProcess( skt ) );
}
return 0;
}
{
static int n = 1;
char packet[15000];
int size = status;
{
return 0;
}
{
DtWarn(
"#### WARNING: Packet too small for DIS header: Received(%s), HeaderSize(%s) ####\n",
return 1;
}
{
DtWarn(
"#### WARNING: Invalid DIS packet length: Received(%s), DIS Header(%s) ####\n",
return 1;
}
if ( size != pktSize && pktVersion >= 7 && !isCoupling)
{
DtWarn(
"#### WARNING: Size mismatch: Received(%s), DIS Header(%s) ####\n",
if ( errorChecking )
{
DtWarn(
" Will not attempt to print this PDU.\n");
return 1;
}
}
if ( printRaw )
{
DtInfo(
"%s%s******** PDU #%-6d \t\t %13.3f secs ********\n%s",
unkPdu.printHeader();
int pduSize = unkPdu.length();
if (pduSize > size)
{
pduSize = size;
}
for ( int k = 0; k + 3 < pduSize; k += 4 )
{
DtInfo(
"%04x\t%08x\n", k, *(
DtU32 *)(unkPdu.netRep() + k));
}
}
if ( (((pduStatus >> 3) & 0x1) == 0x1))
{
unsigned int minimumSizeForAttibutePdu = pktSize + couplingPadding +
sizeof(
DtNetAttributePdu);
if (!(size >= minimumSizeForAttibutePdu))
{
DtWarn(
"Turning off Coupled Extension Indicator in Bad PDU due to packet having insufficient space\n");
isCoupling = false;
}
else
{
}
}
{
}
else
{
}
if (pduWithAttrRecSet)
{
}
if ( pdu )
{
if ( !printRaw )
{
DtInfo(
"%s%s******** PDU #%-6d \t\t %13.3f secs ********\n%s",
}
}
if (isCoupling && !printRaw)
{
unsigned int coupledOffset = pktSize + couplingPadding;
{
char* coupledPduPtr = packet + coupledOffset;
unsigned int bytesRemaining = size - coupledOffset;
if (coupledSize >= (
int)
sizeof(
DtNetPduHeader) && coupledSize <= (
int)bytesRemaining)
{
}
else
{
DtWarn(
"#### WARNING: Invalid coupled PDU length: Remaining(%s), DIS Header(%s) ####\n",
pdu = 0;
}
}
else
{
DtWarn(
"#### WARNING: Coupled PDU header not fully present in packet. ####\n");
pdu = 0;
}
if (pdu)
{
DtInfo(
"%s%s******** PDU #%-6d \t\t %13.3f secs ********\n%s",
}
}
return 1;
}
#endif