summaryrefslogtreecommitdiff
path: root/usr/src/cmd/hostname
diff options
context:
space:
mode:
authorstevel <none@none>2007-01-05 09:47:12 -0800
committerstevel <none@none>2007-01-05 09:47:12 -0800
commit20d159bb22d487d2a4feb5d283a2b7d832bff8d5 (patch)
tree55f26fb1f410a4e45674498dc6abd4c16a8448cd /usr/src/cmd/hostname
parent6d2b079bc5b60a8506ad6223072b074b11db4a7f (diff)
downloadillumos-joyent-20d159bb22d487d2a4feb5d283a2b7d832bff8d5.tar.gz
6442524 *hostname* hostname(1) should use set/gethostname(3c) rather than sysinfo(2)
Contributed by Stephen Potter <spp@unixsa.net>
Diffstat (limited to 'usr/src/cmd/hostname')
-rw-r--r--usr/src/cmd/hostname/hostname.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/usr/src/cmd/hostname/hostname.c b/usr/src/cmd/hostname/hostname.c
index 4c680d64e0..1110aa7ba2 100644
--- a/usr/src/cmd/hostname/hostname.c
+++ b/usr/src/cmd/hostname/hostname.c
@@ -29,12 +29,13 @@
* contributors.
*/
-/* Portions Copyright 2006 Jeremy Teo */
-
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
+/* Portions Copyright 2007 Jeremy Teo */
+/* Portions Copyright 2006 Stephen P. Potter */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
@@ -44,8 +45,7 @@
#include <libgen.h>
#include <stdlib.h>
#include <errno.h>
-#include <sys/utsname.h>
-#include <sys/systeminfo.h>
+#include <netdb.h>
#ifndef TEXT_DOMAIN /* should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* use this only if it wasn't */
@@ -65,7 +65,7 @@ int
main(int argc, char *argv[])
{
char *nodename = NULL;
- char c_hostname[SYS_NMLN];
+ char c_hostname[MAXHOSTNAMELEN];
int optlet;
char *optstring = "?";
@@ -86,13 +86,13 @@ main(int argc, char *argv[])
* if called with no options, just print out the hostname/nodename
*/
if (argc <= optind) {
- if (sysinfo(SI_HOSTNAME, c_hostname, SYS_NMLN)) {
- (void) fprintf(stdout, "%s\n", c_hostname);
- } else {
+ if (gethostname(c_hostname, sizeof (c_hostname)) < 0) {
(void) fprintf(stderr,
gettext("%s: unable to obtain hostname\n"),
basename(progname));
exit(1);
+ } else {
+ (void) fprintf(stdout, "%s\n", c_hostname);
}
} else {
/*
@@ -103,7 +103,7 @@ main(int argc, char *argv[])
usage(); /* too many arguments */
nodename = argv[optind];
- if (sysinfo(SI_SET_HOSTNAME, nodename, strlen(nodename)) < 0) {
+ if (sethostname(nodename, strlen(nodename)) < 0) {
int err = errno;
(void) fprintf(stderr,
gettext("%s: error in setting name: %s\n"),