]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/RecvDgram/RecvDgram.c
4 Copyright (c) 2011-2012, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Library/DebugLib.h>
21 #include <Library/UefiLib.h>
23 #include <netinet/in.h>
25 #include <sys/socket.h>
28 UINT8 mBuffer
[ 65536 ];
33 @param [in] Argc The number of arguments
34 @param [in] Argv The argument value array
36 @retval 0 The application exited normally.
37 @retval Other An error occurred.
45 struct sockaddr_in Address
;
46 socklen_t AddressLength
;
47 ssize_t LengthInBytes
;
50 struct timeval Timeout
;
60 s
= socket ( AF_INET
, SOCK_DGRAM
, 0 );
62 Print ( L
"ERROR - Unable to open the socket, errno: %d\r\n", errno
);
67 Status
= setsockopt ( s
,
73 Print ( L
"ERROR - Unable to set the receive timeout, errno: %d\r\n", errno
);
76 AddressLength
= sizeof ( Address
);
77 LengthInBytes
= recvfrom ( s
,
81 (struct sockaddr
*)&Address
,
83 if ( -1 == LengthInBytes
) {
84 if ( ETIMEDOUT
== errno
) {
85 Print ( L
"No datagram received\r\n" );
88 Print ( L
"ERROR - No datagram received, errno: %d\r\n", errno
);
92 Print ( L
"Received %d bytes from %d.%d.%d.%d:%d\r\n",
94 (UINT8
)Address
.sin_addr
.s_addr
,
95 (UINT8
)( Address
.sin_addr
.s_addr
>> 8 ),
96 (UINT8
)( Address
.sin_addr
.s_addr
>> 16 ),
97 (UINT8
)( Address
.sin_addr
.s_addr
>> 24 ),
98 htons ( Address
.sin_port
));
103 // Done with the socket
112 "%a exiting, errno: %d\r\n",