xref: /csrg-svn/lib/libc/gen/sethostname.c (revision 61111)
158952Smckusick /*
2*61111Sbostic  * Copyright (c) 1989, 1993
3*61111Sbostic  *	The Regents of the University of California.  All rights reserved.
458952Smckusick  *
558952Smckusick  * %sccs.include.redist.c%
658952Smckusick  */
758952Smckusick 
858952Smckusick #if defined(LIBC_SCCS) && !defined(lint)
9*61111Sbostic static char sccsid[] = "@(#)sethostname.c	8.1 (Berkeley) 06/04/93";
1058952Smckusick #endif /* LIBC_SCCS and not lint */
1158952Smckusick 
1258952Smckusick #include <sys/param.h>
1358952Smckusick #include <sys/sysctl.h>
1458952Smckusick 
1558952Smckusick #if __STDC__
1658952Smckusick long
sethostname(const char * name,int namelen)1758952Smckusick sethostname(const char *name, int namelen)
1858952Smckusick #else
1958952Smckusick long
2058952Smckusick sethostname(name, namelen)
2158952Smckusick 	char *name;
2258952Smckusick 	int namelen;
2358952Smckusick #endif
2458952Smckusick {
2558952Smckusick 	int mib[2];
2658952Smckusick 
2758952Smckusick 	mib[0] = CTL_KERN;
2858952Smckusick 	mib[1] = KERN_HOSTNAME;
2958955Smckusick 	if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1)
3058955Smckusick 		return (-1);
3158955Smckusick 	return (0);
3258952Smckusick }
33