From: "Ed Swierk" <eswierk@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Set hostname in DHCP response
Date: Thu, 9 Mar 2006 23:35:09 -0800 [thread overview]
Message-ID: <c1bf1cf0603092335x52389dc6ic7a4fa0099aeff59@mail.gmail.com> (raw)
[-- 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:
next reply other threads:[~2006-03-10 7:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-10 7:35 Ed Swierk [this message]
2006-03-11 22:19 ` [Qemu-devel] [PATCH] Set hostname in DHCP response Paul Brook
2006-03-13 2:13 ` Ed Swierk
2006-03-13 2:46 ` Leonardo E. Reiter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c1bf1cf0603092335x52389dc6ic7a4fa0099aeff59@mail.gmail.com \
--to=eswierk@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).