getdomainname.c revision 90039
1275970Scy/* 2275970Scy * Copyright (c) 1989, 1993 3275970Scy * The Regents of the University of California. All rights reserved. 4275970Scy * 5275970Scy * Redistribution and use in source and binary forms, with or without 6275970Scy * modification, are permitted provided that the following conditions 7275970Scy * are met: 8275970Scy * 1. Redistributions of source code must retain the above copyright 9275970Scy * notice, this list of conditions and the following disclaimer. 10275970Scy * 2. Redistributions in binary form must reproduce the above copyright 11275970Scy * notice, this list of conditions and the following disclaimer in the 12275970Scy * documentation and/or other materials provided with the distribution. 13275970Scy * 3. All advertising materials mentioning features or use of this software 14275970Scy * must display the following acknowledgement: 15275970Scy * This product includes software developed by the University of 16275970Scy * California, Berkeley and its contributors. 17275970Scy * 4. Neither the name of the University nor the names of its contributors 18275970Scy * may be used to endorse or promote products derived from this software 19275970Scy * without specific prior written permission. 20275970Scy * 21275970Scy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22275970Scy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23275970Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24275970Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25275970Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26275970Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27275970Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28275970Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29275970Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30275970Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31275970Scy * SUCH DAMAGE. 32275970Scy */ 33275970Scy 34330567Sgordon#if defined(LIBC_SCCS) && !defined(lint) 35275970Scystatic char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; 36275970Scy#endif /* LIBC_SCCS and not lint */ 37275970Scy#include <sys/cdefs.h> 38275970Scy__FBSDID("$FreeBSD: head/lib/libc/gen/getdomainname.c 90039 2002-02-01 00:57:29Z obrien $"); 39275970Scy 40275970Scy#include <sys/param.h> 41275970Scy#include <sys/sysctl.h> 42275970Scy 43275970Scy#include <unistd.h> 44275970Scy 45275970Scyint 46275970Scygetdomainname(name, namelen) 47275970Scy char *name; 48275970Scy int namelen; 49275970Scy{ 50275970Scy int mib[2]; 51275970Scy size_t size; 52275970Scy 53275970Scy mib[0] = CTL_KERN; 54275970Scy mib[1] = KERN_NISDOMAINNAME; 55275970Scy size = namelen; 56275970Scy if (sysctl(mib, 2, name, &size, NULL, 0) == -1) 57275970Scy return (-1); 58275970Scy return (0); 59275970Scy} 60275970Scy