@CHIP-RTOS C Library V2.06 - 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, SC123/SC143 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, SC123/SC143 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".
| // Example
char szHostIPStr[] = "172.30.1.68" ;
int HostPort = 4000 ;
struct sockaddr_in addr ;
int 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
error_code = connect (sd, (const struct sockaddr far *)&addr) ; |
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 |
-
V1.00 | V1.00 | V1.00 | V0.90 |
This API List
List of C Libraries
@CHIP-RTOS Main Index
End of document
|