]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/getsockname.c
UefiCpuPkg/MicrocodeUpdateDxe: Fix coding style issues in INF file
[mirror_edk2.git] / StdLib / BsdSocketLib / getsockname.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the getsockname API.\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <SocketInternals.h>\r
16\r
17\r
18/**\r
19 Get the local socket address.\r
20\r
a88c3163 21 The getsockname routine retrieves the local system address from the socket.\r
22\r
d7ce7006 23 The\r
24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html#">POSIX</a>\r
25 documentation is available online.\r
26\r
27 @param [in] s Socket file descriptor returned from ::socket.\r
28\r
29 @param [out] address Network address to receive the local system address\r
30\r
31 @param [in] address_len Length of the local network address structure\r
32\r
a88c3163 33 @return This routine returns zero (0) if successful or -1 when an error occurs.\r
34 In the case of an error, ::errno contains more details.\r
d7ce7006 35\r
36 **/\r
37int\r
38getsockname (\r
39 int s,\r
40 struct sockaddr * address,\r
41 socklen_t * address_len\r
42 )\r
43{\r
44 int RetVal;\r
45 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
46 EFI_STATUS Status;\r
47\r
48 //\r
49 // Assume failure\r
50 //\r
51 RetVal = -1;\r
52\r
53 //\r
54 // Locate the context for this socket\r
55 //\r
56 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );\r
57 if ( NULL != pSocketProtocol ) {\r
58 //\r
59 // Get the local socket address\r
60 //\r
61 Status = pSocketProtocol->pfnGetLocal ( pSocketProtocol,\r
62 address,\r
63 address_len,\r
64 &errno );\r
65 if ( !EFI_ERROR ( Status )) {\r
66 RetVal = 0;\r
67 }\r
68 }\r
69\r
70 //\r
71 // Return the operation status\r
72 //\r
73 return RetVal;\r
74}\r