|
|
@@ -24,6 +24,8 @@
|
|
|
#endif
|
|
|
|
|
|
|
|
|
+//#define USE_IPV6
|
|
|
+
|
|
|
//#define USE_BASH
|
|
|
#define USE_FILE
|
|
|
//#define USE_API
|
|
|
@@ -426,22 +428,30 @@ finish:
|
|
|
#endif
|
|
|
|
|
|
return 0;
|
|
|
-
|
|
|
}
|
|
|
static int set_dhcp(int on)
|
|
|
{
|
|
|
if(on) {
|
|
|
- system("udhcpc –i eth0 –s /usr/share/udhcpc/default.script");
|
|
|
+ system("killall udhcpc && udhcpc –i eth0 –s /usr/share/udhcpc/default.script &");
|
|
|
}
|
|
|
else {
|
|
|
system("killall udhcpc");
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
+static int is_number(char *str)
|
|
|
+{
|
|
|
+ while (*str) {
|
|
|
+ if (!isdigit(*str)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ str++;
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+}
|
|
|
static int ip_check(char* addr)
|
|
|
{
|
|
|
- int flag = IP_ERR;
|
|
|
+ int flag=IP_ERR;
|
|
|
struct in_addr addr4;
|
|
|
struct in6_addr addr6;
|
|
|
|
|
|
@@ -450,6 +460,15 @@ static int ip_check(char* addr)
|
|
|
} else if (inet_pton(AF_INET6, addr, &addr6) == 1) {
|
|
|
flag = IP_V6;
|
|
|
} else {
|
|
|
+ if(is_number(addr)) {
|
|
|
+ int val = atoi(addr);
|
|
|
+ if(val>1 && val<128) {
|
|
|
+ flag = IP_V6;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(flag==IP_ERR) {
|
|
|
LOGE("____ wrong ip addr: %s\n", addr);
|
|
|
}
|
|
|
|
|
|
@@ -501,7 +520,7 @@ static int file_load(char* path, file_data_t *fdat)
|
|
|
|
|
|
flen = file_length(path);
|
|
|
if(flen<=0) {
|
|
|
- LOGE("____ file_load, %s length is wrong\n", path);
|
|
|
+ LOGE("____ file_load, %s failed\n", path);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -675,7 +694,10 @@ static int set_dns(char *dns1, char *dns2)
|
|
|
snprintf(buf, sizeof(buf), "interface=eth0\nserver=%s\nserver=%s\n", dns1, dns2);
|
|
|
r = file_save(FILE_DNS, buf, strlen(buf))+1;
|
|
|
if(r==0) {
|
|
|
- r = system("/etc/init.d/dnsmasq restart");
|
|
|
+ r = system("killall dnsmasq; /usr/sbin/dnsmasq &");
|
|
|
+ if(r) {
|
|
|
+ LOGE("___ dnsmasq start failed\n");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return r;
|
|
|
@@ -726,7 +748,6 @@ static int get_net(NetworkInfo_t *para, int ipv)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
static int set_net(NetworkInfo_t *para, int ipv)
|
|
|
{
|
|
|
int r,ipv2;
|
|
|
@@ -780,12 +801,17 @@ static int set_net(NetworkInfo_t *para, int ipv)
|
|
|
char *eth1="auto eth1\niface eth1 inet dhcp\npre-up /etc/network/nfs_check\nwait-delay 5\nhostname $(hostname)\n";
|
|
|
char eth0[1000];
|
|
|
|
|
|
+#ifdef USE_IPV6
|
|
|
snprintf(eth0, sizeof(eth0), "auto eth0\n"
|
|
|
"iface eth0 inet %s\n address %s\n netmask %s\n gateway %s\n\n"
|
|
|
"iface eth0 inet6 %s\n address %s\n netmask %s\n gateway %s\n\n",
|
|
|
(info4.mode==IP_STATIC)?"static":"dhcp", info4.ip_address, info4.mask, info4.gateway,
|
|
|
(info6.mode==IP_STATIC)?"static":"dhcp", info6.ip_address, info6.mask, info6.gateway);
|
|
|
-
|
|
|
+#else
|
|
|
+ snprintf(eth0, sizeof(eth0), "auto eth0\n"
|
|
|
+ "iface eth0 inet %s\n address %s\n netmask %s\n gateway %s\n\n",
|
|
|
+ (info4.mode==IP_STATIC)?"static":"dhcp", info4.ip_address, info4.mask, info4.gateway);
|
|
|
+#endif
|
|
|
sprintf(fbuf, "%s%s%s", lo, eth0, eth1);
|
|
|
#endif
|
|
|
//LOGD("___interfaces___:\n%s", fbuf);
|
|
|
@@ -797,9 +823,6 @@ static int set_net(NetworkInfo_t *para, int ipv)
|
|
|
free(fbuf);
|
|
|
|
|
|
r = set_dns(para->dns1, para->dns2);
|
|
|
- if(r) {
|
|
|
- LOGE("___ set_dns failed\n");
|
|
|
- }
|
|
|
|
|
|
return r;
|
|
|
}
|