[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Status of netcfg-static



Hello,

I am wondering what netcfg-static is good for. Looks like it is an (outdated)
subset of the more generic netcfg. Unfortunately, even the common code of the
two programs seem to have diverged over time (no wonder, duplicated code
almost always suffers from this disease).

Given that the netcfg/disable_dhcp option exists, is netcfg-static really
needed?

BTW: anybody sees how the GET_STATIC state in netcfg.c is supposed to work:

        case GET_STATIC:
            {
                int ret;
                /* Misnomer - this should actually take care of activation */
                if ((ret = netcfg_get_static(client)) == 10)
                    state = GET_INTERFACE;
                else if (ret)
                    state = GET_METHOD;
                else
                    state = QUIT;
                break;
            }

AFAICS, netcfg_get_static() never returns anything other than 0 or 10. So
the GET_METHOD state would never be set.


Here is a first attempt to bring those two programs in sync again. There are
more differences (especially in the GET_INTERFACE state), but I have not done
a closer look at them yet.


diff --git a/netcfg-static.c b/netcfg-static.c
index 1cd2799..3b9faca 100644
--- a/netcfg-static.c
+++ b/netcfg-static.c
@@ -1,7 +1,9 @@
 /* 
-   netcfg-static.c - Configure a static network for the debian-installer
+   netcfg-static.c - Configure a static network
+   for the debian-installer
 
    Copyright (C) 2000-2002  David Kimdon <dwhedon@debian.org>
+                            and others (see debian/copyright)
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,6 +20,7 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    
 */
+
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -27,13 +30,20 @@
 #include <debian-installer.h>
 #include "netcfg.h"
 
-int main(int argc, char** argv)
+int main(int argc, char *argv[])
 {
     int num_interfaces = 0;
     static struct debconfclient *client;
     static int requested_wireless_tools = 0;
     
-    enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT} state = GET_INTERFACE;
+    enum { BACKUP,
+           GET_INTERFACE,
+           GET_HOSTNAME_ONLY,
+           GET_STATIC,
+           WCONFIG,
+           WCONFIG_ESSID,
+           WCONFIG_WEP,
+           QUIT } state = GET_INTERFACE;
     
     /* initialize libd-i */
     di_system_init("netcfg-static");
@@ -46,7 +56,20 @@ int main(int argc, char** argv)
     client = debconfclient_new();
     debconf_capb(client, "backup");
     
-    while (1) {
+    /* Check to see if netcfg should be run at all */
+    debconf_get(client, "netcfg/enable");
+    if (!strcmp(client->value, "false")) {
+        struct in_addr null_ipaddress;
+        char *hostname = NULL;
+
+        null_ipaddress.s_addr = 0;
+        netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 0);
+
+        netcfg_write_common(null_ipaddress, hostname, NULL);
+        return 0;
+    }
+    
+    for (;;) {
         switch(state) {
         case BACKUP:
             return 10;
@@ -81,21 +104,21 @@ int main(int argc, char** argv)
             
         case WCONFIG:
             if (requested_wireless_tools == 0) {
+                di_exec_shell_log("apt-install wireless-tools");
                 requested_wireless_tools = 1;
-                di_exec_shell("apt-install wireless-tools");
             }
             state = WCONFIG_ESSID;
             break;
             
         case WCONFIG_ESSID:
-            if (netcfg_wireless_set_essid (client, interface, NULL))
+            if (netcfg_wireless_set_essid(client, interface, NULL) == GO_BACK)
                 state = BACKUP;
             else
                 state = WCONFIG_WEP;
             break;
             
         case WCONFIG_WEP:
-            if (netcfg_wireless_set_wep (client, interface))
+            if (netcfg_wireless_set_wep(client, interface) == GO_BACK)
                 state = WCONFIG_ESSID;
             else
                 state = GET_STATIC;
diff --git a/netcfg.c b/netcfg.c
index 16823c1..9834f63 100644
--- a/netcfg.c
+++ b/netcfg.c
@@ -1,6 +1,6 @@
 /* 
    netcfg.c - Configure a network via DHCP or manual configuration 
-   for debian-installer
+   for the debian-installer
 
    Copyright (C) 2000-2002  David Kimdon <dwhedon@debian.org>
                             and others (see debian/copyright)
@@ -18,7 +18,7 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
+   
 */
 
 #include <string.h>
@@ -61,6 +61,12 @@ response_t netcfg_get_method(struct debconfclient *client)
 int main(int argc, char *argv[])
 {
     int num_interfaces = 0;
+    static struct debconfclient *client;
+    static int requested_wireless_tools = 0;
+    char **ifaces;
+    char *defiface = NULL, *defwireless = NULL;
+    response_t res;
+    
     enum { BACKUP,
            GET_INTERFACE,
            GET_HOSTNAME_ONLY,
@@ -72,23 +78,17 @@ int main(int argc, char *argv[])
            WCONFIG_WEP,
            QUIT } state = GET_INTERFACE;
     
-    static struct debconfclient *client;
-    static int requested_wireless_tools = 0;
-    char **ifaces;
-    char *defiface = NULL, *defwireless = NULL;
-    response_t res;
-    
     /* initialize libd-i */
     di_system_init("netcfg");
     
-    parse_args (argc, argv);
-    reap_old_files ();
+    parse_args(argc, argv);
+    reap_old_files();
     open_sockets();
     
     /* initialize debconf */
     client = debconfclient_new();
     debconf_capb(client, "backup");
-
+    
     /* Check to see if netcfg should be run at all */
     debconf_get(client, "netcfg/enable");
     if (!strcmp(client->value, "false")) {
@@ -187,12 +187,12 @@ int main(int argc, char *argv[])
             if (!defiface && defwireless)
                 defiface = defwireless;
             
-            if(netcfg_get_interface(client, &interface, &num_interfaces, defiface))
+            if (netcfg_get_interface(client, &interface, &num_interfaces, defiface))
                 state = BACKUP;
             else if (! interface || ! num_interfaces)
                 state = GET_HOSTNAME_ONLY;
             else {
-                if (is_wireless_iface (interface))
+                if (is_wireless_iface(interface))
                     state = WCONFIG;
                 else
                     state = GET_METHOD;
@@ -280,4 +280,6 @@ int main(int argc, char *argv[])
             return 0;
         }
     }
+    
+    return 0;
 }


Reply to: