00001 /* $Xorg: GetHost.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */ 00002 00003 /* 00004 00005 Copyright 1989, 1998 The Open Group 00006 00007 Permission to use, copy, modify, distribute, and sell this software and its 00008 documentation for any purpose is hereby granted without fee, provided that 00009 the above copyright notice appear in all copies and that both that 00010 copyright notice and this permission notice appear in supporting 00011 documentation. 00012 00013 The above copyright notice and this permission notice shall be included in 00014 all copies or substantial portions of the Software. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00022 00023 Except as contained in this notice, the name of The Open Group shall not be 00024 used in advertising or otherwise to promote the sale, use or other dealings 00025 in this Software without prior written authorization from The Open Group. 00026 00027 */ 00028 /* $XFree86: xc/lib/Xmu/GetHost.c,v 3.7 2001/07/25 15:04:50 dawes Exp $ */ 00029 00030 /* 00031 * Author: Jim Fulton, MIT X Consortium 00032 * 00033 * _XGetHostname - similar to gethostname but allows special processing. 00034 */ 00035 00036 #include <X11/Xosdefs.h> 00037 #include <string.h> 00038 #include <unistd.h> 00039 00040 #ifdef WIN32 00041 #include <X11/Xwinsock.h> 00042 #endif 00043 00044 #ifdef USG 00045 #define NEED_UTSNAME 00046 #endif 00047 00048 #ifdef NEED_UTSNAME 00049 #include <sys/utsname.h> 00050 #endif 00051 00052 #include <X11/Xmu/SysUtil.h> 00053 00054 int 00055 XmuGetHostname(char *buf, int maxlen) 00056 { 00057 int len; 00058 #ifdef WIN32 00059 static WSADATA wsadata; 00060 00061 if (!wsadata.wVersion && WSAStartup(MAKEWORD(1,1), &wsadata)) 00062 return -1; 00063 #endif 00064 00065 #ifdef NEED_UTSNAME 00066 /* 00067 * same host name crock as in server and xinit. 00068 */ 00069 struct utsname name; 00070 00071 uname (&name); 00072 len = strlen (name.nodename); 00073 if (len >= maxlen) len = maxlen - 1; 00074 strncpy (buf, name.nodename, len); 00075 buf[len] = '\0'; 00076 #else 00077 buf[0] = '\0'; 00078 (void) gethostname (buf, maxlen); 00079 buf [maxlen - 1] = '\0'; 00080 len = strlen(buf); 00081 #endif /* hpux */ 00082 return len; 00083 }
1.5.1