This is a simple program that prints all received PDUs.
#if DtDIS
#include <vcPdu.h>
#include <stdio.h>
#include <iostream>
#include <vector>
int keybrdTick( void );
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");
DtPduFactory* pduFactory;
#if VXWORKS
#define main realMain
#endif
int main( int argc, char* argv[] )
{
signal( SIGFPE, SIG_IGN );
#if defined( DT_HAVE_64BIT_LONGS ) || defined( _WIN64 )
"64bit"
#else
"32bit"
#endif
<< std::endl;
#ifndef _GT_
setvbuf( stdout, NULL, _IOFBF, BUFSIZ );
#endif
cmdLine.add(destAddrString);
cmdLine.add(netmaskString);
cmdLine.add(deviceAddrString);
cmdLine.add(disPort);
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: \"" << deviceAddrString.getValue()
<< "\" Using default." << std::endl;
}
}
if (netmaskString.isSet())
{
destAddr =
DtInetAddr(destAddrString.getValue(), netmaskString.getValue());
}
if (destAddrString.isSet())
{
}
else
{
if (bcastAddr)
{
}
else
{
}
}
{
}
else
{
}
if (receiveBufferSize.isSet())
{
if (receiveBufferSize <= 0)
{
DtWarn <<
"Invalid receive buffer size: " << receiveBufferSize.getValue() <<
" must be > 0." << std::endl;
}
else
{
}
}
std::vector <DtString>::const_iterator pos = mcastAddrs.getValue().begin();
for (; pos != mcastAddrs.getValue().end(); ++pos)
{
}
DtDisPduFactory fact;
pduFactory = &fact;
pduFactory->DtADD_PDU_CREATOR(ViewControl);
pduFactory->addCreator(
DtPduKind(220), &DtDIGuyCustomPdu::create );
fflush( stdout );
if ( verbose )
{
vb =(char *)"************************************************************\n";
}
else
{
vb = (char *)"";
}
int forever = 1;
while( forever )
{
int numBeforeStdinCheck = 0;
do
{
if ( numBeforeStdinCheck == 0 )
{
numBeforeStdinCheck = numBetweenStdinChecks;
if ( keybrdTick() == -1 )
{
return 0;
}
}
else
{
--numBeforeStdinCheck;
}
} while( readAndProcess( skt ) );
}
return 0;
}
{
static int n = 1;
char packet[15000];
int size = status;
if ( !status )
{
return 0;
}
if ( size != pktSize && pktVersion >= 7 && !isCoupling)
{
DtWarn <<
"#### WARNING: Size mismatch: Received("<< size
<<"), DIS Header(" << pktSize << ") ####\n";
if ( errorChecking )
{
DtWarn <<
" Will not attempt to print this PDU." << std::endl;
return 1;
}
}
if ( printRaw )
{
DtInfo(
"%s%s******** PDU #%-6d \t\t %13.3f secs ********\n%s",
unkPdu.printHeader();
int pduSize = unkPdu.length();
for ( int k = 0; k < 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" << std::endl;
isCoupling = false;
}
else
{
}
}
{
}
else
{
}
if ( pdu )
{
if ( !printRaw )
{
DtInfo(
"%s%s******** PDU #%-6d \t\t %13.3f secs ********\n%s",
}
}
if (isCoupling && !printRaw)
{
char* coupledPduPtr = packet + pktSize + couplingPadding;
if (pdu)
{
DtInfo(
"%s%s******** PDU #%-6d \t\t %13.3f secs ********\n%s",
}
}
return 1;
}
int keybrdTick()
{
if ( !keyPtr )
{
return 0;
}
switch( *keyPtr )
{
case 'q':
case 'Q':
{
return -1;
}
default:
{
std::cout << "Unrecognized command key <" << *keyPtr << ">"
<< std::endl;
break;
}
}
return 0;
}
#endif