Hello,
My program should connect to a server. here's the code :
int main(int argc, char *argv[]){
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock == -1){
perror("socket()");
exit(errno);
}
printf("retour socket = %d",sock);
struct sockaddr *ad;
ad = (struct sockaddr *)malloc(sizeof(struct sockaddr));
ad->sa_len = strlen("172.16.192.1");
ad->sa_family = AF_INET;
strlcpy(ad->sa_data, "172.16.192.1", strlen("172.16.192.1"));
int ret = connect(sock, (struct sockaddr *)&ad, sizeof(ad));
printf("retour connect = %d",ret);
if(ret == -1){
perror("socket()");
exit(errno);
}
return 0;
}
the program answers :
socket(): No route to host
or socket() connection timeout
in both cases socket() returns the integer 3 and connect() returns -1
I must say i have no issue with ping traceroute or even telnet.
so i really dont understant what's happening.
thank you