xref: /csrg-svn/lib/libc/gen/gethostname.c (revision 58952)
1*58952Smckusick /*
2*58952Smckusick  * Copyright (c) 1989 The Regents of the University of California.
3*58952Smckusick  * All rights reserved.
4*58952Smckusick  *
5*58952Smckusick  * %sccs.include.redist.c%
6*58952Smckusick  */
7*58952Smckusick 
8*58952Smckusick #if defined(LIBC_SCCS) && !defined(lint)
9*58952Smckusick static char sccsid[] = "@(#)gethostname.c	5.1 (Berkeley) 04/04/93";
10*58952Smckusick #endif /* LIBC_SCCS and not lint */
11*58952Smckusick 
12*58952Smckusick #include <sys/param.h>
13*58952Smckusick #include <sys/sysctl.h>
14*58952Smckusick 
15*58952Smckusick #if __STDC__
16*58952Smckusick long
17*58952Smckusick gethostname(char *name, int namelen)
18*58952Smckusick #else
19*58952Smckusick long
20*58952Smckusick gethostname(name, namelen)
21*58952Smckusick 	char *name;
22*58952Smckusick 	int namelen;
23*58952Smckusick #endif
24*58952Smckusick {
25*58952Smckusick 	int mib[2];
26*58952Smckusick 
27*58952Smckusick 	mib[0] = CTL_KERN;
28*58952Smckusick 	mib[1] = KERN_HOSTNAME;
29*58952Smckusick 	return (sysctl(mib, 2, name, &namelen, NULL, 0));
30*58952Smckusick }
31