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[] = "@(#)gethostname.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 long gethostname(name,namelen)1658952Smckusickgethostname(name, namelen) 1758952Smckusick char *name; 1858952Smckusick int namelen; 1958952Smckusick { 2058952Smckusick int mib[2]; 2160350Storek size_t size; 2258952Smckusick 2358952Smckusick mib[0] = CTL_KERN; 2458952Smckusick mib[1] = KERN_HOSTNAME; 2560350Storek size = namelen; 2660350Storek if (sysctl(mib, 2, name, &size, NULL, 0) == -1) 2758955Smckusick return (-1); 2858955Smckusick return (0); 2958952Smckusick } 30