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