OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [unix/] [tclUnixSock.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tclUnixSock.c --
3
 *
4
 *      This file contains Unix-specific socket related code.
5
 *
6
 * Copyright (c) 1995 Sun Microsystems, Inc.
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 * RCS: @(#) $Id: tclUnixSock.c,v 1.1.1.1 2002-01-16 10:25:37 markom Exp $
12
 */
13
 
14
#include "tcl.h"
15
#include "tclPort.h"
16
 
17
/*
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
21
 * host name limits.
22
 *
23
 * Note:  SYS_NMLN is a restriction on "uname" not on gethostbyname!
24
 *
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.
27
 *
28
 * Fix suggested by Viktor Dukhovni (viktor@esm.com)
29
 */
30
 
31
#if defined(SYS_NMLN) && SYS_NMLEN >= 256
32
#define TCL_HOSTNAME_LEN SYS_NMLEN
33
#else
34
#define TCL_HOSTNAME_LEN 256
35
#endif
36
 
37
 
38
/*
39
 * The following variable holds the network name of this host.
40
 */
41
 
42
static char hostname[TCL_HOSTNAME_LEN + 1];
43
static int  hostnameInited = 0;
44
 
45
/*
46
 *----------------------------------------------------------------------
47
 *
48
 * Tcl_GetHostName --
49
 *
50
 *      Returns the name of the local host.
51
 *
52
 * Results:
53
 *      A string containing the network name for this machine, or
54
 *      an empty string if we can't figure out the name.  The caller
55
 *      must not modify or free this string.
56
 *
57
 * Side effects:
58
 *      None.
59
 *
60
 *----------------------------------------------------------------------
61
 */
62
 
63
char *
64
Tcl_GetHostName()
65
{
66
#ifndef NO_UNAME
67
    struct utsname u;
68
    struct hostent *hp;
69
#endif
70
 
71
    if (hostnameInited) {
72
        return hostname;
73
    }
74
 
75
#ifndef NO_UNAME
76
    (VOID *) memset((VOID *) &u, (int) 0, sizeof(struct utsname));
77
    if (uname(&u) > -1) {
78
        hp = gethostbyname(u.nodename);
79
        if (hp != NULL) {
80
            strcpy(hostname, hp->h_name);
81
        } else {
82
            strcpy(hostname, u.nodename);
83
        }
84
        hostnameInited = 1;
85
        return hostname;
86
    }
87
#else
88
    /*
89
     * Uname doesn't exist; try gethostname instead.
90
     */
91
 
92
    if (gethostname(hostname, sizeof(hostname)) > -1) {
93
        hostnameInited = 1;
94
        return hostname;
95
    }
96
#endif
97
 
98
    hostname[0] = 0;
99
    return hostname;
100
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.