xref: /freebsd/lib/libc/gen/setdomainname.c (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
1*8a16b7a1SPedro F. Giffuni /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
42e18dcd9SGarrett Wollman  * Copyright (c) 1989, 1993
52e18dcd9SGarrett Wollman  *	The Regents of the University of California.  All rights reserved.
62e18dcd9SGarrett Wollman  *
72e18dcd9SGarrett Wollman  * Redistribution and use in source and binary forms, with or without
82e18dcd9SGarrett Wollman  * modification, are permitted provided that the following conditions
92e18dcd9SGarrett Wollman  * are met:
102e18dcd9SGarrett Wollman  * 1. Redistributions of source code must retain the above copyright
112e18dcd9SGarrett Wollman  *    notice, this list of conditions and the following disclaimer.
122e18dcd9SGarrett Wollman  * 2. Redistributions in binary form must reproduce the above copyright
132e18dcd9SGarrett Wollman  *    notice, this list of conditions and the following disclaimer in the
142e18dcd9SGarrett Wollman  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
162e18dcd9SGarrett Wollman  *    may be used to endorse or promote products derived from this software
172e18dcd9SGarrett Wollman  *    without specific prior written permission.
182e18dcd9SGarrett Wollman  *
192e18dcd9SGarrett Wollman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
202e18dcd9SGarrett Wollman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
212e18dcd9SGarrett Wollman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
222e18dcd9SGarrett Wollman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
232e18dcd9SGarrett Wollman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
242e18dcd9SGarrett Wollman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
252e18dcd9SGarrett Wollman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
262e18dcd9SGarrett Wollman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
272e18dcd9SGarrett Wollman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
282e18dcd9SGarrett Wollman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
292e18dcd9SGarrett Wollman  * SUCH DAMAGE.
302e18dcd9SGarrett Wollman  */
312e18dcd9SGarrett Wollman 
322e18dcd9SGarrett Wollman #include <sys/param.h>
332e18dcd9SGarrett Wollman #include <sys/sysctl.h>
342e18dcd9SGarrett Wollman 
35fba5b1ccSGarrett Wollman #include <unistd.h>
36fba5b1ccSGarrett Wollman 
37fba5b1ccSGarrett Wollman int
setdomainname(const char * name,int namelen)382e18dcd9SGarrett Wollman setdomainname(const char *name, int namelen)
392e18dcd9SGarrett Wollman {
402e18dcd9SGarrett Wollman 	int mib[2];
412e18dcd9SGarrett Wollman 
422e18dcd9SGarrett Wollman 	mib[0] = CTL_KERN;
432b3a38f6SGarrett Wollman 	mib[1] = KERN_NISDOMAINNAME;
442e18dcd9SGarrett Wollman 	if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1)
452e18dcd9SGarrett Wollman 		return (-1);
462e18dcd9SGarrett Wollman 	return (0);
472e18dcd9SGarrett Wollman }
48