File bnc#556613.diff of Package dhcpcd

--- dhcpcd-3.2.3/configure.c
+++ dhcpcd-3.2.3/configure.c	2009-12-10 11:38:54.223002689 +0100
@@ -483,6 +483,52 @@
 }
 #endif
 
+static char *strip_hostname (char *hostname, const dhcp_t *dhcp,
+			     const options_t *options)
+{
+	char *p;
+	if( !hostname || !dhcp || !options)
+		return hostname;
+
+	p = strchr (hostname, '.');
+	if (p) {
+		switch (options->dohostname) {
+			case 1: /* -H */
+			case 4: /* -HHHH */
+				break;
+			case 2: /* -HH */
+			case 5: /* -HHHHH */
+				/* Strip out the domain if it matches */
+				p++;
+				if (*p && dhcp->dnssearch) {
+					char *s = xstrdup (dhcp->dnssearch);
+					char *sp = s;
+					char *t;
+
+					while ((t = strsep (&sp, " ")))
+						if (strcmp (t, p) == 0) {
+							*--p = '\0';
+							break;
+						}
+					free (s);
+				} else if (dhcp->dnsdomain) {
+					if (strcmp (dhcp->dnsdomain, p) == 0)
+						*--p = '\0';
+				}
+				break;
+			case 3: /* -HHH */
+			case 6: /* -HHHHHH */
+				/* Just strip the domain */
+				*p = '\0';
+				break;
+			default: /* Too many H! */
+				break;
+		}
+	}
+
+	return hostname;
+}
+
 static char *lookuphostname (char *hostname, const dhcp_t *dhcp,
 			     const options_t *options)
 {
@@ -495,7 +541,6 @@
 	struct addrinfo hints;
 	struct addrinfo *res = NULL;
 	int result;
-	char *p;
 
 	logger (LOG_DEBUG, "Looking up hostname via DNS");
 	addr = xmalloc (sizeof (char) * NI_MAXHOST);
@@ -527,41 +572,7 @@
 		return (NULL);
 	}
 
-	p = strchr (addr, '.');
-	if (p) {
-		switch (options->dohostname) {
-			case 1: /* -H */
-			case 4: /* -HHHH */
-				break;
-			case 2: /* -HH */
-			case 5: /* -HHHHH */
-				/* Strip out the domain if it matches */
-				p++;
-				if (*p && dhcp->dnssearch) {
-					char *s = xstrdup (dhcp->dnssearch);
-					char *sp = s;
-					char *t;
-
-					while ((t = strsep (&sp, " ")))
-						if (strcmp (t, p) == 0) {
-							*--p = '\0';
-							break;
-						}
-					free (s);
-				} else if (dhcp->dnsdomain) {
-					if (strcmp (dhcp->dnsdomain, p) == 0)
-						*--p = '\0';
-				}
-				break;
-			case 3: /* -HHH */
-			case 6: /* -HHHHHH */
-				/* Just strip the domain */
-				*p = '\0';
-				break;
-			default: /* Too many H! */
-				break;
-		}
-	}
+	strip_hostname(addr, dhcp, options);
 
 	strlcpy (hostname, addr, MAXHOSTNAMELEN);
 	free (addr);
@@ -847,6 +858,8 @@
 		 * if we need it */
 		if (! *newhostname || options->dohostname > 3)
 			lookuphostname (newhostname, dhcp, options);
+		else
+			strip_hostname(newhostname, dhcp, options);
 
 		if (*newhostname) {
 			logger (LOG_INFO, "setting hostname to `%s'",
openSUSE Build Service is sponsored by