]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/bind.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / BsdSocketLib / bind.c
1 /** @file
2 Implement the bind API.
3
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <SocketInternals.h>
16
17
18 /**
19 Bind a name to a socket.
20
21 The bind routine connects a name (network address) to a socket on the local machine.
22
23 The
24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
25 documentation is available online.
26
27 @param[in] s Socket file descriptor returned from ::socket.
28
29 @param[in] name Address of a sockaddr structure that contains the
30 connection point on the local machine. An IPv4 address
31 of INADDR_ANY specifies that the connection is made to
32 all of the network stacks on the platform. Specifying a
33 specific IPv4 address restricts the connection to the
34 network stack supporting that address. Specifying zero
35 for the port causes the network layer to assign a port
36 number from the dynamic range. Specifying a specific
37 port number causes the network layer to use that port.
38
39 @param[in] namelen Specifies the length in bytes of the sockaddr structure.
40
41 @return The bind routine returns zero (0) if successful and -1 upon failure.
42 In the case of an error, ::errno contains more information.
43
44 **/
45 int
46 bind (
47 IN int s,
48 IN const struct sockaddr * name,
49 IN socklen_t namelen
50 )
51 {
52 int BindStatus;
53 EFI_SOCKET_PROTOCOL * pSocketProtocol;
54 EFI_STATUS Status;
55
56 //
57 // Locate the context for this socket
58 //
59 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
60 if ( NULL != pSocketProtocol ) {
61 //
62 // Bind the socket
63 //
64 Status = pSocketProtocol->pfnBind ( pSocketProtocol,
65 name,
66 namelen,
67 &errno );
68 }
69
70 //
71 // Return the operation stauts
72 //
73 BindStatus = ( 0 == errno ) ? 0 : -1;
74 return BindStatus;
75 }