xref: /freebsd/lib/libc/gen/getdomainname.c (revision cf8e5289a110954600f135024d1515a77d0ae34d)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro 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>
36*cf8e5289SKyle Evans #include <ssp/ssp.h>
37fba5b1ccSGarrett Wollman 
38fba5b1ccSGarrett Wollman int
__ssp_real(getdomainname)39*cf8e5289SKyle Evans __ssp_real(getdomainname)(char *name, int namelen)
402e18dcd9SGarrett Wollman {
412e18dcd9SGarrett Wollman 	int mib[2];
422e18dcd9SGarrett Wollman 	size_t size;
432e18dcd9SGarrett Wollman 
442e18dcd9SGarrett Wollman 	mib[0] = CTL_KERN;
452b3a38f6SGarrett Wollman 	mib[1] = KERN_NISDOMAINNAME;
462e18dcd9SGarrett Wollman 	size = namelen;
472e18dcd9SGarrett Wollman 	if (sysctl(mib, 2, name, &size, NULL, 0) == -1)
482e18dcd9SGarrett Wollman 		return (-1);
492e18dcd9SGarrett Wollman 	return (0);
502e18dcd9SGarrett Wollman }
51