www.beck-ipc.com

@CHIP-RTOS C Library V2.00 - TCP/IP API


bind

Bind an unnamed socket to an address and port number.

int bind ( int sd, const struct sockaddr_in far *addressPtr,
           int *error );

Parameters

sd

Socket descriptor.

addressPtr

Pointer to a sockaddr_in structure (see tcpipapi.h) 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 sockaddr_in structure at addressPtr must be filled in by the caller prior to making this API call.  An example of how this can be done follows.

// Example
int ClientPort = 3000 ;
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, &addr ) ;

See Also

RTOS API

This library function invokes a RTOS software interrupt. Refer to this RTOS API function's documentation for more details.


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


End of document