--- rfc2131.c.orig	2013-07-21 08:41:27.000000000 +0100
+++ rfc2131.c	2013-07-22 17:49:26.000000000 +0100
@@ -387,6 +387,8 @@
 	{
 	  hostname = config->hostname;
 	  domain = config->domain;
+	  if (hostname && !domain && option_bool(OPT_EXPAND))
+	    domain = daemon->domain_suffix;
 	}
 
       if (config)
@@ -504,7 +506,7 @@
       return message ? 0 : dhcp_packet_size(mess, agent_id, real_end);
     }
       
-  if ((opt = option_find(mess, sz, OPTION_CLIENT_FQDN, 4)))
+  if ((opt = option_find(mess, sz, OPTION_CLIENT_FQDN, 3)))
     {
       /* http://tools.ietf.org/wg/dhc/draft-ietf-dhc-fqdn-option/draft-ietf-dhc-fqdn-option-10.txt */
       int len = option_len(opt);
@@ -534,7 +536,7 @@
 	}
       
       if (fqdn_flags & 0x04)
-	while (*op != 0 && ((op + (*op) + 1) - pp) < len)
+	while (*op != 0 && ((op + (*op)) - pp) < len)
 	  {
 	    memcpy(pq, op+1, *op);
 	    pq += *op;
@@ -579,6 +581,8 @@
     {
       hostname = config->hostname;
       domain = config->domain;
+      if (hostname && !domain && option_bool(OPT_EXPAND))
+        domain = daemon->domain_suffix;
       hostname_auth = 1;
       /* be careful not to send an OFFER with a hostname not matching the DISCOVER. */
       if (fqdn_flags != 0 || !client_hostname || hostname_isequal(hostname, client_hostname))
@@ -2267,7 +2271,7 @@
       if (fqdn_flags != 0)
 	{
 	  len = strlen(hostname) + 3;
-	  
+          
 	  if (fqdn_flags & 0x04)
 	    len += 2;
 	  else if (null_term)
@@ -2275,6 +2279,8 @@
 
 	  if (domain)
 	    len += strlen(domain) + 1;
+	  else if (fqdn_flags & 0x04)
+	    len--;
 	  
 	  if ((p = free_space(mess, end, OPTION_CLIENT_FQDN, len)))
 	    {
@@ -2286,8 +2292,10 @@
 		{
 		  p = do_rfc1035_name(p, hostname);
 		  if (domain)
-		    p = do_rfc1035_name(p, domain);
-		  *p++ = 0;
+		    {
+		      p = do_rfc1035_name(p, domain);
+		      *p++ = 0;
+		    }
 		}
 	      else
 		{
--- rfc3315.c.orig	2013-07-21 08:38:14.000000000 +0100
+++ rfc3315.c	2013-07-22 17:32:11.000000000 +0100
@@ -459,6 +459,9 @@
 		}
 	    }
 	}
+
+      if (state.hostname && !state.domain && option_bool(OPT_EXPAND))
+        state.domain = daemon->domain_suffix;
     }
 
   if (config)
@@ -1299,16 +1302,25 @@
       size_t len = strlen(state->hostname);
       
       if (state->send_domain)
-	len += strlen(state->send_domain) + 1;
+	len += strlen(state->send_domain) + 2;
+      else if (state->domain)
+        len += strlen(state->domain) + 2;
 
       o = new_opt6(OPTION6_FQDN);
-      if ((p = expand(len + 3)))
+      if ((p = expand(len + 2)))
 	{
 	  *(p++) = state->fqdn_flags;
 	  p = do_rfc1035_name(p, state->hostname);
 	  if (state->send_domain)
-	    p = do_rfc1035_name(p, state->send_domain);
-	  *p = 0;
+	    {  
+	      p = do_rfc1035_name(p, state->send_domain);
+	      *p = 0;
+	    }
+	  else if (state->domain)
+	    {
+	      p = do_rfc1035_name(p, state->domain);
+	      *p = 0;
+	    }
 	}
       end_opt6(o);
     }