|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Dec 2006
Città: Firenze
Messaggi: 118
|
[C/C++] Host>IP
Come faccio a ottenere da un host un ip? gethostbyaddr?
__________________
Federica |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Se parti da un hostname, gethostbyname()
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Dec 2006
Città: Firenze
Messaggi: 118
|
Perchè da che parti con gethostbyaddr?
Cmq come glieli devo passare i valori? perchè se metto "ciao.it" mi dice: "cannot convert `hostent*' to `const char*' for argument `1' to `long unsigned int inet_addr(const char*)' "
__________________
Federica Ultima modifica di Fede_Reghe : 27-03-2007 alle 20:56. |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
Codice:
#include <stdio.h>
#include <netdb.h>
int main (void)
{
struct hostent *he;
he = gethostbyname ("www.hwupgrade.it");
if (he != NULL)
{
int i;
for (i=0; i<he->h_length; i++)
printf (i > 0 ? ".%d" : "%d", he->h_addr_list[0][i] & 255);
printf ("\n");
}
return 0;
}
Su Windows sicuramente c'è da cambiare l'include.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 21:28.




















