소스 검색

优化udhcpc参数

guohui 1 년 전
부모
커밋
04ade39b72
1개의 변경된 파일과 18개의 추가작업 그리고 4개의 파일을 삭제
  1. 18 4
      pro/src/wifi.c

+ 18 - 4
pro/src/wifi.c

@@ -93,13 +93,25 @@ static void res_free(result_t *res)
         }
     }
 }
+static int udhcpc_start(int on)
+{
+    char tmp[200],path[100];
+
+    sprintf(path, "/var/run/udhcpc_%s.pid", WLAN_IFNAME);
+    if(on) {
+        sprintf(tmp, "udhcpc -R -b -t 1 -A 1 -i %s -p %s", WLAN_IFNAME, path);
+    }
+    else {
+        sprintf(tmp, "kill $(cat %s)", path);
+    }
+    return system(tmp);
+}
 static int sta_start(ap_info_t *info, int on)
 {
     int r,ipv,mask=24;
     char tmp[400],txt[200];
     
     //https://www.cnblogs.com/lidabo/p/5076560.html
-    r = system("killall wpa_supplicant");
     if(on) {
         snprintf(txt, sizeof(txt), "ctrl_interface=/var/run/wpa_supplicant\n"
                                "network={\n"
@@ -110,15 +122,17 @@ static int sta_start(ap_info_t *info, int on)
         sprintf(tmp, "echo '%s' > %s", txt, STA_CONF);
         r = system(tmp);
 
+        r = system("killall wpa_supplicant");
+
         sprintf(tmp, "wpa_supplicant -B -i %s -c %s", WLAN_IFNAME, STA_CONF);
         r = system(tmp);
 
-        sprintf(tmp, "udhcpc -R -b -i %s", WLAN_IFNAME);
-        r = system(tmp);
+        r = udhcpc_start(1);
     }
     else {
         r = system("wpa_cli disconnect");
-        r = system("killall wpa_supplicant udhcpc");
+        r = system("killall wpa_supplicant");
+        r = udhcpc_start(0);
     }
 
     return r;