1*b91680c1Satatat /* $NetBSD: sethostid.c,v 1.7 2004/04/19 13:16:42 atatat Exp $ */
25f34d8e3Schristos
3081527a8Scgd /*
4081527a8Scgd * Copyright (c) 1989, 1993
5081527a8Scgd * The Regents of the University of California. All rights reserved.
6081527a8Scgd *
7081527a8Scgd * Redistribution and use in source and binary forms, with or without
8081527a8Scgd * modification, are permitted provided that the following conditions
9081527a8Scgd * are met:
10081527a8Scgd * 1. Redistributions of source code must retain the above copyright
11081527a8Scgd * notice, this list of conditions and the following disclaimer.
12081527a8Scgd * 2. Redistributions in binary form must reproduce the above copyright
13081527a8Scgd * notice, this list of conditions and the following disclaimer in the
14081527a8Scgd * documentation and/or other materials provided with the distribution.
15eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
16081527a8Scgd * may be used to endorse or promote products derived from this software
17081527a8Scgd * without specific prior written permission.
18081527a8Scgd *
19081527a8Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20081527a8Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21081527a8Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22081527a8Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23081527a8Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24081527a8Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25081527a8Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26081527a8Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27081527a8Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28081527a8Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29081527a8Scgd * SUCH DAMAGE.
30081527a8Scgd */
31081527a8Scgd
325f34d8e3Schristos #include <sys/cdefs.h>
33081527a8Scgd #if defined(LIBC_SCCS) && !defined(lint)
345f34d8e3Schristos #if 0
35081527a8Scgd static char sccsid[] = "@(#)sethostid.c 8.1 (Berkeley) 6/2/93";
365f34d8e3Schristos #else
37*b91680c1Satatat __RCSID("$NetBSD: sethostid.c,v 1.7 2004/04/19 13:16:42 atatat Exp $");
385f34d8e3Schristos #endif
39081527a8Scgd #endif /* LIBC_SCCS and not lint */
40081527a8Scgd
4143fa6fe3Sjtc #include "namespace.h"
42081527a8Scgd #include <sys/param.h>
43081527a8Scgd #include <sys/sysctl.h>
443b26fee3Scgd #include <unistd.h>
45081527a8Scgd
463b26fee3Scgd int
sethostid(long hostid)47081527a8Scgd sethostid(long hostid)
48081527a8Scgd {
49*b91680c1Satatat int mib[2], value;
50081527a8Scgd
51081527a8Scgd mib[0] = CTL_KERN;
52081527a8Scgd mib[1] = KERN_HOSTID;
53*b91680c1Satatat value = (int)hostid;
54*b91680c1Satatat if (sysctl(mib, 2, NULL, NULL, &value, sizeof(value)) == -1)
55081527a8Scgd return (-1);
56081527a8Scgd return (0);
57081527a8Scgd }
58