Ho trovato la risposta, magari qualcuno ne avesse bisogno. Il codice per rilevare la connessione è il seguente:
codice:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
//"in" per "sockaddr_in"
#include <netinet/in.h>
//"netdb" per "gethostbyname"
#include <netdb.h>
//#include "main.h"
void ChiudiSocket(int sock){
close(sock);
return;
}
int CreaSocket(char* Destinazione, int Porta){
struct sockaddr_in temp;
struct hostent *h;
int sock;
int errore;
//Tipo di indirizzo
temp.sin_family=AF_INET;
temp.sin_port=htons(Porta);
h=gethostbyname(Destinazione);
if (h==0){
printf("Gethostbyname fallito\n");
return -1;
}
printf("Gethostbyname Eseguito\n");
bcopy(h->h_addr,&temp.sin_addr,h->h_length);
//Creazione socket.
sock=socket(AF_INET,SOCK_STREAM,0);
//Connessione del socket. Esaminare errore per compiere relative azioni.
errore=connect(sock, (struct sockaddr*) &temp, sizeof(temp));
if (errore!=0){printf("Errore Ricevuto n: %d\n",errore);}
else {printf("Connessione presente\n");}
//Chiudo il socket.
ChiudiSocket(sock);
return errore;
}
int verificaSocket(){
int errore=0;
//Creo e connetto il socket
errore=CreaSocket("208.69.34.231",80); //www.google.it
return errore;
}
se qualcuno vuole migliorare questo codice è sempre gradito...comunque funziona!