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