lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 | #include <stdlib.h>
|
| 3 | #include <string.h>
|
| 4 | #include <netdb.h>
|
| 5 | #include <arpa/inet.h>
|
| 6 | #include <ares.h>
|
| 7 | #include <sys/time.h>
|
| 8 | #include <fcntl.h>
|
| 9 | int dns_with_cid(char *name, int cid, int family)
|
| 10 | {
|
| 11 | struct hostent *host = NULL;
|
| 12 | char *dev = malloc(10);
|
| 13 | char num[3] = "";
|
| 14 | char *ptr, **pptr;
|
| 15 | char str[30];
|
| 16 | memset(dev, 0, 10);
|
| 17 | sc_cfg_get("pswan", dev, 10);
|
| 18 | sprintf(num, "%d", cid);
|
| 19 | strcat(dev, num);
|
| 20 | printf("dev : %s\n", dev);
|
| 21 | host = compat_gethostbyname3(name, dev, family);
|
| 22 | if(host != NULL){
|
| 23 | printf("host->h_name = %s\n", host->h_name);
|
| 24 | if(host->h_aliases){
|
| 25 | for(pptr = host->h_aliases; *pptr != NULL; pptr++)
|
| 26 | printf("\talias:%s\n", *pptr);
|
| 27 | }
|
| 28 | else
|
| 29 | printf("no aliase\n");
|
| 30 | if(host->h_addrtype){
|
| 31 | switch(host->h_addrtype){
|
| 32 | case AF_INET:
|
| 33 | pptr = host->h_addr_list;
|
| 34 | for(; *pptr != NULL; pptr++)
|
| 35 | printf("\t address: %s \n", inet_ntop(AF_INET, *pptr, str, sizeof(str)));
|
| 36 | break;
|
| 37 | }
|
| 38 | }else {
|
| 39 | printf("no h_addr_list\n");
|
| 40 | }
|
| 41 | free_hostent(host);
|
| 42 | }
|
| 43 | return 1;
|
| 44 | }
|
| 45 | int main(int argc, char **argv)
|
| 46 | {
|
| 47 | char *dev = malloc(5);
|
| 48 | char name[20] = "www.baidu.com";
|
| 49 | dns_with_cid(name, 1, AF_INET);
|
| 50 | return 0;
|
| 51 | }
|