busybox/udhcpc: set DHCP hostname
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-core / busybox / busybox-1.19.4 / 0010-udhcpc-obtain-hostname-from-OS-by-default.patch
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
5
6 * Doesn't require the 'hostname' option in /etc/network/interfaces,
7   and thus makes udhcpc behave like other clients.
8
9 Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
10 ---
11  networking/udhcp/dhcpc.c |    7 +++++++
12  1 file changed, 7 insertions(+)
13
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)
19                 );
20         if (opt & (OPT_h|OPT_H))
21                 client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
22 +       else {
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);
27 +               }
28 +       }
29         if (opt & OPT_F) {
30                 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
31                 client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
32 -- 
33 1.7.10.4
34