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 2008 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 if (gethostname(hostname
, size
))
53 /* sanity check of hostname string */
54 for (*dn
= hname
; (*dn
> 0x20) && (*dn
< 0x7f); ++dn
)
57 if (*dn
) /* non-ascii in hostname */
58 strncpy(hostname
, "unknown", size
-1);
60 hostname
[size
- 1] = '\0';
65 /** This routine compliments of Scott McGregor at the HP
66 Corporate Computing Center **/
68 int uname(struct utsname
*);
72 (void)strncpy(hostname
,name
.nodename
,size
-1);
74 hostname
[size
- 1] = '\0';
77 #elif defined(SYSTEMID)
82 if ((fp
= our_fopen("/etc/systemid", "rb")) != 0) {
83 fgets(buf
, sizeof(buf
) - 1, fp
);
85 if ((p
= strindex(buf
, '\n')) != NULL
)
87 (void) strncpy(hostname
, buf
, size
- 1);
88 hostname
[size
- 1] = '\0';
95 /** This routine compliments of Scott McGregor at the HP
96 Corporate Computing Center **/
102 (void) strncpy(hostname
,name
.nodename
,size
-1);
104 (void) strncpy(hostname
, HOSTNAME
, size
-1);
107 hostname
[size
- 1] = '\0';
110 /* We shouldn't get here except for the windows
111 * case, which currently doesn't use this (as
112 * it appears nothing else does as well)