1 From 2b4773b6ae48fee56c60fb4a1835672cbca78aee Mon Sep 17 00:00:00 2001
2 From: Andreas Oberritter <obi@opendreambox.org>
3 Date: Tue, 15 Jan 2013 17:33:53 +0100
4 Subject: [PATCH 10/10] udhcpc: obtain hostname from OS by default
6 * Doesn't require the 'hostname' option in /etc/network/interfaces,
7 and thus makes udhcpc behave like other clients.
9 Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
11 networking/udhcp/dhcpc.c | 7 +++++++
12 1 file changed, 7 insertions(+)
14 diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
15 index 9fbd3b3..ec9f25d 100644
16 --- a/networking/udhcp/dhcpc.c
17 +++ b/networking/udhcp/dhcpc.c
18 @@ -1117,6 +1117,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
20 if (opt & (OPT_h|OPT_H))
21 client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
23 + char hostname[256]; /* SUSv2: hostnames are <= 255 bytes */
24 + if (gethostname(hostname, sizeof(hostname)) == 0) {
25 + hostname[sizeof(hostname) - 1] = '\0';
26 + client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, hostname, 0);
30 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
31 client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);