-/** @file\r
- Implement the bind API.\r
-\r
- Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials are licensed and made available under\r
- the terms and conditions of the BSD License that accompanies this distribution.\r
- 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
-#include <SocketInternals.h>\r
-\r
-\r
-/** Bind a name to a socket.\r
-\r
- The bind routine connects a name (network address) to a socket on the local machine.\r
-\r
- The\r
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>\r
- documentation is available online.\r
-\r
- @param[in] s Socket file descriptor returned from ::socket.\r
-\r
- @param[in] name Address of a sockaddr structure that contains the\r
- connection point on the local machine. An IPv4 address\r
- of INADDR_ANY specifies that the connection is made to\r
- all of the network stacks on the platform. Specifying a\r
- specific IPv4 address restricts the connection to the\r
- network stack supporting that address. Specifying zero\r
- for the port causes the network layer to assign a port\r
- number from the dynamic range. Specifying a specific\r
- port number causes the network layer to use that port.\r
-\r
- @param[in] namelen Specifies the length in bytes of the sockaddr structure.\r
-\r
- @return The bind routine returns zero (0) if successful and -1 upon failure.\r
- In the case of an error, ::errno contains more information.\r
- **/\r
-int\r
-bind (\r
- IN int s,\r
- IN const struct sockaddr * name,\r
- IN socklen_t namelen\r
- )\r
-{\r
- int BindStatus;\r
- EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
-\r
- // Locate the context for this socket\r
- pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );\r
- if ( NULL != pSocketProtocol ) {\r
-\r
- // Bind the socket\r
- (void) pSocketProtocol->pfnBind ( pSocketProtocol,\r
- name,\r
- namelen,\r
- &errno );\r
- }\r
-\r
- // Return the operation stauts\r
- BindStatus = ( 0 == errno ) ? 0 : -1;\r
- return BindStatus;\r
-}\r