X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fhostname.c;h=04a051ede7f79089eb98a4d43d9e989ddb990158;hb=11d0096516c0d5395729caba5dfd940a10a6e20c;hp=d2516b5fb904c6f46e77d534dee78dd4369bdb77;hpb=1d9e99b399e72763045a2428e04b32278538ccc7;p=oweals%2Fbusybox.git diff --git a/networking/hostname.c b/networking/hostname.c index d2516b5fb..04a051ede 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -10,6 +10,24 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config HOSTNAME +//config: bool "hostname" +//config: default y +//config: help +//config: Show or set the system's host name. +//config: +//config:config DNSDOMAINNAME +//config: bool "dnsdomainname" +//config: default y +//config: help +//config: Alias to "hostname -d". + +//applet:IF_DNSDOMAINNAME(APPLET_ODDNAME(dnsdomainname, hostname, BB_DIR_BIN, BB_SUID_DROP, dnsdomainname)) +//applet:IF_HOSTNAME(APPLET(hostname, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild: lib-$(CONFIG_HOSTNAME) += hostname.o +//kbuild: lib-$(CONFIG_DNSDOMAINNAME) += hostname.o + //usage:#define hostname_trivial_usage //usage: "[OPTIONS] [HOSTNAME | -F FILE]" //usage:#define hostname_full_usage "\n\n" @@ -106,7 +124,7 @@ int hostname_main(int argc UNUSED_PARAM, char **argv) OPT_i = 0x4, OPT_s = 0x8, OPT_F = 0x10, - OPT_dfis = 0xf, + OPT_dfi = 0x7, }; unsigned opts; @@ -131,10 +149,14 @@ int hostname_main(int argc UNUSED_PARAM, char **argv) opts = getopt32(argv, "dfisF:v", &hostname_str); argv += optind; buf = safe_gethostname(); - if (applet_name[0] == 'd') /* dnsdomainname? */ - opts = OPT_d; + if (ENABLE_DNSDOMAINNAME) { + if (!ENABLE_HOSTNAME || applet_name[0] == 'd') { + /* dnsdomainname */ + opts = OPT_d; + } + } - if (opts & OPT_dfis) { + if (opts & OPT_dfi) { /* Cases when we need full hostname (or its part) */ struct hostent *hp; char *p; @@ -159,6 +181,9 @@ int hostname_main(int argc UNUSED_PARAM, char **argv) bb_putchar('\n'); } } + } else if (opts & OPT_s) { + strchrnul(buf, '.')[0] = '\0'; + puts(buf); } else if (opts & OPT_F) { /* Set the hostname */ do_sethostname(hostname_str, 1);