11e72d8d2Sderaadt /* hostname.c -- use uname() to get the name of the host 21e72d8d2Sderaadt Copyright (C) 1992 Free Software Foundation, Inc. 31e72d8d2Sderaadt 41e72d8d2Sderaadt This program is free software; you can redistribute it and/or modify 51e72d8d2Sderaadt it under the terms of the GNU General Public License as published by 61e72d8d2Sderaadt the Free Software Foundation; either version 2, or (at your option) 71e72d8d2Sderaadt any later version. 81e72d8d2Sderaadt 91e72d8d2Sderaadt This program is distributed in the hope that it will be useful, 101e72d8d2Sderaadt but WITHOUT ANY WARRANTY; without even the implied warranty of 111e72d8d2Sderaadt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*461cc63eStholo GNU General Public License for more details. */ 131e72d8d2Sderaadt 141e72d8d2Sderaadt #ifdef HAVE_CONFIG_H 151e72d8d2Sderaadt #include "config.h" 161e72d8d2Sderaadt #endif 171e72d8d2Sderaadt 181e72d8d2Sderaadt #if defined(STDC_HEADERS) || defined(USG) 191e72d8d2Sderaadt #include <string.h> 201e72d8d2Sderaadt #ifndef index 211e72d8d2Sderaadt #define index strchr 221e72d8d2Sderaadt #endif 231e72d8d2Sderaadt #else 241e72d8d2Sderaadt #include <strings.h> 251e72d8d2Sderaadt #endif 261e72d8d2Sderaadt 271e72d8d2Sderaadt #include <sys/utsname.h> 281e72d8d2Sderaadt 291e72d8d2Sderaadt /* Put this host's name into NAME, using at most NAMELEN characters */ 301e72d8d2Sderaadt 311e72d8d2Sderaadt int gethostname(name,namelen)321e72d8d2Sderaadtgethostname(name, namelen) 331e72d8d2Sderaadt char *name; 341e72d8d2Sderaadt int namelen; 351e72d8d2Sderaadt { 361e72d8d2Sderaadt struct utsname ugnm; 371e72d8d2Sderaadt 381e72d8d2Sderaadt if (uname(&ugnm) < 0) 391e72d8d2Sderaadt return (-1); 401e72d8d2Sderaadt 411e72d8d2Sderaadt (void) strncpy(name, ugnm.nodename, namelen-1); 421e72d8d2Sderaadt name[namelen-1] = '\0'; 431e72d8d2Sderaadt 441e72d8d2Sderaadt return (0); 451e72d8d2Sderaadt } 46