diff options
Diffstat (limited to 'AppPkg/Applications/Sockets/RecvDgram')
-rw-r--r-- | AppPkg/Applications/Sockets/RecvDgram/RecvDgram.c | 116 | ||||
-rw-r--r-- | AppPkg/Applications/Sockets/RecvDgram/RecvDgram.inf | 64 |
2 files changed, 180 insertions, 0 deletions
diff --git a/AppPkg/Applications/Sockets/RecvDgram/RecvDgram.c b/AppPkg/Applications/Sockets/RecvDgram/RecvDgram.c new file mode 100644 index 0000000000..7809e80ff8 --- /dev/null +++ b/AppPkg/Applications/Sockets/RecvDgram/RecvDgram.c @@ -0,0 +1,116 @@ +/** @file
+ Receive a datagram
+
+ 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 <errno.h>
+#include <string.h>
+#include <Uefi.h>
+#include <unistd.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+
+#include <netinet/in.h>
+
+#include <sys/socket.h>
+#include <sys/time.h>
+
+UINT8 mBuffer [ 65536 ];
+
+/**
+ Receive a datagram
+
+ @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
+ )
+{
+ struct sockaddr_in Address;
+ socklen_t AddressLength;
+ ssize_t LengthInBytes;
+ int s;
+ int Status;
+ struct timeval Timeout;
+
+
+ DEBUG (( DEBUG_INFO,
+ "%a starting\r\n",
+ Argv[0]));
+
+ //
+ // Get the socket
+ //
+ s = socket ( AF_INET, SOCK_DGRAM, 0 );
+ if ( -1 == s ) {
+ Print ( L"ERROR - Unable to open the socket, errno: %d\r\n", errno );
+ }
+ else {
+ Timeout.tv_sec = 5;
+ Timeout.tv_usec = 0;
+ Status = setsockopt ( s,
+ SOL_SOCKET,
+ SO_RCVTIMEO,
+ &Timeout,
+ sizeof ( Timeout ));
+ if ( -1 == Status ) {
+ Print ( L"ERROR - Unable to set the receive timeout, errno: %d\r\n", errno );
+ }
+ else {
+ AddressLength = sizeof ( Address );
+ LengthInBytes = recvfrom ( s,
+ &mBuffer[0],
+ sizeof ( mBuffer[0]),
+ 0,
+ (struct sockaddr *)&Address,
+ &AddressLength );
+ if ( -1 == LengthInBytes ) {
+ if ( ETIMEDOUT == errno ) {
+ Print ( L"No datagram received\r\n" );
+ }
+ else {
+ Print ( L"ERROR - No datagram received, errno: %d\r\n", errno );
+ }
+ }
+ else {
+ Print ( L"Received %d bytes from %d.%d.%d.%d:%d\r\n",
+ LengthInBytes,
+ (UINT8)Address.sin_addr.s_addr,
+ (UINT8)( Address.sin_addr.s_addr >> 8 ),
+ (UINT8)( Address.sin_addr.s_addr >> 16 ),
+ (UINT8)( Address.sin_addr.s_addr >> 24 ),
+ htons ( Address.sin_port ));
+ }
+ }
+
+ //
+ // Done with the socket
+ //
+ close ( s );
+ }
+
+ //
+ // All done
+ //
+ DEBUG (( DEBUG_INFO,
+ "%a exiting, errno: %d\r\n",
+ Argv[0],
+ errno ));
+ return errno;
+}
diff --git a/AppPkg/Applications/Sockets/RecvDgram/RecvDgram.inf b/AppPkg/Applications/Sockets/RecvDgram/RecvDgram.inf new file mode 100644 index 0000000000..bef842ad54 --- /dev/null +++ b/AppPkg/Applications/Sockets/RecvDgram/RecvDgram.inf @@ -0,0 +1,64 @@ +#/** @file
+# Receive Datagram 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 = RecvDgram
+ FILE_GUID = 929189C9-0670-4c0b-AF7D-135D1550C8C0
+ 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]
+ RecvDgram.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+ StdLib/StdLib.dec
+
+
+[LibraryClasses]
+ BaseMemoryLib
+ BsdSocketLib
+ DebugLib
+ DevShell
+ 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
+
|