#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <netdb.h> | |
#include <arpa/inet.h> | |
#include <ares.h> | |
#include <sys/time.h> | |
#include <fcntl.h> | |
int dns_with_cid(char *name, int cid, int family) | |
{ | |
struct hostent *host = NULL; | |
char *dev = malloc(10); | |
char num[3] = ""; | |
char *ptr, **pptr; | |
char str[30]; | |
memset(dev, 0, 10); | |
sc_cfg_get("pswan", dev, 10); | |
sprintf(num, "%d", cid); | |
strcat(dev, num); | |
printf("dev : %s\n", dev); | |
host = compat_gethostbyname3(name, dev, family); | |
if(host != NULL){ | |
printf("host->h_name = %s\n", host->h_name); | |
if(host->h_aliases){ | |
for(pptr = host->h_aliases; *pptr != NULL; pptr++) | |
printf("\talias:%s\n", *pptr); | |
} | |
else | |
printf("no aliase\n"); | |
if(host->h_addrtype){ | |
switch(host->h_addrtype){ | |
case AF_INET: | |
pptr = host->h_addr_list; | |
for(; *pptr != NULL; pptr++) | |
printf("\t address: %s \n", inet_ntop(AF_INET, *pptr, str, sizeof(str))); | |
break; | |
} | |
}else { | |
printf("no h_addr_list\n"); | |
} | |
free_hostent(host); | |
} | |
return 1; | |
} | |
int main(int argc, char **argv) | |
{ | |
char *dev = malloc(5); | |
char name[20] = "www.baidu.com"; | |
dns_with_cid(name, 1, AF_INET); | |
return 0; | |
} |