-/** @file\r
- Implement the getsockname API.\r
-\r
- Copyright (c) 2011, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include <SocketInternals.h>\r
-\r
-\r
-/**\r
- Get the local socket address.\r
-\r
- The getsockname routine retrieves the local system address from the socket.\r
-\r
- The\r
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html#">POSIX</a>\r
- documentation is available online.\r
-\r
- @param [in] s Socket file descriptor returned from ::socket.\r
-\r
- @param [out] address Network address to receive the local system address\r
-\r
- @param [in] address_len Length of the local network address structure\r
-\r
- @return This routine returns zero (0) if successful or -1 when an error occurs.\r
- In the case of an error, ::errno contains more details.\r
-\r
- **/\r
-int\r
-getsockname (\r
- int s,\r
- struct sockaddr * address,\r
- socklen_t * address_len\r
- )\r
-{\r
- int RetVal;\r
- EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Assume failure\r
- //\r
- RetVal = -1;\r
-\r
- //\r
- // Locate the context for this socket\r
- //\r
- pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );\r
- if ( NULL != pSocketProtocol ) {\r
- //\r
- // Get the local socket address\r
- //\r
- Status = pSocketProtocol->pfnGetLocal ( pSocketProtocol,\r
- address,\r
- address_len,\r
- &errno );\r
- if ( !EFI_ERROR ( Status )) {\r
- RetVal = 0;\r
- }\r
- }\r
-\r
- //\r
- // Return the operation status\r
- //\r
- return RetVal;\r
-}\r