os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclUnixSock.c
First public contribution.
4 * This file contains Unix-specific socket related code.
6 * Copyright (c) 1995 Sun Microsystems, Inc.
7 * Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * RCS: @(#) $Id: tclUnixSock.c,v 1.6.2.4 2006/09/07 09:01:07 vasiljevic Exp $
19 * There is no portable macro for the maximum length
20 * of host names returned by gethostbyname(). We should only
21 * trust SYS_NMLN if it is at least 255 + 1 bytes to comply with DNS
24 * Note: SYS_NMLN is a restriction on "uname" not on gethostbyname!
26 * For example HP-UX 10.20 has SYS_NMLN == 9, while gethostbyname()
27 * can return a fully qualified name from DNS of up to 255 bytes.
29 * Fix suggested by Viktor Dukhovni (viktor@esm.com)
32 #if defined(SYS_NMLN) && SYS_NMLEN >= 256
33 #define TCL_HOSTNAME_LEN SYS_NMLEN
35 #define TCL_HOSTNAME_LEN 256
40 * The following variable holds the network name of this host.
43 static char hostname[TCL_HOSTNAME_LEN + 1];
44 static int hostnameInited = 0;
45 TCL_DECLARE_MUTEX(hostMutex)
49 *----------------------------------------------------------------------
53 * Returns the name of the local host.
56 * A string containing the network name for this machine, or
57 * an empty string if we can't figure out the name. The caller
58 * must not modify or free this string.
63 *----------------------------------------------------------------------
73 char buffer[sizeof(hostname)];
77 Tcl_MutexLock(&hostMutex);
79 Tcl_MutexUnlock(&hostMutex);
85 (VOID *) memset((VOID *) &u, (int) 0, sizeof(struct utsname));
86 if (uname(&u) > -1) { /* INTL: Native. */
87 hp = TclpGetHostByName(u.nodename); /* INTL: Native. */
90 * Sometimes the nodename is fully qualified, but gets truncated
91 * as it exceeds SYS_NMLN. See if we can just get the immediate
92 * nodename and get a proper answer that way.
94 char *dot = strchr(u.nodename, '.');
96 char *node = ckalloc((unsigned) (dot - u.nodename + 1));
97 memcpy(node, u.nodename, (size_t) (dot - u.nodename));
98 node[dot - u.nodename] = '\0';
99 hp = TclpGetHostByName(node);
111 * Uname doesn't exist; try gethostname instead.
114 if (gethostname(buffer, sizeof(buffer)) > -1) { /* INTL: Native. */
119 if (native == NULL) {
122 Tcl_ExternalToUtf(NULL, NULL, native, -1, 0, NULL, hostname,
123 sizeof(hostname), NULL, NULL, NULL);
126 Tcl_MutexUnlock(&hostMutex);
131 *----------------------------------------------------------------------
135 * Detect if sockets are available on this platform.
143 *----------------------------------------------------------------------
147 TclpHasSockets(interp)
148 Tcl_Interp *interp; /* Not used. */
154 *----------------------------------------------------------------------
156 * TclpFinalizeSockets --
158 * Performs per-thread socket subsystem finalization.
166 *----------------------------------------------------------------------
170 TclpFinalizeSockets()