]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/bind.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / BsdSocketLib / bind.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the bind 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 Bind a name to a socket.\r
20\r
a88c3163 21 The bind routine connects a name (network address) to a socket on the local machine.\r
22\r
23 The\r
d7ce7006 24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>\r
a88c3163 25 documentation is available online.\r
d7ce7006 26\r
7dc13291 27 @param[in] s Socket file descriptor returned from ::socket.\r
d7ce7006 28\r
7dc13291 29 @param[in] name Address of a sockaddr structure that contains the\r
d7ce7006 30 connection point on the local machine. An IPv4 address\r
31 of INADDR_ANY specifies that the connection is made to\r
32 all of the network stacks on the platform. Specifying a\r
33 specific IPv4 address restricts the connection to the\r
34 network stack supporting that address. Specifying zero\r
35 for the port causes the network layer to assign a port\r
36 number from the dynamic range. Specifying a specific\r
37 port number causes the network layer to use that port.\r
38\r
7dc13291 39 @param[in] namelen Specifies the length in bytes of the sockaddr structure.\r
d7ce7006 40\r
7dc13291 41 @return The bind routine returns zero (0) if successful and -1 upon failure.\r
a88c3163 42 In the case of an error, ::errno contains more information.\r
d7ce7006 43\r
44 **/\r
45int\r
46bind (\r
47 IN int s,\r
48 IN const struct sockaddr * name,\r
49 IN socklen_t namelen\r
50 )\r
51{\r
52 int BindStatus;\r
53 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
54 EFI_STATUS Status;\r
55\r
56 //\r
57 // Locate the context for this socket\r
58 //\r
59 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );\r
60 if ( NULL != pSocketProtocol ) {\r
61 //\r
62 // Bind the socket\r
63 //\r
64 Status = pSocketProtocol->pfnBind ( pSocketProtocol,\r
65 name,\r
66 namelen,\r
67 &errno );\r
68 }\r
69\r
70 //\r
71 // Return the operation stauts\r
72 //\r
73 BindStatus = ( 0 == errno ) ? 0 : -1;\r
74 return BindStatus;\r
75}\r