On 20.03.2013 18:02, Tito wrote: > On Wednesday 20 March 2013 15:31:26 Andreas Oberritter wrote: >> * Doesn't require the 'hostname' option in /etc/network/interfaces, >> and thus makes udhcpc behave like other clients. >> >> Signed-off-by: Andreas Oberritter <[email protected]> >> --- >> networking/udhcp/dhcpc.c | 9 +++++++++ >> 1 file changed, 9 insertions(+) >> >> diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c >> index fe2e681..35487b6 100644 >> --- a/networking/udhcp/dhcpc.c >> +++ b/networking/udhcp/dhcpc.c >> @@ -1375,6 +1375,15 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) >> logmode |= LOGMODE_SYSLOG; >> } >> >> + /* try to get hostname from OS */ >> + if (!client_config.hostname) { >> + char hostname[256]; /* SUSv2: hostnames are <= 255 bytes */ >> + if (gethostname(hostname, sizeof(hostname)) == 0) { >> + hostname[sizeof(hostname) - 1] = '\0'; >> + client_config.hostname = >> alloc_dhcp_option(DHCP_HOST_NAME, hostname, 0); >> + } >> + } >> + >> /* Make sure fd 0,1,2 are open */ >> bb_sanitize_stdio(); >> /* Equivalent of doing a fflush after every \n */ >> > > > Hi, > I'm wondering about what will happen if gethostname fails, > seems to me you are in the same situation as before (!client_config.hostname) > . > Maybe something like this; > > /* try to get hostname from OS */ > if (!client_config.hostname) { > hostname = safe_gethostname(); > if (hostname[0] == '?') > hostname = xstrdup("Linux"); > client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, > hostname, 0); > free(hostname); > }
I prefer sending no hostname at all, if gethostbyname fails. Wrong information is worse than no information. Regards, Andreas _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
