]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/bind.c
IntelFsp2WrapperPkg: Update gFspWrapperTokenSpaceGuid to gIntelFsp2WrapperTokenSpaceGuid.
[mirror_edk2.git] / StdLib / BsdSocketLib / bind.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the bind API.\r
3\r
beaaa3b7
OM
4 Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials are licensed and made available under\r
6 the terms and conditions of the BSD License that accompanies this distribution.\r
7 The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
d7ce7006 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
d7ce7006 12**/\r
d7ce7006 13#include <SocketInternals.h>\r
14\r
15\r
beaaa3b7 16/** Bind a name to a socket.\r
d7ce7006 17\r
a88c3163 18 The bind routine connects a name (network address) to a socket on the local machine.\r
19\r
20 The\r
d7ce7006 21 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>\r
a88c3163 22 documentation is available online.\r
d7ce7006 23\r
7dc13291 24 @param[in] s Socket file descriptor returned from ::socket.\r
d7ce7006 25\r
7dc13291 26 @param[in] name Address of a sockaddr structure that contains the\r
d7ce7006 27 connection point on the local machine. An IPv4 address\r
28 of INADDR_ANY specifies that the connection is made to\r
29 all of the network stacks on the platform. Specifying a\r
30 specific IPv4 address restricts the connection to the\r
31 network stack supporting that address. Specifying zero\r
32 for the port causes the network layer to assign a port\r
33 number from the dynamic range. Specifying a specific\r
34 port number causes the network layer to use that port.\r
35\r
7dc13291 36 @param[in] namelen Specifies the length in bytes of the sockaddr structure.\r
d7ce7006 37\r
7dc13291 38 @return The bind routine returns zero (0) if successful and -1 upon failure.\r
a88c3163 39 In the case of an error, ::errno contains more information.\r
d7ce7006 40 **/\r
41int\r
42bind (\r
43 IN int s,\r
44 IN const struct sockaddr * name,\r
45 IN socklen_t namelen\r
46 )\r
47{\r
48 int BindStatus;\r
49 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
d7ce7006 50\r
d7ce7006 51 // Locate the context for this socket\r
d7ce7006 52 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );\r
53 if ( NULL != pSocketProtocol ) {\r
beaaa3b7 54\r
d7ce7006 55 // Bind the socket\r
beaaa3b7 56 (void) pSocketProtocol->pfnBind ( pSocketProtocol,\r
d7ce7006 57 name,\r
58 namelen,\r
59 &errno );\r
60 }\r
61\r
d7ce7006 62 // Return the operation stauts\r
d7ce7006 63 BindStatus = ( 0 == errno ) ? 0 : -1;\r
64 return BindStatus;\r
65}\r