]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/bind.c
2 Implement the bind API.
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
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.
15 #include <SocketInternals.h>
19 Bind a name to a socket.
21 The bind routine connects a name (network address) to a socket on the local machine.
24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
25 documentation is available online.
27 @param[in] s Socket file descriptor returned from ::socket.
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.
39 @param[in] namelen Specifies the length in bytes of the sockaddr structure.
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.
48 IN
const struct sockaddr
* name
,
53 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
57 // Locate the context for this socket
59 pSocketProtocol
= BslFdToSocketProtocol ( s
, NULL
, &errno
);
60 if ( NULL
!= pSocketProtocol
) {
64 Status
= pSocketProtocol
->pfnBind ( pSocketProtocol
,
71 // Return the operation stauts
73 BindStatus
= ( 0 == errno
) ? 0 : -1;