2 .\" Copyright 2015 Nexenta Systems, Inc. All rights reserved.
3 .\" Copyright (c) 1983 Regents of the University of California. All rights reserved. The Berkeley software License Agreement specifies the terms and conditions for redistribution. Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
4 .TH GETHOSTNAME 3C "Feb 7, 2015"
6 gethostname, sethostname \- get or set name of current host
12 \fBint\fR \fBgethostname\fR(\fBchar *\fR\fIname\fR, \fBint\fR \fInamelen\fR);
17 \fBint\fR \fBsethostname\fR(\fBchar *\fR\fIname\fR, \fBint\fR \fInamelen\fR);
22 The \fBgethostname()\fR function returns the standard host name for the current
23 machine, as previously set by \fBsethostname()\fR. The \fInamelen\fR
24 argument specifies the size of the array pointed to by \fIname\fR. The returned
25 name is null-terminated unless insufficient space is provided.
28 The \fBsethostname()\fR function sets the name of the host machine to be
29 \fIname\fR, which has length \fInamelen\fR. This call is restricted to the
30 superuser and is normally used only when the system is bootstrapped.
33 Host names are limited to \fBMAXHOSTNAMELEN\fR characters, currently 256,
34 defined in the <\fBnetdb.h\fR> header.
37 Upon successful completion, \fBgethostname()\fR and \fBsethostname()\fR return
38 0. Otherwise, they return \(mi1 and set \fBerrno\fR to indicate the error.
41 The \fBgethostname()\fR and \fBsethostname()\fR functions will fail if:
48 The \fIname\fR or \fInamelen\fR argument gave an invalid address.
53 The \fBsethostname()\fR function will fail if:
60 The {\fBPRIV_SYS_ADMIN\fR} privilege was not asserted in the effective set of
66 See \fBattributes\fR(5) for descriptions of the following attributes:
74 ATTRIBUTE TYPE ATTRIBUTE VALUE
76 Interface Stability Standard
83 \fBsysinfo\fR(2), \fBuname\fR(2), \fBgethostid\fR(3C), \fBattributes\fR(5),