#include <stdio.h> #include <netdb.h> #include <string.h> #include <netinet/in.h> #include <arpa/inet.h> int add_white_ip_address(char * domain){ int i = 0; struct hostent *he; struct in_addr *h_addr; char ip_addr[64] = {0}; if ( !domain ) return -1; he = gethostbyname(domain); if (he == NULL) { return 0; } while (he->h_addr_list[i] != 0) { memset(ip_addr,0x0,sizeof(ip_addr)); strcpy(ip_addr,inet_ntoa(*(struct in_addr *)he->h_addr_list[i])); printf("%s[%d] = %s\n",domain,i,ip_addr); i++; } return 1; } int iptables_fw_init(void) { char * p = NULL; //char *p_white_domain_list = nvram_safe_get("white_domain_list"); char *p_white_domain_list = "www.baidu.com;www.sina.com.cn;www.csdn.net;www.126.com;www.kuaiwifi.com"; char white_domain_list_buf[512] = {0}; struct in_addr *parse_addr; if (p_white_domain_list) { strcpy(white_domain_list_buf,p_white_domain_list); p = strtok(white_domain_list_buf,";"); if ( p ) { printf("p=%s\n",p); add_white_ip_address(p); while ((p = strtok(NULL,";")) != NULL) { printf("p = %s\n",p); add_white_ip_address(p); } } } } int main() { //add_white_ip_address("www.baidu.com"); iptables_fw_init(); return 0; }
原文地址:http://blog.csdn.net/dxt1107/article/details/46503521