qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Set hostname in DHCP response
@ 2006-03-10  7:35 Ed Swierk
  2006-03-11 22:19 ` Paul Brook
  0 siblings, 1 reply; 4+ messages in thread
From: Ed Swierk @ 2006-03-10  7:35 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

Here is a patch that sets the hostname in the DHCP response generated
by qemu's user-net DHCP server, and adds a new -hostname command line
option to specify the value.

If the guest OS is configured properly, the value received in the DHCP
response is automatically used to set the machine's hostname. (In Red
Hat/Fedora Linuxes, this happens if HOSTNAME is not hardcoded in
/etc/sysconfig/network.)

Feedback welcome.

--Ed

[-- Attachment #2: qemu-hostname.patch --]
[-- Type: text/x-patch, Size: 2889 bytes --]

diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/bootp.c qemu-snapshot-2006-03-06_23/slirp/bootp.c
--- qemu-snapshot-2006-03-06_23.orig/slirp/bootp.c	2005-06-05 17:11:42.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/bootp.c	2006-03-10 07:11:19.000000000 +0000
@@ -228,6 +228,16 @@
         val = htonl(LEASE_TIME);
         memcpy(q, &val, 4);
         q += 4;
+
+        if (slirp_hostname && *slirp_hostname) {
+            val = strlen(slirp_hostname);
+            if (val > 32)
+                val = 32;
+            *q++ = RFC1533_HOSTNAME;
+            *q++ = val;
+            memcpy(q, slirp_hostname, val);
+            q += val;
+        }
     }
     *q++ = RFC1533_END;
     
diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/libslirp.h qemu-snapshot-2006-03-06_23/slirp/libslirp.h
--- qemu-snapshot-2006-03-06_23.orig/slirp/libslirp.h	2005-06-05 17:11:42.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/libslirp.h	2006-03-10 06:47:32.000000000 +0000
@@ -32,6 +32,7 @@
                    int guest_port);
 
 extern const char *tftp_prefix;
+extern const char *slirp_hostname;
 
 #ifdef __cplusplus
 }
diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/slirp.c qemu-snapshot-2006-03-06_23/slirp/slirp.c
--- qemu-snapshot-2006-03-06_23.orig/slirp/slirp.c	2005-09-03 10:45:09.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/slirp.c	2006-03-10 06:46:28.000000000 +0000
@@ -25,6 +25,8 @@
 /* XXX: suppress those select globals */
 fd_set *global_readfds, *global_writefds, *global_xfds;
 
+const char *slirp_hostname = NULL;
+
 #ifdef _WIN32
 
 static int get_dns_addr(struct in_addr *pdns_addr)
diff -BurN qemu-snapshot-2006-03-06_23.orig/vl.c qemu-snapshot-2006-03-06_23/vl.c
--- qemu-snapshot-2006-03-06_23.orig/vl.c	2006-02-20 00:33:36.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/vl.c	2006-03-10 06:45:32.000000000 +0000
@@ -4183,6 +4183,7 @@
 #endif
            "-redir [tcp|udp]:host-port:[guest-host]:guest-port\n"
            "                redirect TCP or UDP connections from host to guest [-net user]\n"
+           "-hostname name  set hostname in DHCP responses\n"
 #endif
            "\n"
            "Linux boot specific:\n"
@@ -4267,6 +4268,7 @@
     QEMU_OPTION_tftp,
     QEMU_OPTION_smb,
     QEMU_OPTION_redir,
+    QEMU_OPTION_hostname,
 
     QEMU_OPTION_kernel,
     QEMU_OPTION_append,
@@ -4332,6 +4334,7 @@
     { "smb", HAS_ARG, QEMU_OPTION_smb },
 #endif
     { "redir", HAS_ARG, QEMU_OPTION_redir },
+    { "hostname", HAS_ARG, QEMU_OPTION_hostname },
 #endif
 
     { "kernel", HAS_ARG, QEMU_OPTION_kernel },
@@ -4785,6 +4788,9 @@
             case QEMU_OPTION_redir:
                 net_slirp_redir(optarg);                
                 break;
+            case QEMU_OPTION_hostname:
+                slirp_hostname = optarg;
+                break;
 #endif
 #ifdef HAS_AUDIO
             case QEMU_OPTION_audio_help:

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-13  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-10  7:35 [Qemu-devel] [PATCH] Set hostname in DHCP response Ed Swierk
2006-03-11 22:19 ` Paul Brook
2006-03-13  2:13   ` Ed Swierk
2006-03-13  2:46     ` Leonardo E. Reiter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).