@CHIP-RTOS C Library - TCP/IP API
connect_bsd
Connect to another socket. int far connect_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 specifying host's IP
address and port number.
addressLength
- Length of object at addressPtr in bytes.
Return Value
- 0 on success
-1: Failure, error code is available using
get_socketerror.
Comments
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 connect()
call can be used in
BSD 4.4 compatible style with the parameters specified above.
Using this switch the CLIB TCPIP_Socket.H redefines connect()
to connect_bsd()
.
The caller must fill in the
sockaddr_in (IPv4) or
sockaddr_in6
(IPv6) 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 = 0 ;
// Convert server IP address string to binary.
// (In network byte order)
addr.sin_addr.s_addr = inet_addr_bsd (szHostIPStr) ;
addr.sin_port = htons (HostPort) ; // Network byte order
addr.sin_family = PF_INET ; // IPv4 protocol
// Establish a connection to the server.
if ( connect_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-
| SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
| n/a | n/a | n/a | V1.36 | V1.36 |
Supported by @CHIP-RTOS C Library since version
This API List
List of C Libraries
@CHIP-RTOS Main Index
End of document
|