Update the sockets applications

* Builds with GCC 4.4 compiler.

Signed-off by: lpleahy


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12498 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lpleahy
2011-09-30 23:04:13 +00:00
parent a88c31639b
commit 59bc059327
52 changed files with 3062 additions and 235 deletions

View File

@@ -0,0 +1,44 @@
/** @file
Raw IP4 receive test 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
http://opensource.org/licenses/bsd-license.php
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"
/**
Receive raw datagrams from a remote system.
@param [in] Argc The number of arguments
@param [in] Argv The argument value array
@retval 0 The application exited normally.
@retval Other An error occurred.
**/
int
main (
IN int Argc,
IN char **Argv
)
{
int RetVal;
//
// Run the application
//
RetVal = RawIp4Rx ( Argc, Argv );
//
// Return the operation status
//
return RetVal;
}

View File

@@ -0,0 +1,188 @@
/** @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
http://opensource.org/licenses/bsd-license.php
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"
UINT8 mBuffer[65536];
/**
Run the raw IP4 receive application
@param [in] ArgC Argument count
@param [in] ArgV Argument value array
@retval 0 Successfully operation
**/
int
RawIp4Rx (
IN int ArgC,
IN char **ArgV
)
{
ssize_t BytesReceived;
struct sockaddr_in LocalPort;
socklen_t LocalPortLength;
struct sockaddr_in RemotePort;
socklen_t RemotePortLength;
int RetVal;
SOCKET s;
UINT64 TotalBytesReceived;
//
// Create the socket
//
s = socket ( AF_INET, SOCK_RAW, RAW_PROTOCOL );
if ( -1 == s ) {
RetVal = GET_ERRNO;
printf ( "ERROR - socket error, errno: %d\r\n", RetVal );
}
else {
//
// Use for/break; instead of goto
//
for ( ; ; ) {
//
// Bind the socket to a known port
//
memset ( &LocalPort, 0, sizeof ( LocalPort ));
SIN_LEN ( LocalPort ) = sizeof ( LocalPort );
SIN_FAMILY ( LocalPort ) = AF_INET;
SIN_ADDR ( LocalPort ) = 0;
SIN_PORT ( LocalPort ) = 0;
RetVal = bind ( s,
(struct sockaddr *)&LocalPort,
sizeof ( LocalPort ));
if ( -1 == RetVal ) {
RetVal = GET_ERRNO;
printf ( "ERROR - bind error, errno: %d\r\n", RetVal );
break;
}
//
// Display the local address and protocol
//
LocalPortLength = sizeof ( LocalPort );
RetVal = getsockname ( s, (struct sockaddr *)&LocalPort, &LocalPortLength );
if ( 0 != RetVal ) {
RetVal = GET_ERRNO;
printf ( "ERROR - getsockname error, errno: %d\r\n", RetVal );
break;
}
printf ( "Local Address: %d.%d.%d.%d, Protocol: %d\r\n",
(UINT8)SIN_ADDR ( LocalPort ),
(UINT8)( SIN_ADDR ( LocalPort ) >> 8 ),
(UINT8)( SIN_ADDR ( LocalPort ) >> 16 ),
(UINT8)( SIN_ADDR ( LocalPort ) >> 24 ),
RAW_PROTOCOL );
//
// Use for/break instead of goto
//
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 );
RetVal = (UINT32)BytesReceived;
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",
(UINT32)BytesReceived,
(UINT8)SIN_ADDR ( RemotePort ),
(UINT8)( SIN_ADDR ( RemotePort ) >> 8 ),
(UINT8)( SIN_ADDR ( RemotePort ) >> 16 ),
(UINT8)( SIN_ADDR ( RemotePort ) >> 24 ),
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]);
TotalBytesReceived += BytesReceived;
//
// All done when the correct packet is received
//
if ( mBuffer[9] == RAW_PROTOCOL ) {
break;
}
}
else if ( -1 == BytesReceived ) {
//
// Check for a timeout
//
RetVal = GET_ERRNO;
printf ( "ERROR - recv error, errno: %d\r\n", RetVal );
break;
}
} while ( 0 != RetVal );
//
// Display the bytes received
//
if ( 0 == RetVal ) {
printf ( "Total Bytes Received: %Ld\r\n", TotalBytesReceived );
}
//
// Test complete
//
break;
}
break;
}
//
// Close the socket
//
CLOSE_SOCKET ( s );
printf ( "Socket closed\r\n" );
}
//
// Return the operation status
//
return RetVal;
}

View File

