gethostname.c revision 1573
1218887Sdim/* 2218887Sdim * Copyright (c) 1989, 1993 3218887Sdim * The Regents of the University of California. All rights reserved. 4218887Sdim * 5218887Sdim * Redistribution and use in source and binary forms, with or without 6218887Sdim * modification, are permitted provided that the following conditions 7218887Sdim * are met: 8218887Sdim * 1. Redistributions of source code must retain the above copyright 9218887Sdim * notice, this list of conditions and the following disclaimer. 10218887Sdim * 2. Redistributions in binary form must reproduce the above copyright 11218887Sdim * notice, this list of conditions and the following disclaimer in the 12218887Sdim * documentation and/or other materials provided with the distribution. 13218887Sdim * 3. All advertising materials mentioning features or use of this software 14252723Sdim * must display the following acknowledgement: 15245431Sdim * This product includes software developed by the University of 16226890Sdim * California, Berkeley and its contributors. 17218887Sdim * 4. Neither the name of the University nor the names of its contributors 18218887Sdim * may be used to endorse or promote products derived from this software 19218887Sdim * without specific prior written permission. 20218887Sdim * 21218887Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22218887Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23218887Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24235633Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25221345Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26221345Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27218887Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28218887Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29218887Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30226890Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31218887Sdim * SUCH DAMAGE. 32218887Sdim */ 33218887Sdim 34218887Sdim#if defined(LIBC_SCCS) && !defined(lint) 35218887Sdimstatic char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; 36235633Sdim#endif /* LIBC_SCCS and not lint */ 37218887Sdim 38235633Sdim#include <sys/param.h> 39218887Sdim#include <sys/sysctl.h> 40235633Sdim 41218887Sdimlong 42218887Sdimgethostname(name, namelen) 43218887Sdim char *name; 44218887Sdim int namelen; 45235633Sdim{ 46218887Sdim int mib[2]; 47218887Sdim size_t size; 48218887Sdim 49218887Sdim mib[0] = CTL_KERN; 50218887Sdim mib[1] = KERN_HOSTNAME; 51218887Sdim size = namelen; 52218887Sdim if (sysctl(mib, 2, name, &size, NULL, 0) == -1) 53218887Sdim return (-1); 54226890Sdim return (0); 55218887Sdim} 56218887Sdim