hostname-3.23ubuntu2/0000775000000000000000000000000014127606000011470 5ustar hostname-3.23ubuntu2/COPYRIGHT0000664000000000000000000000147713234044046013000 0ustar hostname -- set the host name or show the host/domain name Copyright (C) 1994-1997 Peter Tobias 2009- Michael Meskes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. hostname-3.23ubuntu2/Makefile0000664000000000000000000000215213234044046013134 0ustar CFLAGS+=-O2 -Wall -D_GNU_SOURCE # uncomment the following line if you want to install to a different base dir. #BASEDIR=/mnt/test BINDIR:=/bin MANDIR:=/usr/share/man OBJS=hostname.o hostname: $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) ln -fs hostname dnsdomainname ln -fs hostname domainname ln -fs hostname ypdomainname ln -fs hostname nisdomainname install: hostname install -d ${BASEDIR}$(MANDIR)/man1 install -o root -g root -m 0644 hostname.1 ${BASEDIR}$(MANDIR)/man1 ln -fs hostname.1 ${BASEDIR}$(MANDIR)/man1/dnsdomainname.1 ln -fs hostname.1 ${BASEDIR}$(MANDIR)/man1/domainname.1 ln -fs hostname.1 ${BASEDIR}$(MANDIR)/man1/ypdomainname.1 ln -fs hostname.1 ${BASEDIR}$(MANDIR)/man1/nisdomainname.1 install -d ${BASEDIR}$(BINDIR) install -o root -g root -m 0755 hostname ${BASEDIR}$(BINDIR) ln -fs hostname ${BASEDIR}$(BINDIR)/dnsdomainname ln -fs hostname ${BASEDIR}$(BINDIR)/domainname ln -fs hostname ${BASEDIR}$(BINDIR)/nisdomainname ln -fs hostname ${BASEDIR}$(BINDIR)/ypdomainname clean: -rm -f $(OBJS) hostname dnsdomainname domainname nisdomainname ypdomainname .PHONY: clean install hostname-3.23ubuntu2/debian/0000775000000000000000000000000014216623547012730 5ustar hostname-3.23ubuntu2/debian/changelog0000664000000000000000000003602514216623547014610 0ustar hostname (3.23ubuntu2) jammy; urgency=medium * No-change rebuild for ppc64el baseline bump. -- Łukasz 'sil2100' Zemczak Wed, 23 Mar 2022 14:57:59 +0100 hostname (3.23ubuntu1) impish; urgency=medium * Fix version check for buildN and ubuntuN versions. -- Matthias Klose Thu, 07 Oct 2021 17:02:24 +0200 hostname (3.23) unstable; urgency=medium * Increase buffer size for all FQDNs to NI_MAXHOST as suggested by manpage. (Closes: #942311) * Use the same size for getdomainname(). * Bumped Standards-Version, no changes needed. * Removed debian/compat file as suggested by lintian. -- Michael Meskes Thu, 07 Nov 2019 12:31:36 +0100 hostname (3.22) unstable; urgency=medium * Made build process robust against binNMUs. (Closes: #935277) * Bumped Standards-Version, no changes needed. * Bumped debhelper version, no changes needed. -- Michael Meskes Sat, 24 Aug 2019 19:05:40 +0200 hostname (3.21) unstable; urgency=medium * Minor fixes to the manpage. Thanks to Bjarni Ingi Gislason (Closes: #900857) * Bumped Standards-Version, no changes needed. -- Michael Meskes Thu, 27 Sep 2018 10:45:17 +0200 hostname (3.20) unstable; urgency=medium * Removed old alioth list from maintainers field. -- Michael Meskes Wed, 31 Jan 2018 13:08:15 +0100 hostname (3.19) unstable; urgency=medium * Bumped Standards-Version to 4.1.3, no changes needed. * Switched to debhelper 11 * Fix lintian warnings. -- Michael Meskes Tue, 30 Jan 2018 11:34:44 +0100 hostname (3.18) unstable; urgency=medium * Make sure memory is initialized to zero before attempting to read hostname. Thanks to Marko Dimjašević (Closes: #829010) * Bumped Standards-Version to 3.9.8, no changes needed. * Updated to debhelper 9. -- Michael Meskes Sun, 03 Jul 2016 21:26:17 +0200 hostname (3.17) unstable; urgency=medium * Applied patch by Szabolcs Nagy (Ccloses: #787780) to: * Use _GNU_SOURCE feature test macro, instead of glibc internal __USE_GNU. * Use getdomainname instead of yp_get_default_domain because it is more widely available and avoids the -lnsl dependency. * localnisdomain is kept, even though it should be the same as localdomain, so the behaviour is not changed in case of an error. * Replace 'dh-clean -k' with 'dh-prep' -- Michael Meskes Fri, 19 Feb 2016 13:00:23 +0100 hostname (3.16) unstable; urgency=medium * Changed buffer size to the recommended 255 character when working with names instead of IPs. (Closes: #796922) * Bumped Standards-Version to 3.9.6, no changes needed. -- Michael Meskes Tue, 01 Sep 2015 12:32:18 +0200 hostname (3.15) unstable; urgency=low * Applied patch to make it possible to install binaries and man pages into custom directories. Thanks to Jiri Popelka (Closes: #726484) * Tried to clarify manpage. (Closes: #718393) * Removed hostname.1.fr with was outdated and not kept in sync. -- Michael Meskes Sun, 03 Nov 2013 15:27:04 +0100 hostname (3.14) unstable; urgency=low * Symlink binaries instead of hardlinking them. (Closes: #718400) -- Michael Meskes Fri, 06 Sep 2013 12:06:19 +0200 hostname (3.13) unstable; urgency=low * Finally completely remove verbose option. Thanks to Jiri Popelka (Closes: #703974) * Bumped Standards-Version to 3.9.4, no changes needed. -- Michael Meskes Tue, 18 Jun 2013 11:51:37 +0200 hostname (3.12) unstable; urgency=low * Rewrote parts of the manpage. Thanks to Ben Wong (Closes: #568889) * Bumped Standards-Version to 3.9.3, no changes needed. -- Michael Meskes Thu, 06 Dec 2012 16:15:53 +0100 hostname (3.11) unstable; urgency=low * Fixed typo in manpage. Thanks to Regid Ichira (Closes: #659836) * Order options alphabetically in program. Thanks to Jari Aalto (Closes: #660106) * Combine options in manpage. * Do not install hostname.1.fr anymore because it is outdated. -- Michael Meskes Thu, 16 Feb 2012 16:02:01 +0100 hostname (3.10) unstable; urgency=low * Enabled hardened build flag. Thanks to Moritz Muehlenhoff (Closes: #655874) -- Michael Meskes Sun, 15 Jan 2012 13:52:38 +0100 hostname (3.09) unstable; urgency=low * Order items alphabetically in manpage. Thanks to Jari Aalto (Closes: #653269) -- Michael Meskes Wed, 28 Dec 2011 15:14:48 +0100 hostname (3.08) unstable; urgency=low * Prevent a potential buffer underrun. * Clarified FQDN message in man page. (Closes: #626292) * Use Breaks instead of Conflicts. -- Michael Meskes Fri, 23 Dec 2011 11:07:34 +0100 hostname (3.07) unstable; urgency=low * Strip leading and trailing whitespaces from hostname. (Closes: #650822) * Bumped Standards-Version to 3.9.2, no changes needed. * Added build-arch and build-indep targets to rules file. -- Michael Meskes Thu, 22 Dec 2011 16:31:05 +0100 hostname (3.06) unstable; urgency=low * Relax version comparison to make binnmus possible. (Closes: #616683) -- Michael Meskes Mon, 07 Mar 2011 12:31:08 +0100 hostname (3.05) unstable; urgency=low * Updated hostname.c to carry correct version number. (Closes: #602987) * Bumped Standards-Version to 3.9.1, no changes needed. * Added source/format file. -- Michael Meskes Tue, 16 Nov 2010 14:31:07 +0100 hostname (3.04) unstable; urgency=low * Don't strip domain before resolving it for a fqdn hostname. (Closes: #573375) * Bumped Standards-Version to 3.8.4, no changes needed. -- Michael Meskes Mon, 22 Mar 2010 11:58:16 +0100 hostname (3.03) unstable; urgency=low * Do not use buffer on error return. (Closes: #565634) - thanks to Marco d'Itri -- Michael Meskes Tue, 19 Jan 2010 09:07:56 +0100 hostname (3.02) unstable; urgency=low [ Cristian Greco ] * bump version to 3.02 for next release. * set my new maintainer email address. [ Michael Meskes ] * Reject invalid hostnames. (LP #52335) * Gratiously accept FQ hostnames. While this should not be done hostname should still be able to cope with it and print the short name as promised in the manpage (LP#389602). (Closes: #563074) * Added option to display all ip addresses and all fqdns. (Closes: #562830) - thanks to Gábor Gombás -- Michael Meskes Fri, 15 Jan 2010 13:08:57 +0100 hostname (3.01) unstable; urgency=low * Made 'hostname -s' only display the host name cut at the first dot. (Closes: #552482) -- Michael Meskes Tue, 27 Oct 2009 13:25:38 +0100 hostname (3.00) unstable; urgency=low * Bumped versioned conflict against nis. (Closes: #546753) * End beta phase and bump major version to 3. -- Michael Meskes Thu, 01 Oct 2009 14:07:26 +0200 hostname (2.99) unstable; urgency=low [ Cristian Greco ] * attempt to clarify program documentation in usage() and manpage. * bump version to 2.99 * Add versioned Replaces/Conflicts against nis (<< 3.17-29), which drops the {yp,nis,} commands. -- Michael Meskes Mon, 28 Sep 2009 15:31:05 +0200 hostname (2.98) unstable; urgency=low [ Cristian Greco ] * Fix some indentation. * bump version to 2.98. * attempt to clarify program documentation in usage() and manpage. [ Michael Meskes ] * Made program behave exactly like yp-tools domainname when called as {nis,yp,}domainname. * We replace nis by installing {yp,nis,}domainname, closes: #546753 -- Michael Meskes Wed, 16 Sep 2009 19:47:31 +0200 hostname (2.97) unstable; urgency=low * New maintainer, closes: #543892 * Bumped Standards-Version to 3.8.3, no changes needed. * Do not print trailing blank for option "-a", closes: #390527 * Refer to correct init file, closes: #540774 * Applied patch by Scott James Remnant to take care of an empty or non existant /etc/hostname, closes: #543666 * Made package description and manpage clearer, closes: #483221 * Added patch by Michael Stapelberg to better cope with IPv6, closes: #535467 * Added nisdomainname/ypdomainname, closes: #501005 * Strip domain name returned by gethostname(), closes: #420053 -- Michael Meskes Sun, 13 Sep 2009 14:34:13 +0200 hostname (2.96) unstable; urgency=low * Orphaning package. -- Daniel Baumann Thu, 27 Aug 2009 10:01:51 +0200 hostname (2.95) unstable; urgency=low * Bumping to new policy. * Fixing makefile to also install hostname.1.fr * Don't hide make errors in clean target of rules. * Adding ${misc:Depends} to pre-depends. -- Daniel Baumann Thu, 27 Dec 2007 12:39:00 +0100 hostname (2.94) unstable; urgency=low * Correcting manpage about --file (Closes: #252182). * Explicitly saying in the manpage, that /etc/hostname should not contain the FQDN (Closes: #253956). * Using symlink for dnsdomainname (Closes: #382728). * Syncing version number in code (Closes: #396596). * Applied patch from Neil Williams to add cross build support (Closes: #451305). -- Daniel Baumann Wed, 14 Nov 2007 23:05:00 +0100 hostname (2.93) unstable; urgency=low * New maintainer (Closes: #400078). * Updated debian/* to my own packaging style :) * Bumped policy version. -- Daniel Baumann Thu, 23 Nov 2006 20:50:00 +0100 hostname (2.92) unstable; urgency=low * Use syntax in RFC1123 and RFC952 to check hostnames. Thanks to LaMont for the patch. (closes: #341763) -- Graham Wilson Sat, 25 Feb 2006 02:51:17 +0000 hostname (2.91) unstable; urgency=low * Break in read_file instead of returning, so that the file can be closed properly. * Oops. * Properly read files that don't end in a newline. (closes: #325324) -- Graham Wilson Mon, 29 Aug 2005 14:59:17 +0000 hostname (2.90) unstable; urgency=low * Rewrite hostname to hopefully be a bit more organzied. - moved localhost() and localdomain() to hostname.c - code to set the host or domain name moved to set_name() - code to display the host or domain name moved to show_name() - clean up main() - i18n support removed, seems to be unused and outdated - verbose output removed - check for non-used arguments (closes: #253957) - remove the useless man directory from the source - remove unneeded header files - simplify the build system * Set the debhelper compat level to 4. * Build depend on debhelper (>= 4.0). * Improve the copyright file. (closes: #290178) * Update standards version. No changes. * Adjust the synopsis to be in line with the Developer's Reference. * A check_name function was added to check whether hostnames follow RFC 1035 syntax. * Use inet_ntop instead of inet_ntoa when printing addresses, in order to support IPv6 addresses. (closes: #303579) -- Graham Wilson Tue, 23 Aug 2005 06:37:42 +0000 hostname (2.13) unstable; urgency=low * Update the version on clean. (closes: #223978) -- Graham Wilson Wed, 17 Dec 2003 15:25:51 +0000 hostname (2.12) unstable; urgency=medium * Revert the change in 2.11. (closes: #223521) - This technically re-opens #188924 and #208895, but I'll let somebody else see to that. - I think calling gethostbyname is the correct behavior, since the FQDN is supposed to be listed in the hosts(5) file, in which case gethostbyname shouldn't touch the network. So basically, I think the two aforementioned bugs are configuration errors. -- Graham Wilson Sat, 13 Dec 2003 06:28:42 +0000 hostname (2.11) unstable; urgency=medium * New maintainer. Thanks Adam. * Don't call gethostbyname in every case. (closes: #188924, #208895) * Remove extra space from the manual page. -- Graham Wilson Fri, 05 Dec 2003 06:49:23 +0000 hostname (2.10) unstable; urgency=low * -V now does exit(0), not exit(-1). Closes: #180212 * -V sends to stdout not stderr. Closes: #164235 * Recompiled with newer binutils, to support prelinking. Closes: #176356 * -h now sends to stdout, instead of stderr. -- Adam Heath Sat, 8 Feb 2003 01:10:07 -0600 hostname (2.09) unstable; urgency=medium * Changed Depends to Pre-Depends. Closes: 102396. -- Adam Heath Sat, 7 Jul 2001 18:03:56 -0500 hostname (2.08) unstable; urgency=medium * Fixed typo in -h help. Closes: #58795. * Fix dnsdomainname when order is 'nis dns hosts'. Closes: #71721. * Change embedded version to 2.08, instead of 2.05. :| * Use internal error variable, instead of using global errno. Closes: #88279(grave on m68k) * Removed preinst, and changed Pre-Depends to Depends. * Fixed all -Wall. -- Adam Heath Mon, 14 May 2001 08:51:27 -0500 hostname (2.07) unstable; urgency=low * Added build depends. * New maintainer/author, as the old maintainer/author has gone awol, and isn't responding to my mails. -- Adam Heath Sat, 4 Dec 1999 07:40:55 -0600 hostname (2.06) unstable; urgency=low * No longer proved hardlinks for domainname, nisdomainname, and ypdomainname. Closes: #48850, #49009, #49067, #49248, #49553, #49954 -- Adam Heath Sat, 13 Nov 1999 17:50:31 -0600 hostname (2.05) unstable; urgency=low * NMU * Applied patch for hostnames/domainnames of arbitrary length. Closes: #44415 * Fixed extra space when only one hostname is being printed. Closes: #22735 * Added hardlinks for binaries domainname, nisdomainname and ypdomainname. Also updated programs internal version. Closes: #22993 * Used debhelper instead of debstd now. * FHS compliant. -- Adam Heath Wed, 22 Sep 1999 00:12:31 -0500 hostname (2.04) frozen unstable; urgency=low * rebuild with latest debmake version * updated standards-version * minor manpage fixes -- Peter Tobias Mon, 30 Mar 1998 00:00:12 +0200 hostname (2.03) unstable; urgency=low * libc6 version -- Peter Tobias Sun, 14 Sep 1997 11:36:19 +0200 hostname (2.02) unstable; urgency=low * a character now marks the end of the hostname if you set the hostname with the --file option. -- Peter Tobias Wed, 18 Jun 1997 15:04:49 +0200 hostname (2.01) unstable; urgency=low * converted to packaging standard 2.1.2.2 * minor fixes -- Peter Tobias Thu, 16 Jan 1997 01:00:34 +0100 hostname-3.23ubuntu2/debian/control0000664000000000000000000000100413561000230014302 0ustar Source: hostname Section: admin Priority: required Maintainer: Michael Meskes Standards-Version: 4.4.1 Build-Depends: debhelper-compat (= 12) Package: hostname Architecture: any Essential: yes Replaces: nis (<< 3.17-30) Breaks: nis (<< 3.17-30) Pre-Depends: ${shlibs:Depends}, ${misc:Depends} Description: utility to set/show the host name or domain name This package provides commands which can be used to display the system's DNS name, and to display or set its hostname or NIS domain name. hostname-3.23ubuntu2/debian/copyright0000664000000000000000000000217213234044046014653 0ustar This package was written by Peter Tobias on Thu, 16 Jan 1997 01:00:34 +0100. License: Copyright (C) 2009 Michael Meskes Copyright (C) 2004-2005 Graham Wilson Copyright (C) 1997 Bernd Eckenfels Copyright (C) 1997 Peter Tobias Copyright (C) 1996 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2 file. hostname-3.23ubuntu2/debian/dirs0000664000000000000000000000003113234044046013574 0ustar /bin /usr/share/man/man1 hostname-3.23ubuntu2/debian/rules0000775000000000000000000000312014127606000013766 0ustar #!/usr/bin/make -f # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 include /usr/share/dpkg/pkg-info.mk PRGVERSION := $(shell awk '/define VERSION/ { print substr($$3,2,length($$3)-2)}' hostname.c) MYVERSION := $(shell echo '$(DEB_VERSION)' | sed -e 's/\+.*//;s/ubuntu.*$$//;s/build.*$$//') export DEB_BUILD_MAINT_OPTIONS=hardening=+all CFLAGS = `dpkg-buildflags --get CFLAGS` CFLAGS += -Wall LDFLAGS = `dpkg-buildflags --get LDFLAGS` CPPFLAGS = `dpkg-buildflags --get CPPFLAGS` DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE)) CROSS=CC=$(DEB_HOST_GNU_TYPE)-gcc else CROSS= endif build: build-arch build-indep build-arch: build-stamp build-indep: build-stamp build-stamp: dh_testdir # Building package [ "$(MYVERSION)" = "$(PRGVERSION)" ] || exit 1 CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) $(CROSS) touch build-stamp clean: dh_testdir dh_testroot rm -f build-stamp # Cleaning package [ ! -f Makefile ] || $(MAKE) clean dh_clean install: build dh_testdir dh_testroot dh_prep dh_installdirs # Installing package $(MAKE) install BASEDIR=$(CURDIR)/debian/hostname $(CROSS) binary-indep: build install binary-arch: build install dh_testdir dh_testroot dh_installchangelogs dh_installdocs dh_install dh_strip dh_compress dh_fixperms dh_installdeb dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install hostname-3.23ubuntu2/debian/source/0000775000000000000000000000000013234044046014216 5ustar hostname-3.23ubuntu2/debian/source/format0000664000000000000000000000000413234044046015423 0ustar 1.0 hostname-3.23ubuntu2/hostname.10000664000000000000000000001631513353113642013403 0ustar .TH HOSTNAME 1 "2009-09-16" "net-tools" "Linux Programmer's Manual" .SH NAME hostname \- show or set the system's host name .br domainname \- show or set the system's NIS/YP domain name .br ypdomainname \- show or set the system's NIS/YP domain name .br nisdomainname \- show or set the system's NIS/YP domain name .br dnsdomainname \- show the system's DNS domain name .br .SH SYNOPSIS .B hostname .RB [ \-a|\-\-alias ] .RB [ \-d|\-\-domain ] .RB [ \-f|\-\-fqdn|\-\-long ] .RB [ \-A|\-\-all-fqdns ] .RB [ \-i|\-\-ip-address ] .RB [ \-I|\-\-all-ip-addresses ] .RB [ \-s|\-\-short ] .RB [ \-y|\-\-yp|\-\-nis ] .br .B hostname .RB [ \-b|\-\-boot ] .RB [ \-F|\-\-file\ filename ] .RB [ hostname ] .br .B hostname .RB [ \-h|\-\-help ] .RB [ \-V|\-\-version ] .PP .B domainname .RB [ nisdomain ] .RB [ \-F\ file ] .br .B ypdomainname .RB [ nisdomain ] .RB [ \-F\ file ] .br .B nisdomainname .RB [ nisdomain ] .RB [ \-F\ file ] .PP .B dnsdomainname .SH DESCRIPTION .B Hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name. .SS "GET NAME" When called without any arguments, the program displays the current names: .LP .B hostname will print the name of the system as returned by the .BR gethostname (2) function. .LP .B domainname will print the NIS domainname of the system. .B domainname uses the .BR gethostname (2) function, while .B ypdomainname and .B nisdomainname use the .BR getdomainname (2). .LP .B dnsdomainname will print the domain part of the FQDN (Fully Qualified Domain Name). The complete FQDN of the system is returned with .B hostname \-\-fqdn (but see the warnings in section .B THE FQDN below). .SS "SET NAME" When called with one argument or with the .B \-\-file option, the commands set the host name or the NIS/YP domain name. .B hostname uses the .BR sethostname (2) function, while all of the three .BR domainname , .B ypdomainname and .B nisdomainname use .BR setdomainname (2). Note, that this is effective only until the next reboot. Edit /etc/hostname for permanent change. .LP Note, that only the super-user can change the names. .LP It is not possible to set the FQDN or the DNS domain name with the .B dnsdomainname command (see .B THE FQDN below). .LP The host name is usually set once at system startup in .I /etc/init.d/hostname.sh (normally by reading the contents of a file which contains the host name, e.g. .IR /etc/hostname ). .SS THE FQDN The FQDN (Fully Qualified Domain Name) of the system is the name that the .BR resolver (3) returns for the host name, such as, .IR ursula.example.com . It is usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN using .B hostname \-\-fqdn or the domain name using .BR "dnsdomainname" . .LP You cannot change the FQDN with .B hostname or .BR dnsdomainname . .LP The recommended method of setting the FQDN is to make the hostname be an alias for the fully qualified name using .IR /etc/hosts , DNS, or NIS. For example, if the hostname was "ursula", one might have a line in .I /etc/hosts which reads .LP .RS 127.0.1.1 ursula.example.com ursula .RE .LP Technically: The FQDN is the name .BR getaddrinfo (3) returns for the host name returned by .BR gethostname (2). The DNS domain name is the part after the first dot. .LP Therefore it depends on the configuration of the resolver (usually in .IR /etc/host.conf ) how you can change it. Usually the hosts file is parsed before DNS or NIS, so it is most common to change the FQDN in .IR /etc/hosts . .LP If a machine has multiple network interfaces/addresses or is used in a mobile environment, then it may either have multiple FQDNs/domain names or none at all. Therefore avoid using .BR "hostname \-\-fqdn" , .B hostname \-\-domain and .BR "dnsdomainname" . .B hostname \-\-ip-address is subject to the same limitations so it should be avoided as well. .SH OPTIONS .TP .I "\-a, \-\-alias" Display the alias name of the host (if used). This option is deprecated and should not be used anymore. .TP .I "\-A, \-\-all-fqdns" Displays all FQDNs of the machine. This option enumerates all configured network addresses on all configured network interfaces, and translates them to DNS domain names. Addresses that cannot be translated (i.e. because they do not have an appropriate reverse IP entry) are skipped. Note that different addresses may resolve to the same name, therefore the output may contain duplicate entries. Do not make any assumptions about the order of the output. .TP .I "\-b, \-\-boot" Always set a hostname; this allows the file specified by \fI\-F\fR to be non-existent or empty, in which case the default hostname \fIlocalhost\fR will be used if none is yet set. .TP .I "\-d, \-\-domain" Display the name of the DNS domain. Don't use the command .B domainname to get the DNS domain name because it will show the NIS domain name and not the DNS domain name. Use .B dnsdomainname instead. See the warnings in section .B THE FQDN above, and avoid using this option. .TP .I "\-f, \-\-fqdn, \-\-long" Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain name. Unless you are using bind or NIS for host lookups you can change the FQDN and the DNS domain name (which is part of the FQDN) in the \fI/etc/hosts\fR file. See the warnings in section .B THE FQDN above und use .B hostname \-\-all-fqdns instead wherever possible. .TP .I "\-F, \-\-file filename" Read the host name from the specified file. Comments (lines starting with a `#') are ignored. .TP .I "\-i, \-\-ip-address" Display the network address(es) of the host name. Note that this works only if the host name can be resolved. Avoid using this option; use .B hostname \-\-all-ip-addresses instead. .TP .I "\-I, \-\-all-ip-addresses" Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option \fI\-i\fR, this option does not depend on name resolution. Do not make any assumptions about the order of the output. .TP .I "\-s, \-\-short" Display the short host name. This is the host name cut at the first dot. .TP .I "\-V, \-\-version" Print version information on standard output and exit successfully. .TP .I "\-y, \-\-yp, \-\-nis" Display the NIS domain name. If a parameter is given (or .B \-\-file name ) then root can also set a new NIS domain. .TP .I "\-h, \-\-help" Print a usage message and exit. .SH NOTES The address families .B hostname tries when looking up the FQDN, aliases and network addresses of the host are determined by the configuration of your resolver. For instance, on GNU Libc systems, the resolver can be instructed to try IPv6 lookups first by using the .B inet6 option in .BR /etc/resolv.conf . .SH FILES .B /etc/hostname Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname. .LP .B /etc/hosts Usually, this is where one sets the domain name by aliasing the host name to the FQDN. .SH AUTHORS Peter Tobias, .br Bernd Eckenfels, (NIS and manpage). .br Michael Meskes, .br hostname-3.23ubuntu2/hostname.c0000664000000000000000000003152613561000230013453 0ustar /* * hostname This file contains an implementation of the command * that maintains the host name and the domain name. It * is also used to show the FQDN and the IP-Addresses. * * Usage: hostname [-a|-A|-d|-f|-i|-I|-s|-y] * hostname [-h|-V] * hostname [-b] {name|-F file} * dnsdomainname * domainname * ypdomainname * nisdomainname * * Authors: Peter Tobias * Bernd Eckenfels * Graham Wilson * Michael Meskes * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation; either version 2 of the License, or (at * your option) any later version. * * The localdomain and localhost functions are copyright * (C) 1996 Free Software Foundation, Inc. and were * written by Miles Bader and * Marcus Brinkmann . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define VERSION "3.23" enum type_t { DEFAULT, DNS, FQDN, SHORT, ALIAS, IP, NIS, NIS_DEF, ALL_FQDNS, ALL_IPS }; char *progname; /* * Return the name of the nis default domain. Same as localdomain below, * but reports failure for unset domain. */ char * localnisdomain() { /* The historical NIS limit is 1024, the limit on Linux is 64. We go * with the limit suggested for getnameinfo(), which should be 1025. */ static char buf[NI_MAXHOST]; int myerror = 0; myerror = getdomainname(buf, sizeof buf); if (myerror || strcmp(buf, "(none)") == 0) { printf("%s: Local domain name not set\n", progname); exit (1); } return buf; } /* * Return the name of the localdomain. This is just a wrapper for * getdomainname, which takes care of allocating a big enough buffer, and * caches the result after the first call (so the result should be copied * before modification). If something goes wrong, program exits. */ char * localdomain() { char *buf = 0; size_t buf_len = 0; int myerror = 0; do { errno = 0; if (buf) { buf_len += buf_len; if ((buf = realloc (buf, buf_len)) == NULL) err(1, NULL); } else { buf_len = 128; /* Initial guess */ if ((buf = malloc (buf_len)) == NULL) err(1, NULL); } } while (((myerror = getdomainname(buf, buf_len)) == 0 && !memchr (buf, '\0', buf_len)) || errno == ENAMETOOLONG); /* getdomainname failed, abort. */ if (myerror) err(1, NULL); return buf; } /* * Return the name of the localhost. This is just a wrapper for gethostname, * which takes care of allocating a big enough buffer, and caches the result * after the first call (so the result should be copied before modification). * If something goes wrong, program exits. */ char * localhost() { char *buf = 0; size_t buf_len = 0; int myerror = 0; do { errno = 0; if (buf) { buf_len += buf_len; if ((buf = realloc (buf, buf_len)) == NULL) err(1, NULL); } else { buf_len = 128; /* Initial guess */ if ((buf = malloc (buf_len)) == NULL) err(1, NULL); } } while (((myerror = gethostname(buf, buf_len)) == 0 && !memchr (buf, '\0', buf_len)) || errno == ENAMETOOLONG); /* gethostname failed, abort. */ if (myerror) err(1, NULL); return buf; } void usage(FILE *stream) { fprintf(stream, "Usage: hostname [-b] {hostname|-F file} set host name (from file)\n" " hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name\n" " hostname display host name\n" "\n" " {yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)\n" " {yp,nis,}domainname display NIS domain name\n" "\n" " dnsdomainname display dns domain name\n" "\n" " hostname -V|--version|-h|--help print info and exit\n" "\n" "Program name:\n" " {yp,nis,}domainname=hostname -y\n" " dnsdomainname=hostname -d\n" "\n" "Program options:\n" " -a, --alias alias names\n" " -A, --all-fqdns all long host names (FQDNs)\n" " -b, --boot set default hostname if none available\n" " -d, --domain DNS domain name\n" " -f, --fqdn, --long long host name (FQDN)\n" " -F, --file read host name or NIS domain name from given file\n" " -i, --ip-address addresses for the host name\n" " -I, --all-ip-addresses all addresses for the host\n" " -s, --short short host name\n" " -y, --yp, --nis NIS/YP domain name\n" "\n" "Description:\n" " This command can get or set the host name or the NIS domain name. You can\n" " also get the DNS domain or the FQDN (fully qualified domain name).\n" " Unless you are using bind or NIS for host lookups you can change the\n" " FQDN (Fully Qualified Domain Name) and the DNS domain name (which is\n" " part of the FQDN) in the /etc/hosts file.\n"); exit(-1); } /* * Check the format of a user-specified hostname. Uses the rules from RFC 1035, * section 2.3.1. */ int check_name(char *name) { int i, len = strlen(name); /* Handle leading and trailing hyphen now. */ if (!len || !isalnum(name[0]) || !isalnum(name[len-1])) return 0; for (i = 0; i < len; i++) { if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') return 0; if (name[i] == '-' && (name[i - 1] == '.' || name[i + 1] == '.')) return 0; if (name[i] == '.' && name[i - 1] == '.') return 0; } return 1; } void set_name(enum type_t type, char *name) { int i; switch (type) { case DEFAULT: /* Whitespaces are invalid characters in a hostname. */ /* Thus remove trailing and leading whitespaces. */ while (isspace(*name)) { name++; } for (i = strlen(name) - 1; i >= 0 && isspace(name[i]); i--); name[i+1] = '\0'; /* Now check for a valid name. */ if (!check_name(name)) errx(1, "the specified hostname is invalid"); if (sethostname(name, strlen(name))) { if (errno == EPERM) errx(1, "you must be root to change the host name"); else if (errno == EINVAL) errx(1, "name too long"); } break; case NIS: case NIS_DEF: if (setdomainname(name, strlen(name))) { if (errno == EPERM) errx(1, "you must be root to change the domain name"); else if (errno == EINVAL) errx(1, "name too long"); } break; default: /* * Only the host name and the domain name can be set using this * command. */ usage(stderr); } } void show_name(enum type_t type) { struct addrinfo *res; struct addrinfo hints; struct ifaddrs *ifa, *ifap; char *p; int ret; /* Handle a few cases specially. */ switch(type) { case DEFAULT: printf("%s\n", localhost()); break; case SHORT: p = localhost(); *(strchrnul(p, '.')) = '\0'; printf("%s\n", p); break; case NIS: printf("%s\n", localdomain()); break; case NIS_DEF: printf("%s\n", localnisdomain()); break; case ALL_IPS: case ALL_FQDNS: { char buf[NI_MAXHOST]; int flags, ret, family, addrlen; /* What kind of information do we want from getnameinfo()? */ flags = (type == ALL_IPS) ? NI_NUMERICHOST : NI_NAMEREQD; if (getifaddrs(&ifa) != 0) errx(1, "%s", strerror(errno)); for (ifap = ifa; ifap != NULL; ifap = ifap->ifa_next) { /* Skip interfaces that have no configured addresses */ if (ifap->ifa_addr == NULL) continue; /* Skip the loopback interface */ if (ifap->ifa_flags & IFF_LOOPBACK) continue; /* Skip interfaces that are not UP */ if (!(ifap->ifa_flags & IFF_UP)) continue; /* Only handle IPv4 and IPv6 addresses */ family = ifap->ifa_addr->sa_family; if (family != AF_INET && family != AF_INET6) continue; addrlen = (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); /* Skip IPv6 link-local addresses */ if (family == AF_INET6) { struct sockaddr_in6 *sin6; sin6 = (struct sockaddr_in6 *)ifap->ifa_addr; if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&sin6->sin6_addr)) continue; } ret = getnameinfo(ifap->ifa_addr, addrlen, buf, sizeof(buf), NULL, 0, flags); /* Just skip addresses that cannot be translated */ if (ret != 0) { if (type != ALL_FQDNS && ret != EAI_NONAME) errx(1, "%s", gai_strerror(ret)); } else printf("%s ", buf); } printf("\n"); freeifaddrs(ifa); break; } default: memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_CANONNAME; p = localhost(); if ((ret = getaddrinfo(p, NULL, &hints, &res)) != 0) errx(1, "%s", gai_strerror(ret)); p = strchr(res->ai_canonname, '.'); switch (type) { case ALIAS: { struct hostent *hp; int i; if ((hp = gethostbyname(localhost())) == NULL) errx(1, "%s", hstrerror(h_errno)); for (i = 0; hp->h_aliases[i]; i++) { if (i > 0) printf(" "); printf("%s", hp->h_aliases[i]); } printf("\n"); break; } case IP: { char buf[INET6_ADDRSTRLEN]; int ret; struct addrinfo *walk; for (walk = res; walk != NULL; walk = walk->ai_next) { if ((ret = getnameinfo(walk->ai_addr, walk->ai_addrlen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST)) != 0) errx(1, "%s", gai_strerror(ret)); if (walk != res) printf(" "); printf("%s", buf); } printf("\n"); break; } case DNS: if (p != NULL) printf("%s\n", ++p); break; case FQDN: printf("%s\n", res->ai_canonname); break; default: break; } break; } } char * read_file(char *filename, int boot) { struct stat st; FILE *fp; char *buf; if ((fp = fopen(filename, "r")) == NULL) { if (boot) return NULL; else err(1, NULL); } if (fstat(fileno(fp), &st) == -1 || (buf = (char *) calloc(st.st_size + 1, sizeof(char))) == NULL) err(1, NULL); while (fgets(buf, st.st_size + 1, fp) != NULL) { char *p; if (buf[0] == '\n' || buf[0] == '#') continue; if ((p = strchr(buf, '\n')) != NULL) *p = '\0'; break; } fclose(fp); return buf; } int main(int argc, char **argv) { char *file = NULL, *name = NULL; enum type_t type = DEFAULT; int boot = 0; int o; static const struct option long_options[] = { {"domain", no_argument, 0, 'd'}, {"boot", no_argument, 0, 'b'}, {"file", required_argument, 0, 'F'}, {"fqdn", no_argument, 0, 'f'}, {"all-fqdns", no_argument, 0, 'A'}, {"help", no_argument, 0, 'h'}, {"long", no_argument, 0, 'f'}, {"short", no_argument, 0, 's'}, {"version", no_argument, 0, 'V'}, {"alias", no_argument, 0, 'a'}, {"ip-address", no_argument, 0, 'i'}, {"all-ip-addresses", no_argument, 0, 'I'}, {"nis", no_argument, 0, 'y'}, {"yp", no_argument, 0, 'y'}, {0, 0, 0, 0} }; /* If called as 'dnsdomainname', by default show the DNS domain name. */ progname = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0]; if (!strcmp(progname, "dnsdomainname")) type = DNS; else if (!strcmp(progname, "domainname")) type = NIS; else if (!strcmp(progname, "ypdomainname")) type = NIS_DEF; else if (!strcmp(progname, "nisdomainname")) type = NIS_DEF; while((o = getopt_long(argc, argv, "aAdfbF:h?iIsVy", long_options, NULL)) != -1) switch (o) { case 'd': type = DNS; break; case 'a': type = ALIAS; break; case 'f': type = FQDN; break; case 'A': type = ALL_FQDNS; break; case 'i': type = IP; break; case 'I': type = ALL_IPS; break; case 's': type = SHORT; break; case 'y': type = NIS_DEF; break; case 'b': boot = 1; break; case 'F': file = optarg; break; case 'V': printf("hostname %s\n", VERSION); return 0; case '?': case 'h': usage(stdout); break; default: usage(stderr); } /* * Hostname may be read from a file, it's ok for this file to not * exist or be empty if -b is given in which case we default to * "localhost" if there is not one already set. */ if (file) { name = read_file(file, boot); if (boot && (name == NULL || name[0] == '\0')) { free(name); name = localhost(); if (name[0] == '\0' || !strcmp(name,"(none)")) strcpy(name, "localhost"); } } /* Otherwise the hostname is the first non-option argument. */ if (optind < argc) { /* * It is an error to specify a host name as an argument, and to * be read from a file. */ if (name) usage(stderr); if ((name = strdup(argv[optind])) == NULL) err(1, NULL); optind++; } /* Check for any remaining arguments. */ if (optind < argc) usage(stderr); if (name) { set_name(type, name); free(name); } else show_name(type); return 0; } /* vim: set noexpandtab: */