1#ifndef _SH_H 2#define _SH_H 3 4#pragma pack(1) 5 6#include <sys/types.h> 7#include <sys/socket.h> 8#include <netinet/in.h> 9#include <arpa/inet.h> 10#include <sys/stat.h> 11#include <sys/time.h> 12#include <sys/select.h> 13#include <sys/resource.h> 14#include <sys/wait.h> 15#include <sys/ioctl.h> 16#include <unistd.h> 17#include <stdio.h> 18#include <string.h> 19#include <stdlib.h> 20#include <errno.h> 21#include <signal.h> 22#include <dirent.h> 23#include <fcntl.h> 24#include <netdb.h> 25#include <time.h> 26#include <syslog.h> 27#include <sys/param.h> // for the variable, NOFILE 28#include <stdarg.h> // 2008.02 James. 29 30#define socklen_t int 31#include <net/if.h> 32#include <shutils.h> 33#include <ethtool-util.h> 34#include <bcmnvram.h> 35 36#ifndef SIOCETHTOOL 37#define SIOCETHTOOL 0x8946 38#endif 39 40#ifndef SIOCGIFADDR 41#define SIOCGIFADDR 0x8915 42#endif 43 44#ifndef SIOCGETCPHYRD 45#define SIOCGETCPHYRD 0x89FE 46#endif 47 48#define MAXLINE 2048 49#define PATHLEN 256 50#define STRLEN 256 51//#define HOSTLEN 64 52#define DFL_HTTP_SERV_PORT "18017" 53#define DFL_DNS_SERV_PORT "18018" 54#define MAX_USER 100 55 56#define GET 'g' 57#define POST 'p' 58 59#define T_HTTP 'H' 60#define T_DNS 'D' 61 62#define DISCONN 0 63#define CONNED 1 64#define C2D 3 65#define D2C 4 66 67#define CASE_DISWAN 1 68#define CASE_PPPFAIL 2 69#define CASE_DHCPFAIL 3 70#define CASE_MISROUTE 4 71#define CASE_OTHERS 5 72#define CASE_THESAMENET 6 73 74#define OK_STR "Content-Type: text/html\r\n" 75 76typedef struct Flags_Pack{ 77 uint16_t reply_1:4, // bit:0-3 78 non_auth_ok:1, // bit:4 79 answer_auth:1, // bit:5 80 reserved:1, // bit:6 81 recur_avail:1, // bit:7 82 recur_desired:1, // bit:8 83 truncated:1, // bit:9 84 authori:1, // bit:10 85 opcode:4, // bit:11-14 86 response:1; // bit:15 87} flag_pack; 88 89typedef struct DNS_HEADER{ 90 uint16_t tid; 91 union { 92 uint16_t flag_num; 93 flag_pack flags; 94 } flag_set; 95 uint16_t questions; 96 uint16_t answer_rrs; 97 uint16_t auth_rrs; 98 uint16_t additional_rss; 99} dns_header; 100 101typedef struct QUERIES{ 102 char name[PATHLEN]; 103 uint16_t type; 104 uint16_t ip_class; 105} dns_queries; 106 107typedef struct ANSWER{ 108 uint16_t name; 109 uint16_t type; 110 uint16_t ip_class; 111 uint32_t ttl; // time to live 112 uint16_t data_len; 113 uint32_t addr; 114} dns_answer; 115 116typedef struct DNS_REQUEST{ 117 dns_header header; 118 dns_queries queries; 119} dns_query_packet; 120 121typedef struct DNS_RESPONSE{ 122 dns_header header; 123 char *q_name; 124 uint16_t q_type; 125 uint16_t q_class; 126 dns_answer answers; 127} dns_response_packet; 128 129typedef struct REQCLIENT{ 130 int sfd; 131 char type; 132} clients; 133 134// var 135int http_sock, dns_sock, maxfd; 136clients client[MAX_USER]; 137fd_set rset, allset; 138int fd_i; 139int cur_sockfd, main_pid, connfd, rule_setup, nat_enable; 140char dst_url[256]; 141int disconn_case; 142int err_state; 143//bool is_wsc_configed; 144bool isFirstUse; 145#define NAT_FILE "/tmp/nat_rules" 146#define REDIRECT_FILE "/tmp/redirect_rules" 147#define DEL_REDIRECT_FILE "/tmp/del_redirect_rules" 148char *add_command[] = {"iptables-restore", REDIRECT_FILE, NULL}; 149char *del_command[] = {"iptables-restore", NAT_FILE, NULL}; 150char *del_command2[] = {"iptables-restore", DEL_REDIRECT_FILE, NULL}; 151 152int Dr_Surf_case = 0; // 2008.02 James. 153 154int wan_ready = 0; 155char wan_pppoe_relay_x[2]; // 2009.08 James. 156int wan_unit = 0; 157char wan0_ifname[16]; 158char wan1_ifname[16]; 159char wan0_proto[16]; 160char wan1_proto[16]; 161char wan_gateway_t[16]; 162char wan_ipaddr_t[16]; 163char wan_netmask_t[16]; 164unsigned int wan_subnet; 165char lan_ipaddr_t[16]; 166char lan_netmask_t[16]; 167unsigned int lan_subnet; 168 169// func 170void change_redirect_rules(int num); 171void run_http_serv(int); 172void run_dns_serv(int); 173int readline(int, char*, int); 174void handle_http_req(int, char*); 175void handle_dns_req(int, char*, int n, struct sockaddr*, int); 176void send_page(int, char*, char *); 177int if_wan_phyconnected(); 178// 2007.11 James { 179void build_rule_file(); 180int build_socket(char *http_port, char *dns_port, int *hd, int *dd); 181void record_conn_status(); 182void logmessage(char *logheader, char *fmt, ...); 183void get_related_nvram(); 184void get_related_nvram2(); 185// 2007.11 James } 186#endif 187