1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: hostname.c 312 2006-12-11 18:06:32Z hubert@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006 University of Washington
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
24
#include <sys/utsname.h>
26
#elif defined(SYSTEMID)
36
/*----------------------------------------------------------------------
37
Call system gethostname
39
Args: hostname -- buffer to return host name in
40
size -- Size of buffer hostname is to be returned in
42
Result: returns 0 if the hostname is correctly set,
43
-1 if not (and errno is set).
46
hostname(char *hostname, int size)
50
return(gethostname(hostname, size));
54
/** This routine compliments of Scott McGregor at the HP
55
Corporate Computing Center **/
57
int uname(struct utsname *);
61
(void)strncpy(hostname,name.nodename,size-1);
63
hostname[size - 1] = '\0';
66
#elif defined(SYSTEMID)
71
if ((fp = our_fopen("/etc/systemid", "rb")) != 0) {
72
fgets(buf, sizeof(buf) - 1, fp);
74
if ((p = strindex(buf, '\n')) != NULL)
76
(void) strncpy(hostname, buf, size - 1);
77
hostname[size - 1] = '\0';
84
/** This routine compliments of Scott McGregor at the HP
85
Corporate Computing Center **/
91
(void) strncpy(hostname,name.nodename,size-1);
93
(void) strncpy(hostname, HOSTNAME, size-1);
96
hostname[size - 1] = '\0';
99
/* We shouldn't get here except for the windows
100
* case, which currently doesn't use this (as
101
* it appears nothing else does as well)