debian set_ip4_config_from_resolv_conf patch
- From: Thom May <thom canonical com>
- To: networkmanager list <networkmanager-list gnome org>
- Subject: debian set_ip4_config_from_resolv_conf patch
- Date: Mon, 13 Jun 2005 21:27:44 +0100
Hi;
this patch adds set_ip4_config... to the Debian backend.
Cheers,
-Thom
Index: src/backends/NetworkManagerDebian.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/backends/NetworkManagerDebian.c,v
retrieving revision 1.24
diff -u -u -r1.24 NetworkManagerDebian.c
--- src/backends/NetworkManagerDebian.c 16 May 2005 12:57:08 -0000 1.24
+++ src/backends/NetworkManagerDebian.c 13 Jun 2005 20:13:41 -0000
@@ -421,7 +421,83 @@
} DebSystemConfigData;
/*
- * nm_system_device_update_config_info
+ * set_ip4_config_from_resolv_conf
+ *
+ * Add nameservers and search names from a resolv.conf format file.
+ *
+ */
+static void set_ip4_config_from_resolv_conf (const char *filename, NMIP4Config *ip4_config)
+{
+ char * contents = NULL;
+ char ** split_contents = NULL;
+ int i, len;
+
+ g_return_if_fail (filename != NULL);
+ g_return_if_fail (ip4_config != NULL);
+
+ if (!g_file_get_contents (filename, &contents, NULL, NULL) || (contents == NULL))
+ return;
+
+ if (!(split_contents = g_strsplit (contents, "\n", 0)))
+ goto out;
+
+ len = g_strv_length (split_contents);
+ for (i = 0; i < len; i++)
+ {
+ char *line = split_contents[i];
+
+ /* Ignore comments */
+ if (!line || (line[0] == ';'))
+ continue;
+
+ line = g_strstrip (line);
+ if ((strncmp (line, "search", 6) == 0) && (strlen (line) > 6))
+ {
+ char *searches = g_strdup (line + 7);
+ char **split_searches = NULL;
+
+ if (!searches || !strlen (searches))
+ continue;
+
+ /* Allow space-separated search domains */
+ if (split_searches == g_strsplit (searches, " ", 0))
+ {
+ int m, srch_len;
+
+ srch_len = g_strv_length (split_searches);
+ for (m = 0; m < srch_len; m++)
+ {
+ if (split_searches[m])
+ nm_ip4_config_add_domain (ip4_config, split_searches[m]);
+ }
+ g_strfreev (split_searches);
+ }
+ else
+ {
+ /* Only 1 item, add the whole line */
+ nm_ip4_config_add_domain (ip4_config, searches);
+ }
+
+ g_free (searches);
+ }
+ else if ((strncmp (line, "nameserver", 10) == 0) && (strlen (line) > 10))
+ {
+ guint32 addr = (guint32) (inet_addr (line + 11));
+
+ if (addr != (guint32) -1)
+ nm_ip4_config_add_nameserver (ip4_config, addr);
+ }
+ }
+
+ g_strfreev (split_contents);
+
+out:
+ g_free (contents);
+}
+
+
+/*
+ * nm_system_device_get_system_config
*
* Retrieve any relevant configuration info for a particular device
* from the system network configuration information. Clear out existing
@@ -487,6 +563,9 @@
| ~nm_ip4_config_get_netmask (sys_data->config));
nm_ip4_config_set_broadcast (sys_data->config, broadcast);
}
+
+ if (!sys_data->use_dhcp)
+ set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config);
#if 0
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]