#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char *argv[])
{
char tmphstbuf [4096];
size_t hstbuflen = sizeof (tmphstbuf);
struct hostent hostinfo_buf = {0,};
struct hostent *hostresult = NULL;
int herr ;
int ret = -1 ;
size_t len;
char ip_addr[INET6_ADDRSTRLEN] = {0,};
struct sockaddr_in6 addr;
len = sizeof(tmphstbuf);
ret = gethostbyname_r(argv[1], &hostinfo_buf, tmphstbuf, len, &hostresult, &herr);
printf("Addresses:\t");
inet_ntop(AF_INET6, hostinfo_buf.h_addr_list[0], ip_addr, INET6_ADDRSTRLEN);
printf("%s\n", ip_addr);
}
/* Keep add your hostnames in /etc/hosts file */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char *argv[])
{
char tmphstbuf [4096];
size_t hstbuflen = sizeof (tmphstbuf);
struct hostent hostinfo_buf = {0,};
struct hostent *hostresult = NULL;
int herr ;
int ret = -1 ;
size_t len;
char ip_addr[INET6_ADDRSTRLEN] = {0,};
struct sockaddr_in6 addr;
len = sizeof(tmphstbuf);
ret = gethostbyname_r(argv[1], &hostinfo_buf, tmphstbuf, len, &hostresult, &herr);
printf("Addresses:\t");
inet_ntop(AF_INET6, hostinfo_buf.h_addr_list[0], ip_addr, INET6_ADDRSTRLEN);
printf("%s\n", ip_addr);
}
/* Keep add your hostnames in /etc/hosts file */
No comments:
Post a Comment