www.beck-ipc.com

@CHIP-RTOS C Library - TCP/IP API


bind_bsd

Bind an unnamed socket to an address and port number.

int far bind_bsd ( int sd,
                     const struct sockaddr far * addressPtr,
                     int addressLength ) ;

Parameters

sd

Socket descriptor

addressPtr

Pointer to a sockaddr_in (IPv4) or sockaddr_in6 (IPv6) data structure preset by caller.

addressLength

Length of object at addressPtr in bytes, which must be either
     sizeof(struct sockaddr_in)
or
     sizeof(struct sockaddr_in6) .

Return Value

0 on success
-1: Failure, error code is available using get_socketerror.

Comments

The bind call assigns the socket a specific port number for its source port address.   Otherwise a random 16-bit source port number will be used when no bind call is made.   This binding is usually only necessary in server applications, where remote clients must find the server at an agreed upon port number.

If the compilation switch

     #define BSD44_SOCKET_API_STYLE

is set as a global define in the user application prior to including the Beck C-library header files, the bind() call can be used in BSD 4.4 compatible style with the parameters specified above.   Using this switch the C-Library TCPIP_Socket.H header file redefines bind() to bind_bsd() .

The caller must fill in the sockaddr_in (IPv4) or sockaddr_in6 (IPv6) 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 = 0 ;

addr.sin_family = PF_INET ;
addr.sin_addr.s_addr =  0 ;
addr.sin_port = htons(ClientPort);   // Network byte order
if (bind_bsd ( sd,
              (const struct sockaddr *)&addr,
               sizeof(struct sockaddr_in)) != 0)
{
    error_code = get_socketerror(sd) ;
}

See Also

RTOS API

On the first call, this library function invokes a software interrupt which modifies the code at the calling site inside your application program.   A direct FAR JMP into the @CHIP-RTOS-x86 implementation for this function is installed so that on return and on any subsequent calls to this API this dynamic link reaches the function's implementation directly.

Supported since or modified in @CHIP-RTOS version

    SC12SC13SC11SC1x3SC2x
    n/an/an/aV1.36V1.36

Supported by @CHIP-RTOS C Library since version

    CLIB
    V2.20

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


End of document