i need a C program which gets hostname as the input and prints the IP address of that hostname.
(Hostname's IP addresses will be given using a seperate file in define.....
just guide me with respect to this...
thanks....
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
struct hostent *he;
struct in_addr a;
int
main (int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "usage: %s hostname\n", argv[0]);
return 1;
}
he = gethostbyname (argv[1]);
if (he)
{
printf("name: %s\n", he->h_name);
while (*he->h_aliases)
printf("alias: %s\n", *he->h_aliases++);
while (*he->h_addr_list)
{
bcopy(*he->h_addr_list++, (char *) &a, sizeof(a));
printf("address: %s\n", inet_ntoa(a));
}
}
else
herror(argv[0]);
return 0;
}
can any one please explain me this program....
struct hostent *he;
struct in_addr a;
what these two structures are? waht they will do?