www.beck-ipc.com

@CHIP-RTOS C Library V2.06 - 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, SC123/SC143 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, SC123/SC143 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".

            
// 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

    SC12SC13SC11SC1x3
    V1.00V1.00V1.00V0.90

This API List
List of C Libraries
@CHIP-RTOS Main Index


End of document