kern_soconnect Kernel Service

Purpose

Establishes a connection to a foreign address.

Syntax

#include <sys/kern_socket.h>
int kern_soconnect( ksocket_t  so, struct sockaddr *faddr )

Parameters

Item Description
so The socket that was created by socreate().
faddr Foreign address to connect.

Description

The kern_soconnect kernel service establishes connection with a foreign address.

Execution Environment

The kern_soconnect kernel service can be called from the process environment.

Examples

ksocket_t   so;
struct sockaddr_in faddr;
int		     rc;
rc = kern_socreate(AF_INET, &so, SOCK_STREAM, IPPROTO_TCP);
if (rc != 0 )  		 
{ 		 		 
			return(-1); 		 
}		   		 
bzero(&faddr, sizeof(struct sockaddr_in));
faddr.sin_family = AF_INET;
faddr.sin_port = 23456; 		 
faddr.sin_len = sizeof(struct sockaddr_in); 		 
faddr.sin_addr.s_addr = inet_addr("9.3.108.210"); 		 
rc = kern_soconnect(so, (struct sockaddr *) &faddr); 		 
if (rc != 0 )  		 
{ 		 		 
			return(-1);
}		 	 

Return Values

Item Description
0 Upon Success
>0 Error

The nonzero return value is the error number that is defined in the /usr/include/sys/errno.h file.