#3997 dns resolver problem

obsolete: 8.5.2
Reinhard Max

I have a problem to resolv reverse DNS in tcl interpreter compiled with treads in my server socket code. If host is available i reverse DNS zone it is ok but if host is not available tcl returns last position from /etc/hosts file.
This situation is only on tcl compiled with threads. I check 8.5.2, 8.4.15, 8.4.18

No threaded interpreter:
logger: Opening SMTP connection from

Threaded interpreter:
logger: Opening SMTP connection from osiolek

Last position from my /etc/hosts osiolek

fconfigure returns bad hostname

Sample code:
if {[catch {set RemoteName [lindex [fconfigure $channel -peername] 1]} err]} {
logger "Can't read client name"
after 0 "close $channel"

Linux distributions: SLES 9, SLES 10, Ubuntu



  • Logged In: YES
    Originator: NO

    my observations:

    with nothreaded interpreter:

    set hostip [lindex [fconfigure $channel -peername] 0] returns client(host) IP
    set hostname [lindex [fconfigure $channel -peername] 1] returns client(host) NAME (from DNS or /etc/hosts)
    set hostport [lindex [fconfigure $channel -peername] 2] returns client(host) PORT

    but with threaded interpreter "fconfigure -peername" returns good client IP, NAME and PORT doesn't exists (!).

    Darek. d.wapinski@dominet.pl

  • Logged In: YES
    Originator: NO

    Looks like there's thread-safety problems in TclpGetHostByAddr when built under modern Linux. Should review to see if replacing with getaddrinfo (which is *supposed* to be thread-safe) is practical.

    • labels: 104253 --> 27. Channel Types
    • assigned_to: nobody --> andreas_kupries
    • milestone: --> obsolete: 8.5.2
    • priority: 5 --> 8
  • Logged In: YES
    Originator: NO

    Maybe problem is because gethostbyaddr_r return more than one error conditions:

    Error Conditions

    When the gethostbyaddr_r() function fails, h_errno (defined in <netdb.h>) can be set to:


    In TclpGetHostByAddr(const char *addr, int length, int type) in tclUnixCompat.c we have only NULL? If I reduce TclpGetHostByAddr() to:

    struct hostent *
    const char *addr,
    int length,
    int type)
    return gethostbyaddr(addr, length, type);

    everything is OK. But this is NOT answer.

  • Tcl 8.6 uses getaddrinfo() now which is documented as thread safe. (It also supports IPv6, which is why we switched to GAI.)

    • assigned_to: andreas_kupries --> rmax
    • status: open --> closed-out-of-date