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