In the Router Portal Authentication module, the pre-authentication user is not able to surf the Internet through the router, but can access the specified domain name,
The Portal authentication module needs to release the IP address of the authentication server, domain name corresponding IP may be multiple, the following program to simulate domain name resolution to obtain multiple IP addresses.
#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[6 4] = {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]);p rintf ("%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;}
Portal Authentication Server Whitelist