i meet a question.
i don't know how to use
struct hostent *gethostby(const void *addr, size_t length, int type)
function to get remote computer hostent struct information.
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
struct hostent *hp;
char *ip;
in_addr_t data;
if (argc = 2) {
ip = argv[1];
data = inet_addr(ip);
hp = gethostbyaddr(&data, 4, AF_INET);
if (hp == NULL) {
printf("Unknown host\n");
exit(1);
}//why did i always get hp = NULL;
else {
printf("get remote computer hostent");
}
}
else printf("argv error");
}
can you give me a example?
thanks a lot!!