1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: hostname.c 1176 2008-09-29 21:16:42Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2018 Eduardo Chappa
8 * Copyright 2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
25 #include <sys/utsname.h>
27 #elif defined(SYSTEMID)
37 /*----------------------------------------------------------------------
38 Call system gethostname
40 Args: hostname -- buffer to return host name in
41 size -- Size of buffer hostname is to be returned in
43 Result: returns 0 if the hostname is correctly set,
44 -1 if not (and errno is set).
47 hostname(char *hostname
, int size
)
51 if (gethostname(hostname
, size
))
54 /* sanity check of hostname string */
55 for (*dn
= hname
; (*dn
> 0x20) && (*dn
< 0x7f); ++dn
)
58 if (*dn
) /* non-ascii in hostname */
59 strncpy(hostname
, "unknown", size
-1);
61 hostname
[size
- 1] = '\0';
66 /** This routine compliments of Scott McGregor at the HP
67 Corporate Computing Center **/
69 int uname(struct utsname
*);
73 (void)strncpy(hostname
,name
.nodename
,size
-1);
75 hostname
[size
- 1] = '\0';
78 #elif defined(SYSTEMID)
83 if ((fp
= our_fopen("/etc/systemid", "rb")) != 0) {
84 fgets(buf
, sizeof(buf
) - 1, fp
);
86 if ((p
= strindex(buf
, '\n')) != NULL
)
88 (void) strncpy(hostname
, buf
, size
- 1);
89 hostname
[size
- 1] = '\0';
96 /** This routine compliments of Scott McGregor at the HP
97 Corporate Computing Center **/
103 (void) strncpy(hostname
,name
.nodename
,size
-1);
105 (void) strncpy(hostname
, HOSTNAME
, size
-1);
108 hostname
[size
- 1] = '\0';
111 /* We shouldn't get here except for the windows
112 * case, which currently doesn't use this (as
113 * it appears nothing else does as well)