.dsy:it.
Show 150 posts per page

.dsy:it. (http://www.dsy.it/forum/)
- Reti di calcolatori (http://www.dsy.it/forum/forumdisplay.php?forumid=68)
-- esame laboratorio socket (http://www.dsy.it/forum/showthread.php?threadid=42622)


Posted by fofo on 24-01-2012 21:14:

esame laboratorio socket

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?


Posted by CowBoy on 25-01-2012 12:16:

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);

__________________
.. ±·ø·±-`` MuSiC iS My LanGuAGe ´´-±·ø·± ..


Posted by fofo on 25-01-2012 16:56:

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...


Posted by fofo on 25-01-2012 20:12:

PERFETTO FUNZIONA ....GRAZIE TANTE...AVEVO PROVATO VON getnameinfo ma era un casino...ora bisogna implementare i server...speriamo di riuscirci


All times are GMT. The time now is 02:11.
Show all 4 posts from this thread on one page

Powered by: vBulletin Version 2.3.1
Copyright © Jelsoft Enterprises Limited 2000 - 2002.