esame laboratorio socket Clicca QUI per vedere il messaggio nel forum |
fofo |
ragazzi sto provando a fare il comando nslookup...do l'host name e con getaddrinfo riesco a trovare l'ip...ma x fare il contrario?!
if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0)
{
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
return 2;
}
printf("IP addresses for %s:\n\n", argv[1]);
for(p = res;p != NULL; p = p->ai_next)
{
void *addr;
char *ipver;
char *s,*host;
// si ottiene il puntatore all’indirizzo stesso,
// facendo attenzione ai diversi campi in IPv4 e IPv6:
if (p->ai_family == AF_INET)
{ // IPv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
s=p->ai_canonname;
addr = &(ipv4->sin_addr);
ipver = "IPv4";
in s avrò l'ip ma io vorrei fare anche il contrario sapete come si fa? |
CowBoy |
Prova a dare un'occhiata qua: http://www.gsp.com/cgi-bin/man.cgi?...c=gethostbyaddr
EXAMPLES
Print out the hostname associated with a specific IP address:
const char *ipstr = "127.0.0.1";
struct in_addr ip;
struct hostent *hp;
if (!inet_aton(ipstr, &ip))
errx(1, "can’t parse IP address %s", ipstr);
if ((hp = gethostbyaddr((const void *)&ip,
sizeof ip, AF_INET)) == NULL)
errx(1, "no name associated with %s", ipstr);
printf("name associated with %s is %s\n", ipstr, hp->h_name);
|
fofo |
grazie avevo intenzione di utilizzare la struttura hostent....non sappiamo ancora comìè andato lo scritto e nn credo per ora di scrivere da zero un codice per un banale client o server....io mi sento nella merda... |
fofo |
PERFETTO FUNZIONA ....GRAZIE TANTE...AVEVO PROVATO VON getnameinfo ma era un casino...ora bisogna implementare i server...speriamo di riuscirci |
|
|
|