in reply to gethost from Net::Hostent fails strangely

Two things to check up-front, from a debugging point of view:
  1. Turn on auto-flush by setting $|=1
  2. Print new-lines after your print statements.
I'm not sure about Win2k, but on Unix, by default, STDOUT is line-buffered, meaning you won't tend to see stuff until the full line is printed, unless you set autoflush on. Either of these changes could allow you to see the text you're looking for.

If we're sure the output is coming out when it should, but your code is somehow not executing, we can begin investigating the module, but realistically, Net::hostent is just a wrapper around gethostbyaddr/gethostbyname.

Update: I am not able to reproduce your behavior as you describe, however, using an IP address that does not resolve back to a name causes my script to die outright:

Can't call method "name" on an undefined value at test line 8.
Could you be executing this in an eval block or something, which might be trapping the die and allowing your script to continue executing?

Replies are listed 'Best First'.
Re: Re: gethost from Net::Hostent fails strangely
by jepri (Parson) on Jan 10, 2001 at 12:43 UTC
    Thanks for trying it out. You were right about the eval - it was part of a callback routine called from Tk::Timer. I don't know why it wasn't crashing the whole program, but I swear I had strict and diagnostics on.

    I eventually got it working with Net::DNS, and managed to reproduce the error there too. But because the query is broken into parts I was able to get a bit closer to the problem. If you do a reverse lookup (effectively an ordinary lookup on the reverse zone) and there's no record, you actually get a DNS reply packet with no records in it rather than a fail. But it appears the writers of the code did not envisage a DNS lookup that was partially successful (returns a packet with no RRs, rather than failing outright), since if you can get through to the primary DNS for a zone you can always get either a address RR or a not found (for a host->address lookup). But the reverse zone DNS seems to return a 'found' (since we know the machine exists) with no RRs (since the machine doesn't have a hostname that the DNS knows about). The code doesn't seem do any sanity checking, tries to load an RR (which isn't there) and then falls over.

    Phew!

    The short of that is that reverse DNS lookups on broken domains can break the support libraries. The only real way to be sure is to use Net::DNS and check that you actually have a RR before you try and print it out.

    * A RR is a resource record, or a mapping from hostname to ip address or vice versa. They have to be manually entered in the DNS but some DNS admins get lazy/clever and don't enter the ip address to hostname listing.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

      Just check to be sure 'gethost' succeeded. You were just trying to use the return value as an object, when it's not guaranteed not to be undefined. Since you're doing it inside an eval, the die would be caught by the eval. You should probably do a little more checking in your code to be sure stuff actually succeeded.