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