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

Bug#649747: 127.0.1.1 hack is not supported by kFreeBSD



Package: netcfg
Version: 1.70
Severity: normal
Tags: patch

127.0.1.1 hack introduced in commit 6762701e15829b1857fe252c1de642f8ec00f8a8
is based on the assumption that when loopback interface is set with
a 255.0.0.0 netmask, it will identify itself by any address belonging to
this subnet.  This is true on Linux, but not on kFreeBSD.

(it remains to be found whether it's true on Hurd pfinet, anyone can
find out by running "ping 127.0.1.1"?)

Attached patch partially reverts that to make it only effective on Linux.

[1] See:

+netcfg (1.13) unstable; urgency=low
+
+  [ Thomas Hood ]
+  * If there is no permanent IP address with which the UNIX hostname
+    (i.e., that which is returned by the "hostname" command) can be
+    associated in /etc/hosts then associate it with address 127.0.1.1
+    rather than 127.0.0.1.  Associating the UNIX hostname with the
+    latter had the unwanted effect of making 'localhost.localdomain'
+    the canoncial hostname associated with the UNIX hostname.
+    (Closes: #316099)

-- System Information:
Debian Release: 6.0.3
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: kfreebsd-amd64 (x86_64)

Kernel: kFreeBSD 8.1-1-amd64
Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff --git a/netcfg-common.c b/netcfg-common.c
index 4b2a8a0..6053a48 100644
--- a/netcfg-common.c
+++ b/netcfg-common.c
@@ -1042,19 +1042,23 @@ void netcfg_write_common(struct in_addr ipaddress, char *hostname, char *domain)
     if ((fp = file_open(HOSTS_FILE, "w"))) {
         char ptr1[INET_ADDRSTRLEN];
 
-        fprintf(fp, "127.0.0.1\tlocalhost\n");
+        fprintf(fp, "127.0.0.1\tlocalhost");
 
         if (ipaddress.s_addr) {
             inet_ntop (AF_INET, &ipaddress, ptr1, sizeof(ptr1));
             if (domain_nodot && !empty_str(domain_nodot))
-                fprintf(fp, "%s\t%s.%s\t%s\n", ptr1, hostname, domain_nodot, hostname);
+                fprintf(fp, "\n%s\t%s.%s\t%s\n", ptr1, hostname, domain_nodot, hostname);
             else
-                fprintf(fp, "%s\t%s\n", ptr1, hostname);
+                fprintf(fp, "\n%s\t%s\n", ptr1, hostname);
         } else {
+#ifdef __linux__
             if (domain_nodot && !empty_str(domain_nodot))
-                fprintf(fp, "127.0.1.1\t%s.%s\t%s\n", hostname, domain_nodot, hostname);
+                fprintf(fp, "\n127.0.1.1\t%s.%s\t%s\n", hostname, domain_nodot, hostname);
             else
-                fprintf(fp, "127.0.1.1\t%s\n", hostname);
+                fprintf(fp, "\n127.0.1.1\t%s\n", hostname);
+#else
+            fprintf(fp, "\t%s\n", hostname);
+#endif
         }
 
         fprintf(fp, "\n" IPV6_HOSTS);

Reply to: