]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/getpeername.c
Fix send to properly wait while long transmits are in progress
[mirror_edk2.git] / StdLib / BsdSocketLib / getpeername.c
1 /** @file
2 Implement the getpeername API.
3
4 Copyright (c) 2011, 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
9
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.
12
13 **/
14
15 #include <SocketInternals.h>
16
17
18 /**
19 Get the remote address
20
21 The ::getpeername routine retrieves the remote system address from the socket.
22 The
23 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html#">POSIX</a>
24 documentation is available online.
25
26 @param [in] s Socket file descriptor returned from ::socket.
27
28 @param [out] address Network address to receive the remote system address
29
30 @param [in] address_len Length of the remote network address structure
31
32 @returns ::getpeername returns zero (0) if successful or -1 when an error occurs.
33 In the case of an error, errno contains more details.
34
35 **/
36 int
37 getpeername (
38 int s,
39 struct sockaddr * address,
40 socklen_t * address_len
41 )
42 {
43 int RetVal;
44 EFI_SOCKET_PROTOCOL * pSocketProtocol;
45 EFI_STATUS Status;
46
47 //
48 // Assume failure
49 //
50 RetVal = -1;
51
52 //
53 // Locate the context for this socket
54 //
55 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
56 if ( NULL != pSocketProtocol ) {
57 //
58 // Get the remote address
59 //
60 Status = pSocketProtocol->pfnGetPeer ( pSocketProtocol,
61 address,
62 address_len,
63 &errno );
64 if ( !EFI_ERROR ( Status )) {
65 RetVal = 0;
66 }
67 }
68
69 //
70 // Return the operation status
71 //
72 return RetVal;
73 }