| 1 |
/* |
| 2 |
|
| 3 |
Copyright 1989, 1998 The Open Group |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in |
| 12 |
all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
Except as contained in this notice, the name of The Open Group shall not be |
| 22 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 23 |
in this Software without prior written authorization from The Open Group. |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
/* |
| 28 |
* Author: Jim Fulton, MIT X Consortium |
| 29 |
* |
| 30 |
* _XGetHostname - similar to gethostname but allows special processing. |
| 31 |
*/ |
| 32 |
|
| 33 |
#ifdef HAVE_CONFIG_H |
| 34 |
#include <config.h> |
| 35 |
#endif |
| 36 |
#include <X11/Xosdefs.h> |
| 37 |
#include <string.h> |
| 38 |
#include <unistd.h> |
| 39 |
|
| 40 |
#ifdef WIN32 |
| 41 |
#include <X11/Xlibint.h> |
| 42 |
#include <X11/Xwinsock.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
#ifdef USG |
| 46 |
#define NEED_UTSNAME |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifdef NEED_UTSNAME |
| 50 |
#include <sys/utsname.h> |
| 51 |
#endif |
| 52 |
|
| 53 |
#include <X11/Xmu/SysUtil.h> |
| 54 |
|
| 55 |
int |
| 56 |
XmuGetHostname(char *buf, int maxlen) |
| 57 |
{ |
| 58 |
int len; |
| 59 |
#ifdef WIN32 |
| 60 |
static WSADATA wsadata; |
| 61 |
|
| 62 |
if (!wsadata.wVersion && WSAStartup(MAKEWORD(2,2), &wsadata)) |
| 63 |
return -1; |
| 64 |
#endif |
| 65 |
|
| 66 |
#ifdef NEED_UTSNAME |
| 67 |
/* |
| 68 |
* same host name crock as in server and xinit. |
| 69 |
*/ |
| 70 |
struct utsname name; |
| 71 |
|
| 72 |
uname (&name); |
| 73 |
len = strlen (name.nodename); |
| 74 |
if (len >= maxlen) len = maxlen - 1; |
| 75 |
strncpy (buf, name.nodename, len); |
| 76 |
buf[len] = '\0'; |
| 77 |
#else |
| 78 |
buf[0] = '\0'; |
| 79 |
(void) gethostname (buf, maxlen); |
| 80 |
buf [maxlen - 1] = '\0'; |
| 81 |
len = strlen(buf); |
| 82 |
#endif /* hpux */ |
| 83 |
return len; |
| 84 |
} |