kennzors has asked for the wisdom of the Perl Monks concerning the following question:

hi

i'm having some difficulty in determining how to differentiate between gethostbyname() function call timing out, or not being able to find the host information at all.

I'm most interested in the time it takes to actually find the host information, or how long it takes to time out.

if i implement this for example:
$ipaddr = gethostbyname("www.thisisnotawebsite.com");
it takes no time at all for the dns server to return telling that the hostname is invalid.

From what I've tested, it takes around 20 seconds before the function returns undefined for $ipaddr. However, this difference isn't particularly accurate because it may be the case that it takes 20 seconds or more for the dns server to actually reply with the host information, or to return that the host is invalid.

anyone have a solution for this? If there needs to be clarification, i will clarify to the best of my ability!!

kennzors

  • Comment on gethostbyname timing out or dns server can't find the host information

Replies are listed 'Best First'.
Re: gethostbyname timing out or dns server can't find the host information
by kennzors (Initiate) on Mar 11, 2013 at 23:10 UTC

    tye has answered this for me on chatterbox

    checking the value of $!, which is the errno, can be used to differentiate this. Thanks tye!

Re: gethostbyname timing out or dns server can't find the host information
by Anonymous Monk on Mar 11, 2013 at 23:12 UTC
    I imagine, in case of timeout, $! might be set, %! ought to have something  $! and die join ' ', grep( { $!{$_} } keys %! )
      $ perl -le " print for grep /timeout/i, keys %!" ERROR_CTX_CLIENT_QUERY_TIMEOUT ERROR_CTX_MODEM_RESPONSE_TIMEOUT ERROR_TIMEOUT ERROR_COUNTER_TIMEOUT ERROR_SEM_TIMEOUT ERROR_SERVICE_REQUEST_TIMEOUT

      hmm from http://perldoc.perl.org/perlvar.html

      Additionally, if the h_errno variable is supported in C, its value is returned via $? if any gethost*() function fails.

      would using $? work? tye also mentioned this value

        I've no idea, really
        $ perl -MData::Dump -E " gethostbyname(q(blocalhost)); dd $!,int$!,$?, + grep( { $!{$_} } keys %! ) " ("No such host is known.", 11001, 11001)