Skip to content
Tcl Source Code View Ticket
Login

View Ticket

dns resolver problem

Closed / Out of Date1962217fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 15 years ago
Descriptionplain2008-05-12 07:06:36
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 172.16.17.222

Threaded interpreter:
logger: Opening SMTP connection from osiolek

Last position from my /etc/hosts
172.16.55.11 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"
        return
    }

Linux distributions: SLES 9, SLES 10, Ubuntu

[email protected]
wapinskiplain2008-05-20 04:55:40
Logged In: YES 
user_id=2091947
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. [email protected]
dkfplain2008-05-20 15:16:11
Logged In: YES 
user_id=79902
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.
dkf Ticket [1962217fff]: 4 changes [History diff]2008-05-20 15:16:12
wapinskiplain2008-05-26 18:35:21
Logged In: YES 
user_id=2091947
Originator: NO

Maybe problem is because gethostbyaddr_r return more than one error conditions:
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/apis/tsghosta.htm

"
Error Conditions

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

[HOST_NOT_FOUND]
[NO_DATA]
[NO_RECOVERY]
[TRY_AGAIN]
[EINVAL]
"

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

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

everything is OK. But this is NOT answer.
dkfplain2012-05-18 00:08:39
allow_comments - 1

Tcl 8.6 uses getaddrinfo() now which is documented as thread safe. (It also supports IPv6, which is why we switched to GAI.)
Log in (anonymous is fine) to add a comment.