|
|
@@ -24,7 +24,7 @@
|
|
|
#endif
|
|
|
|
|
|
|
|
|
-//#define USE_IPV6
|
|
|
+#define USE_IPV6
|
|
|
|
|
|
//#define USE_BASH
|
|
|
#define USE_FILE
|
|
|
@@ -490,60 +490,29 @@ typedef struct {
|
|
|
int len;
|
|
|
}nic_t;
|
|
|
|
|
|
-static char* find_str(char *buf, char *head, char *tail, char *nic)
|
|
|
-{
|
|
|
- int len;
|
|
|
- char *p,*p1,*p2,*ptr=NULL;
|
|
|
-
|
|
|
- p1 = strstr(buf, head);
|
|
|
- p2 = strstr(buf, tail);
|
|
|
- if(p1 && p2) {
|
|
|
- p1 = p1 + sizeof(head);
|
|
|
- len = XLEN(p2,p1);
|
|
|
- if(len>0) {
|
|
|
- p = malloc(len+1);
|
|
|
- if(p) {
|
|
|
- memcpy(p, p1, len); p[len] = 0;
|
|
|
- if(strstr(p, nic)) {
|
|
|
- ptr = p1;
|
|
|
- }
|
|
|
- free(p);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return ptr;
|
|
|
-}
|
|
|
+
|
|
|
static int get_nic(char *nbuf, int nlen, char *nic, char *fbuf, int flen)
|
|
|
{
|
|
|
- int r,len;
|
|
|
- char *p,*p1,*p2;
|
|
|
+ int r,xlen;
|
|
|
+ char tmp[20];
|
|
|
+ char *p1,*p2;
|
|
|
char *fend=fbuf+flen-1;
|
|
|
|
|
|
- p = fbuf;
|
|
|
- while(p<fend) {
|
|
|
- p1 = find_str(p, "auto", "\n", nic);
|
|
|
- if(p1) {
|
|
|
- p2 = strstr(p1+1, "auto");
|
|
|
- if(!p2) {
|
|
|
- p2 = fend;
|
|
|
- }
|
|
|
-
|
|
|
- len = XLEN(p2,p1);
|
|
|
- if(nlen>len) {
|
|
|
- memcpy(nbuf, p1, len);
|
|
|
- nbuf[len] = 0;
|
|
|
- //LOGD("__x__%s:\n %s\n", nic, nbuf);
|
|
|
-
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else {
|
|
|
- LOGD("___ nbuf is too small\n");
|
|
|
- }
|
|
|
- }
|
|
|
- p = p+1;
|
|
|
+ sprintf(tmp, "auto %s", nic);
|
|
|
+ p1 = strstr(fbuf, tmp);
|
|
|
+ if(!p1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ p2 = strstr(p1+1, "auto");
|
|
|
+ if(!p2 || p2>fend) {
|
|
|
+ p2 = fend;
|
|
|
}
|
|
|
|
|
|
- return -1;
|
|
|
+ xlen = XLEN(p2,p1);
|
|
|
+ memcpy(nbuf, p1, xlen);
|
|
|
+ nbuf[xlen] = 0;
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
static int get_ip(char *nbuf, char *token, char *ipaddr, int ipv)
|
|
|
{
|
|
|
@@ -564,7 +533,9 @@ static int get_ip(char *nbuf, char *token, char *ipaddr, int ipv)
|
|
|
|
|
|
p = strstr(pbuf, token);
|
|
|
if(p) {
|
|
|
- while(!isdigit(*p)) p++;
|
|
|
+ p += strlen(token);
|
|
|
+
|
|
|
+ while(isspace(*p)) p++;
|
|
|
p1 = p;
|
|
|
while(!isspace(*p)) p++;
|
|
|
p2 = p;
|
|
|
@@ -614,14 +585,19 @@ static int get_dns(char *nbuf, char *dns1, char *dns2)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int set_dns(char *dns1, char *dns2)
|
|
|
+static int set_dns(NetworkInfo_t *para)
|
|
|
{
|
|
|
int r;
|
|
|
- char buf[4000];
|
|
|
+ char buf[200];
|
|
|
|
|
|
LOGD("_____ set_dns\n");
|
|
|
+
|
|
|
+ if(strlen(para->dns1)==0 && strlen(para->dns2)==0) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
- snprintf(buf, sizeof(buf), "interface=eth0\nserver=%s\nserver=%s\n", dns1, dns2);
|
|
|
+ snprintf(buf, sizeof(buf), "interface=eth0\nserver=%s\nserver=%s\n", para->dns1, para->dns2);
|
|
|
r = file_save(FILE_DNS, buf, strlen(buf))+1;
|
|
|
if(r==0) {
|
|
|
system("killall dnsmasq; /usr/sbin/dnsmasq &");
|
|
|
@@ -743,16 +719,7 @@ static int set_net(NetworkInfo_t *para, int ipv)
|
|
|
#endif
|
|
|
//LOGD("___interfaces___:\n%s", fbuf);
|
|
|
|
|
|
- r = file_save(FILE_NET, fbuf, strlen(fbuf));
|
|
|
- if(r==0) {
|
|
|
- //system("ip addr flush dev eth0");
|
|
|
- //sprintf(eth0, "ip link set dev eth0 %s/%d && ip link set eth0 up && ip link set eth0 down", info->ip_address, info->netmask);
|
|
|
- //system(eth0);
|
|
|
- system("ifdown eth0 && ifup eth0");
|
|
|
- }
|
|
|
- free(fbuf);
|
|
|
-
|
|
|
- //set_dns(para->dns1, para->dns2);
|
|
|
+ r = file_save(FILE_NET, fbuf, strlen(fbuf)); free(fbuf);
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
@@ -801,7 +768,15 @@ int sys_set_net(NetworkInfo_t *para, int ipVersion)
|
|
|
LOGW("%s NetworkInfo is same, no need to set\n", DFLT_NIC);
|
|
|
return -1;
|
|
|
}
|
|
|
+ set_dns(para);
|
|
|
r = set_net(para, ipVersion);
|
|
|
+ if(r==0) {
|
|
|
+ //system("ip addr flush dev eth0");
|
|
|
+ //sprintf(eth0, "ip link set dev eth0 %s/%d && ip link set eth0 up && ip link set eth0 down", info->ip_address, info->netmask);
|
|
|
+ //system(eth0);
|
|
|
+ system("ifdown eth0 && ifup eth0");
|
|
|
+ if(ipVersion==IP_V6) exit(0);
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
LOGE("get_net failed\n");
|