Explorar o código

解决网络设置的bug

guohui %!s(int64=2) %!d(string=hai) anos
pai
achega
650d4706e3

+ 15 - 5
04-软件设计及源码/03-核心板/V1.0/05.src/smart_pdu/src/sys.c

@@ -730,13 +730,14 @@ static int set_net(NetworkInfo_t *para)
     if(ip_check(para->gateway) && strcmp(para->gateway, para2.gateway)) {
         strcpy(para2.gateway, para->gateway);
     }
-    
-    int flen=file_length(fpath);
+ 
     char *fbuf=malloc(xlen);
     if(!fbuf) {
-        LOGE("___ malloc %d failed\n", flen);
+        LOGE("___ malloc %d failed\n", xlen);
         return -1;
     }
+
+#if 0
     file_load(fpath, fbuf, flen);
     fbuf[flen] = 0;
 
@@ -747,11 +748,20 @@ static int set_net(NetworkInfo_t *para)
                               para2.mode?"static":"dhcp", para2.ip_address, para2.mask, para2.gateway);
     strcpy(fbuf, pNet->lo);
     strcat(fbuf, pNet->e0);
-    strcat(fbuf, pNet->e1);
+    strcat(fbuf, pNet->e1);  
+#else
+    char *lo="auto lo\niface lo inet loopback\n\n";
+    char *eth1="auto eth1\niface eth1 inet dhcp\npre-up /etc/network/nfs_check\nwait-delay 5\nhostname $(hostname)\n";
+    char eth0[500];
+
+    snprintf(eth0, sizeof(eth0), "auto eth0\niface eth0 inet %s\n  address %s\n  netmask %s\n  gateway %s\n\n", 
+             para2.mode?"static":"dhcp", para2.ip_address, para2.mask, para2.gateway);
 
+    sprintf(fbuf, "%s%s%s", lo, eth0, eth1);
+#endif
+    //LOGD("___interfaces___:\n%s", fbuf);
     r = file_save(fpath, fbuf, strlen(fbuf));
     free(fbuf);
-
     if(r==0) {
         paras_get()->dev._network_info = para2;
     }