/** @file
Raw IP4 receive application
Copyright (c) 2011, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "RawIp4Rx.h"
/**
Run the raw IP4 receive application
@param [in] ArgC Argument count
@param [in] ArgV Argument value array
@retval 0 Successfully operation
**/
int
RawIp4Rx (
)
{
int RetVal;
SOCKET s;
//
// Create the socket
//
if ( -1 == s ) {
}
else {
//
//
for ( ; ; ) {
//
// Bind the socket to a known port
//
sizeof ( LocalPort ));
if ( -1 == RetVal ) {
break;
}
//
// Display the local address and protocol
//
LocalPortLength = sizeof ( LocalPort );
if ( 0 != RetVal ) {
break;
}
printf ( "Local Address: %d.%d.%d.%d, Protocol: %d\r\n",
RAW_PROTOCOL );
//
//
TotalBytesReceived = 0;
for ( ; ; ) {
//
// Receive data from the remote system
//
do {
//
// Attempt to receive a packet
//
RemotePortLength = sizeof ( RemotePort );
BytesReceived = recvfrom ( s,
&mBuffer[0],
sizeof ( mBuffer ),
0,
(struct sockaddr *)&RemotePort,
&RemotePortLength );
if ( 0 < BytesReceived ) {
//
// Display the received data
//
printf ( "%4d bytes received from %d.%d.%d.%d:%d\r\n"
"%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\r\n"
"%02x %02x %02x %02x\r\n",
SIN_PORT ( RemotePort ),
mBuffer[0],
mBuffer[1],
mBuffer[2],
mBuffer[3],
mBuffer[4],
mBuffer[5],
mBuffer[6],
mBuffer[7],
mBuffer[8],
mBuffer[9],
mBuffer[10],
mBuffer[11],
mBuffer[12],
mBuffer[13],
mBuffer[14],
mBuffer[15],
mBuffer[16],
mBuffer[17],
mBuffer[18],
mBuffer[19]);
//
// All done when the correct packet is received
//
break;
}
}
else if ( -1 == BytesReceived ) {
//
// Check for a timeout
//
break;
}
} while ( 0 != RetVal );
//
// Display the bytes received
//
if ( 0 == RetVal ) {
}
//
// Test complete
//
break;
}
break;
}
//
// Close the socket
//
CLOSE_SOCKET ( s );
printf ( "Socket closed\r\n" );
}
//
// Return the operation status
//
return RetVal;
}