@@ -0,0 +1,98 @@
/** @file
Definitions for the 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _RAW_IP4_RX_H_
#define _RAW_IP4_RX_H_
//------------------------------------------------------------------------------
// Include Files
//------------------------------------------------------------------------------
#ifdef BUILD_FOR_WINDOWS
//
// Build for Windows environment
//
#include <winsock2.h>
#define CLOSE_SOCKET closesocket
#define SIN_ADDR(port) port.sin_addr.S_un.S_addr
#define SIN_FAMILY(port) port.sin_family
#define SIN_LEN(port) port.sin_family
#define SIN_PORT(port) port.sin_port
#define GET_ERRNO WSAGetLastError ( )
#define ssize_t int
#define socklen_t int
#else // BUILD_FOR_WINDOWS
//
// Build for EFI environment
//
#include <Uefi.h>
#include <errno.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/EfiSysCall.h>
#include <sys/endian.h>
#include <sys/socket.h>
#include <sys/time.h>
#define CLOSE_SOCKET close
#define SIN_ADDR(port) port.sin_addr.s_addr
#define SIN_FAMILY(port) port.sin_family
#define SIN_LEN(port) port.sin_len
#define SIN_PORT(port) port.sin_port
#define SOCKET int
#define GET_ERRNO errno
#endif // BUILD_FOR_WINDOWS
#include <stdio.h>
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
//
// See http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml
// and http://tools.ietf.org/html/rfc3692
//
#define RAW_PROTOCOL 253
//------------------------------------------------------------------------------
// API
//------------------------------------------------------------------------------
/**
Run the raw IP4 receive application
@param [in] ArgC Argument count
@param [in] ArgV Argument value array
@retval 0 Successfully operation
**/
int
RawIp4Rx (
IN int ArgC,
IN char **ArgV
);
//------------------------------------------------------------------------------
#endif // _RAW_IP4_RX_H_

View File

@@ -0,0 +1,64 @@
#/** @file
# RawIp4 Application
#
# This file contains an 'Intel Peripheral Driver' and is
# licensed for Intel CPUs and chipsets under the terms of your
# license agreement with Intel or your vendor. This file may
# be modified by the user, subject to additional terms of the
# license agreement
#
#
# Copyright (c) 20011 Intel Corporation. All rights reserved
# This software and associated documentation (if any) is furnished
# under a license and may only be used or copied in accordance
# with the terms of the license. Except as permitted by such
# license, no part of this software or documentation may be
# reproduced, stored in a retrieval system, or transmitted in any
# form or by any means without the express written consent of
# Intel Corporation.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = RawIp4Rx
FILE_GUID = 8D7AE6A9-B490-45e1-8795-C2BEAADC3814
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = ShellCEntryLib
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
Main.c
RawIp4Rx.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
StdLib/StdLib.dec
[LibraryClasses]
BaseMemoryLib
BsdSocketLib
DebugLib
EfiSocketLib
LibC
LibMath
ShellCEntryLib
UefiBootServicesTableLib
UefiLib
# UseSocketDxe
[BuildOptions]
INTEL:*_*_*_CC_FLAGS = /Qdiag-disable:181,186
MSFT:*_*_*_CC_FLAGS = /Od
GCC:*_*_*_CC_FLAGS = -O0 -Wno-unused-variable

View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RawIp4Rx", "RawIp4Rx.vcproj", "{FAD3909F-E05E-4A2A-9681-7C474EAC5025}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FAD3909F-E05E-4A2A-9681-7C474EAC5025}.Debug|Win32.ActiveCfg = Debug|Win32
{FAD3909F-E05E-4A2A-9681-7C474EAC5025}.Debug|Win32.Build.0 = Debug|Win32
{FAD3909F-E05E-4A2A-9681-7C474EAC5025}.Release|Win32.ActiveCfg = Release|Win32
{FAD3909F-E05E-4A2A-9681-7C474EAC5025}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,211 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="RawIp4Rx"
ProjectGUID="{FAD3909F-E05E-4A2A-9681-7C474EAC5025}"
RootNamespace="RawIp4Rx"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".."
PreprocessorDefinitions="BUILD_FOR_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
BrowseInformation="1"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=".."
PreprocessorDefinitions="BUILD_FOR_WINDOWS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
BrowseInformation="1"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\main.c"
>
</File>
<File
RelativePath="..\RawIp4Rx.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\RawIp4Rx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,61 @@
/** @file
Windows version of the 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
http://opensource.org/licenses/bsd-license.php
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>
/**
Receive raw IP4 packets from a remote system.
Please note that this program must be run with administrator privileges!
@param [in] argc The number of arguments
@param [in] argv The argument value array
@retval 0 The application exited normally.
@retval Other An error occurred.
**/
int
main(
int argc,
char ** argv
)
{
int RetVal;
WSADATA WsaData;
//
// Initialize the WinSock layer
//
RetVal = WSAStartup ( MAKEWORD ( 2, 2 ), &WsaData );
if ( 0 == RetVal ) {
//
// Start the application
//
RetVal = RawIp4Rx ( argc, argv );
if ( WSAEACCES == RetVal ) {
printf ( "Requires administrator privileges to run!\r\n" );
}
//
// Done with the WinSock layer
//
WSACleanup ( );
}
//
// Return the final result
//
return RetVal;
}