www.beck-ipc.com

@CHIP-RTOS C Library - TCP/IP API


connect

Connect to another socket.

int connect ( 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 containing host's IP address and port number.

error

Output parameter:  Failure code, 0 on success.

Return Value

0 = success
Non-zero = Failure (see error output parameter)

Comments

The caller must fill in the sockaddr_in (IPv4) or sockaddr_in6 (IPv6, SC1x3/SC2x only! ) data structure at addressPtr prior to calling here.   An example of how this normally would be done follows.   The PF_INET setting for the sin_family is required for IPv4.   For IPv6 set sin6_family to PF_INET6.

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 or sockaddr_in6 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 connect() specified here is not compatible to the BSD 4.4 Socket API.   The connect() 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 connect() to connect_bsd().  The parameters to connect_bsd() are identical to the parameters of the BSD4.4 socket connect() function.

            
// Example
char szHostIPStr[] = "172.30.1.68" ;
int HostPort = 4000 ;
struct sockaddr_in addr ;
int result,error_code ;

addr.sin_family = PF_INET ;
addr.sin_addr.s_addr =  0 ;
addr.sin_port = htons (HostPort) ;   // convert byte order

// convert server IP address string to binary
inet_addr (szHostIPStr, &addr.sin_addr.s_addr);
// establish a connection to the server
result = connect (sd, (const struct sockaddr far *)&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

    SC12SC13SC11SC1x3SC2x
    V1.00V1.00V1.00V0.90V1.00

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


End of document