@CHIP-RTOS C Library - TCP/IP API
bind
Bind an unnamed socket to an address and port number. int bind ( int sd,
const struct sockaddr far *addressPtr,
int *error ); Parameters
sd
- Socket descriptor.
addressPtr
- Pointer to a
sockaddr_in
(IPv4) or
sockaddr_in6
(IPv6, SC1x3/SC2x only!
) data structure preset by caller.
error
- Output parameter: Failure
code, 0 on success.
Return Value
- 0 = success
Non-zero = Failure (see error
output parameter)
Comments
- It is only necessary to use the bind call in server applications.
If you use the bind call in a client application, the client uses the
given port number as its own source port address. Otherwise a random
16-bit source port number will be used when no bind call is made.
The caller must fill in the
sockaddr_in (IPv4) or
sockaddr_in6
(IPv6, SC1x3/SC2x only!
) data structure at addressPtr
prior
to making this API call. An example (IPv4) of how this
can be done follows. This function's prototype uses a pointer to the
generic type sockaddr
for its addressPtr
parameter,
for compatibility between IPv4 and IPv6 protocols. The pointer to the
sockaddr_in
(IPv4) or sockaddr_in6
(IPv6)
data structure which
is actually used should be cast to this type as shown below to avoid
compiler warnings, "Suspicious pointer conversion".
SC1x3/SC2x Comments- This legacy version of bind()
specified here is not compatible
to the BSD 4.4 Socket API. The bind()
function can be used
in BSD 4.4 compatible mode if the compilation switch
#define BSD44_SOCKET_API_STYLE
is defined in the user application prior to including the Beck C-Library
header files. Using this switch the C-Library TCPIP_Socket.H include
file redefines bind()
to
bind_bsd(). The parameters
to bind_bsd()
are identical to the parameters of the BSD4.4 socket
bind()
function.
| | // Example
int ClientPort = 4000 ;
struct sockaddr_in addr ;
int error_code ;
addr.sin_family = PF_INET ;
addr.sin_addr.s_addr = 0 ;
addr.sin_port = htons(ClientPort); // convert byte order
error_code = bind (sd, (const struct sockaddr *)&addr, &error_code) ; |
See Also
RTOS API
- This library function invokes a RTOS software interrupt.
Refer to this RTOS API function's
documentation
for more details.
Supported since or modified in @CHIP-RTOS version-
| SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
| V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
This API List
List of C Libraries
@CHIP-RTOS Main Index
End of document
|