1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
int can_resolve_host (const char *host)
{
struct hostent *h = NULL;
h = gethostbyname (host);
if (h == NULL)
{
return -1;
}
else
{
return 0;
}
}
int main(int argc, char **argv)
{
if (can_resolve_host ("google.com") == -1)
{
printf ("Failed to reach google.com\n");
}
else
{
printf ("Successfully reached google.com\n");
}
return 0;
} |