4 * This file contains Unix-specific socket related code.
6 * Copyright (c) 1995 Sun Microsystems, Inc.
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
18 * There is no portable macro for the maximum length
19 * of host names returned by gethostbyname(). We should only
20 * trust SYS_NMLN if it is at least 255 + 1 bytes to comply with DNS
23 * Note: SYS_NMLN is a restriction on "uname" not on gethostbyname!
25 * For example HP-UX 10.20 has SYS_NMLN == 9, while gethostbyname()
26 * can return a fully qualified name from DNS of up to 255 bytes.
28 * Fix suggested by Viktor Dukhovni (viktor@esm.com)
31 #if defined(SYS_NMLN) && SYS_NMLEN >= 256
32 #define TCL_HOSTNAME_LEN SYS_NMLEN
34 #define TCL_HOSTNAME_LEN 256
39 * The following variable holds the network name of this host.
42 static char hostname[TCL_HOSTNAME_LEN + 1];
43 static int hostnameInited = 0;
44 TCL_DECLARE_MUTEX(hostMutex)
48 *----------------------------------------------------------------------
52 * Returns the name of the local host.
55 * A string containing the network name for this machine, or
56 * an empty string if we can't figure out the name. The caller
57 * must not modify or free this string.
62 *----------------------------------------------------------------------
72 char buffer[sizeof(hostname)];
76 Tcl_MutexLock(&hostMutex);
78 Tcl_MutexUnlock(&hostMutex);
84 (VOID *) memset((VOID *) &u, (int) 0, sizeof(struct utsname));
85 if (uname(&u) > -1) { /* INTL: Native. */
86 hp = gethostbyname(u.nodename); /* INTL: Native. */
95 * Uname doesn't exist; try gethostname instead.
98 if (gethostname(buffer, sizeof(buffer)) > -1) { /* INTL: Native. */
103 if (native == NULL) {
106 Tcl_ExternalToUtf(NULL, NULL, native, -1, 0, NULL, hostname,
107 sizeof(hostname), NULL, NULL, NULL);
110 Tcl_MutexUnlock(&hostMutex);
115 *----------------------------------------------------------------------
119 * Detect if sockets are available on this platform.
127 *----------------------------------------------------------------------
131 TclpHasSockets(interp)
132 Tcl_Interp *interp; /* Not used. */