'\" te .\" 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. .TH gethostname 3C "22 Mar 2004" "SunOS 5.11" "Standard C Library Functions" .SH NAME gethostname, sethostname \- get or set name of current host .SH SYNOPSIS .LP .nf #include \fBint\fR \fBgethostname\fR(\fBchar *\fR\fIname\fR, \fBint\fR \fInamelen\fR); .fi .LP .nf \fBint\fR \fBsethostname\fR(\fBchar *\fR\fIname\fR, \fBint\fR \fInamelen\fR); .fi .SH DESCRIPTION .sp .LP The \fBgethostname()\fR function returns the standard host name for the current processor, as previously set by \fBsethostname()\fR. The \fInamelen\fR argument specifies the size of the array pointed to by \fIname\fR. The returned name is null-terminated unless insufficient space is provided. .sp .LP The \fBsethostname()\fR function sets the name of the host machine to be \fIname\fR, which has length \fInamelen\fR. This call is restricted to the superuser and is normally used only when the system is bootstrapped. .sp .LP Host names are limited to \fBMAXHOSTNAMELEN\fR characters, currently 256, defined in the <\fBnetdb.h\fR> header. .SH RETURN VALUES .sp .LP Upon successful completion, \fBgethostname()\fR and \fBsethostname()\fR return 0. Otherwise, they return \(mi1 and set \fBerrno\fR to indicate the error. .SH ERRORS .sp .LP The \fBgethostname()\fR and \fBsethostname()\fR functions will fail if: .sp .ne 2 .mk .na \fB\fBEFAULT\fR\fR .ad .RS 10n .rt The \fIname\fR or \fInamelen\fR argument gave an invalid address. .RE .sp .LP The \fBsethostname()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBEPERM\fR\fR .ad .RS 9n .rt The {\fBPRIV_SYS_ADMIN\fR} privilege was not asserted in the effective set of the calling process. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityStandard _ MT-LevelMT-Safe .TE .SH SEE ALSO .sp .LP \fBsysinfo\fR(2), \fBuname\fR(2), \fBgethostid\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)