library "speciale" ?!?!?!?!?!?!?!?!
non è mica winsock2 !
è tutto già a disposizione nel kernel, usa il comando man:
> man socket
> man gethostbyname
se usi il kde, digita l'url man:/ nella location bar.
comunque:
codice:
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
...
// cerca l'host
struct in_addr host;
struct hostent* ip = gethostbyname("www.html.it");
host.s_addr=*(int*)(ip->h_addr);
// crea il socket
int sock = socket(AF_INET,SOCK_STREAM,0);
// lo connette all'host
struct sockaddr_in sai;
sai.sin_family=PF_INET;
sai.sin_port=htons(((short)80));
memcpy(&sai.sin_addr,host,sizeof(*host));
connect(sock,(struct sockaddr*)&sai,sizeof(sai));
// il gioco è fatto:
FILE* fp = fdopen(sock, "rw");
// manda un comando HTTP
fprintf(fp, "HEAD / HTTP/1.1\r\n\r\n");
// legge la risposta
char buf[255];
do
{
fgets(buf, 255, fp);
printf("%s", buf);
}
while(buf[0] != '\r');
// chiude
fclose(fp);
naturalmente non è testato...
ciao