xref: /freebsd/lib/libc/gen/setdomainname.c (revision fba5b1cc9777dbe10a839d58450bce9a0d961b65)
12e18dcd9SGarrett Wollman /*
22e18dcd9SGarrett Wollman  * Copyright (c) 1989, 1993
32e18dcd9SGarrett Wollman  *	The Regents of the University of California.  All rights reserved.
42e18dcd9SGarrett Wollman  *
52e18dcd9SGarrett Wollman  * Redistribution and use in source and binary forms, with or without
62e18dcd9SGarrett Wollman  * modification, are permitted provided that the following conditions
72e18dcd9SGarrett Wollman  * are met:
82e18dcd9SGarrett Wollman  * 1. Redistributions of source code must retain the above copyright
92e18dcd9SGarrett Wollman  *    notice, this list of conditions and the following disclaimer.
102e18dcd9SGarrett Wollman  * 2. Redistributions in binary form must reproduce the above copyright
112e18dcd9SGarrett Wollman  *    notice, this list of conditions and the following disclaimer in the
122e18dcd9SGarrett Wollman  *    documentation and/or other materials provided with the distribution.
132e18dcd9SGarrett Wollman  * 3. All advertising materials mentioning features or use of this software
142e18dcd9SGarrett Wollman  *    must display the following acknowledgement:
152e18dcd9SGarrett Wollman  *	This product includes software developed by the University of
162e18dcd9SGarrett Wollman  *	California, Berkeley and its contributors.
172e18dcd9SGarrett Wollman  * 4. Neither the name of the University nor the names of its contributors
182e18dcd9SGarrett Wollman  *    may be used to endorse or promote products derived from this software
192e18dcd9SGarrett Wollman  *    without specific prior written permission.
202e18dcd9SGarrett Wollman  *
212e18dcd9SGarrett Wollman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
222e18dcd9SGarrett Wollman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
232e18dcd9SGarrett Wollman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
242e18dcd9SGarrett Wollman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
252e18dcd9SGarrett Wollman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
262e18dcd9SGarrett Wollman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
272e18dcd9SGarrett Wollman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
282e18dcd9SGarrett Wollman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
292e18dcd9SGarrett Wollman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
302e18dcd9SGarrett Wollman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
312e18dcd9SGarrett Wollman  * SUCH DAMAGE.
322e18dcd9SGarrett Wollman  */
332e18dcd9SGarrett Wollman 
342e18dcd9SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint)
352e18dcd9SGarrett Wollman /*
362e18dcd9SGarrett Wollman static char sccsid[] = "From: @(#)sethostname.c	8.1 (Berkeley) 6/4/93";
372e18dcd9SGarrett Wollman */
382e18dcd9SGarrett Wollman static const char rcsid[] =
39fba5b1ccSGarrett Wollman   "$Id: setdomainname.c,v 1.1 1994/08/08 00:40:24 wollman Exp $";
402e18dcd9SGarrett Wollman #endif /* LIBC_SCCS and not lint */
412e18dcd9SGarrett Wollman 
422e18dcd9SGarrett Wollman #include <sys/param.h>
432e18dcd9SGarrett Wollman #include <sys/sysctl.h>
442e18dcd9SGarrett Wollman 
45fba5b1ccSGarrett Wollman #include <unistd.h>
46fba5b1ccSGarrett Wollman 
47fba5b1ccSGarrett Wollman int
482e18dcd9SGarrett Wollman setdomainname(const char *name, int namelen)
492e18dcd9SGarrett Wollman {
502e18dcd9SGarrett Wollman 	int mib[2];
512e18dcd9SGarrett Wollman 
522e18dcd9SGarrett Wollman 	mib[0] = CTL_KERN;
532e18dcd9SGarrett Wollman 	mib[1] = KERN_DOMAINNAME;
542e18dcd9SGarrett Wollman 	if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1)
552e18dcd9SGarrett Wollman 		return (-1);
562e18dcd9SGarrett Wollman 	return (0);
572e18dcd9SGarrett Wollman }
58