1.\" $OpenBSD: getdomainname.3,v 1.23 2007/05/31 19:19:28 jmc Exp $ 2.\" 3.\" Copyright (c) 1983, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.Dd $Mdocdate: May 31 2007 $ 31.Dt GETDOMAINNAME 3 32.Os 33.Sh NAME 34.Nm getdomainname , 35.Nm setdomainname 36.Nd get/set YP domain name of current host 37.Sh SYNOPSIS 38.Fd #include <unistd.h> 39.Ft int 40.Fn getdomainname "char *name" "size_t namelen" 41.Ft int 42.Fn setdomainname "const char *name" "size_t namelen" 43.Sh DESCRIPTION 44The 45.Fn getdomainname 46function returns the YP domain name for the current processor, as 47previously set by 48.Fn setdomainname . 49The parameter 50.Fa namelen 51specifies the size of the 52.Fa name 53array. 54If insufficient space is provided, the returned name is truncated. 55The returned name is always NUL terminated. 56.Pp 57.Fn setdomainname 58sets the domain name of the host machine to be 59.Fa name , 60which has length 61.Fa namelen . 62This call is restricted to the superuser and 63is normally used only when the system is bootstrapped. 64.Sh RETURN VALUES 65If the call succeeds a value of 0 is returned. 66If the call fails, a value of \-1 is returned and an error code is 67placed in the global variable 68.Va errno . 69.Sh ERRORS 70The following errors may be returned by these calls: 71.Bl -tag -width Er 72.It Bq Er EFAULT 73The 74.Fa name 75parameter gave an 76invalid address. 77.It Bq Er EPERM 78The caller tried to set the domain name and was not the superuser. 79.El 80.Sh SEE ALSO 81.Xr domainname 1 , 82.Xr gethostid 3 , 83.Xr gethostname 3 , 84.Xr sysctl 3 , 85.Xr sysctl 8 , 86.Xr yp 8 87.Sh HISTORY 88The 89.Nm 90function call appeared in 91SunOS 3.x. 92.Sh BUGS 93Domain names are limited to 94.Dv MAXHOSTNAMELEN 95(from 96.Ao Pa sys/param.h Ac ) 97characters, currently 256. 98This includes the terminating NUL character. 99.Pp 100If the buffer passed to 101.Fn getdomainname 102is too small, other operating systems may not guarantee termination with NUL. 103