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

Bug#588761: netcfg: please include Hurd support



Package: netcfg
Version: 1.54
Tags: patch
Usertags: gsoc2010

NB: Please don't care -- I'll ask Samuel Thibault (my GSoC mentor) to
commit most of my changes, including those, and ask debian-boot to
review the more intrusive ones later, in one run. Of course I welcome
any kind of comments nonetheless.

Anyway, the attached patch makes netcfg-static work on Hurd.

Thanks,
-- 
Jeremie Koenig <jk@jk.fr.eu.org>
http://jk.fr.eu.org
Index: netcfg/debian/changelog
===================================================================
--- netcfg/debian/changelog	(revision 63843)
+++ netcfg/debian/changelog	(working copy)
@@ -1,3 +1,10 @@
+netcfg (1.55) UNRELEASED; urgency=low
+
+  * More fixes for Hurd support, including network device detection
+    (closes: <please fill-in>).
+
+ -- Jeremie Koenig <jk@jk.fr.eu.org>  Sun, 11 Jul 2010 22:51:56 +0000
+
 netcfg (1.54) unstable; urgency=low
 
   [ Samuel Thibault ]
Index: netcfg/static.c
===================================================================
--- netcfg/static.c	(revision 63843)
+++ netcfg/static.c	(working copy)
@@ -274,20 +274,22 @@
     char ptr1[INET_ADDRSTRLEN];
 
 #ifdef __GNU__
-    di_exec_shell_log("settrans /servers/socket/2 -fg");
     snprintf(buf, sizeof(buf),
              "settrans -fgap /servers/socket/2 /hurd/pfinet --interface=%s --address=%s",
              interface, inet_ntop (AF_INET, &ipaddress, ptr1, sizeof (ptr1)));
     di_snprintfcat(buf, sizeof(buf), " --netmask=%s",
                    inet_ntop (AF_INET, &netmask, ptr1, sizeof (ptr1)));
-    buf[sizeof(buf) - 1] = '\0';
 
     if (gateway.s_addr)
-        snprintf(buf, sizeof(buf), " --gateway=%s",
-                 inet_ntop (AF_INET, &gateway, ptr1, sizeof (ptr1)));
+        di_snprintfcat(buf, sizeof(buf), " --gateway=%s",
+                       inet_ntop (AF_INET, &gateway, ptr1, sizeof (ptr1)));
 
-    rv |= di_exec_shell_log(buf);
+    buf[sizeof(buf) - 1] = '\0';
 
+    /* NB: unfortunately we cannot use di_exec_shell_log() here, as the active
+     * translator would capture its pipe and make it hang forever. */
+    rv |= di_exec_shell(buf);
+
 #elif defined(__FreeBSD_kernel__)
     deconfigure_network();
     
Index: netcfg/netcfg-common.c
===================================================================
--- netcfg/netcfg-common.c	(revision 63843)
+++ netcfg/netcfg-common.c	(working copy)
@@ -229,8 +229,52 @@
     return strcmp(*ia, *ib);
 }
 
+#ifdef __GNU__
+#include <mach.h>
+#include <device/device.h>
+#include <hurd.h>
+/* Unfortunately, getifaddrs() does not work on Hurd, so we try possible names
+ * for network interfaces and check whether they exists by attempting to open
+ * the kernel device. */
 int get_all_ifs (int all, char*** ptr)
 {
+    static const char *const fmt[] = { "eth%d", "wl%d", NULL };
+
+    mach_port_t device_master;
+    device_t device;
+    int err;
+    char **list;
+    int num, i, j;
+    char name[5 + 3 * sizeof (int)];
+
+    err = get_privileged_ports (0, &device_master);
+    if (err)
+	return 0;
+
+    num = 0;
+    list = malloc(sizeof *list);
+    for (i = 0; fmt[i]; i++)
+	for (j = 0; 1; j++) {
+	    sprintf (name, fmt[i], j);
+	    err = device_open (device_master, D_READ, name, &device);
+	    if (err != 0)
+		break;
+
+	    device_close (device);
+	    mach_port_deallocate (mach_task_self (), device);
+
+	    list = realloc (list, (num + 2) * sizeof *list);
+	    list[num++] = strdup(name);
+	}
+    list[num] = NULL;
+
+    mach_port_deallocate (mach_task_self (), device_master);
+    *ptr = list;
+    return num;
+}
+#else
+int get_all_ifs (int all, char*** ptr)
+{
     struct ifaddrs *ifap, *ifa;
     char ibuf[512];
     char** list = NULL;
@@ -279,6 +323,7 @@
 
     return len;
 }
+#endif
 
 #ifdef __linux__
 short find_in_stab(const char* iface)

Reply to: