Mail::SpamAssassin::DnsResolver − DNS resolution engine


This is a DNS resolution engine for SpamAssassin, implemented in order to reduce file descriptor usage by Net::DNS and avoid a response collision bug in that module.



Load the "Net::DNS::Resolver" object. Returns 0 if Net::DNS cannot be used, 1 if it is available.

$resolver = $res−>get_resolver()

Return the "Net::DNS::Resolver" object.


Wrapper for Net::DNS::Resolver−>nameservers to get or set list of nameservers


Re-connect to the first nameserver listed in "/etc/resolv.conf" or similar platform-dependent source, as provided by "Net::DNS".


Return the "IO::Socket::INET" object used to communicate with the nameserver.

$packet = new_dns_packet ($host, $type, $class)

A wrapper for "Net::DNS::Packet::new()" which traps a die thrown by it.

To use this, change calls to "Net::DNS::Resolver::bgsend" from:

    $res−>bgsend($hostname, $type);


    $res−>bgsend(Mail::SpamAssassin::DnsResolver::new_dns_packet($hostname, $type, $class));

$id = $res−>bgsend($host, $type, $class, $cb)

Quite similar to "Net::DNS::Resolver::bgsend", except that when a response packet eventually arrives, and "poll_responses" is called, the callback sub reference $cb will be called.

Note that $type and $class may be "undef", in which case they will default to "A" and "IN", respectively.

The callback sub will be called with three arguments -- the packet that was delivered, and an id string that fingerprints the query packet and the expected reply. The third argument is a timestamp (Unix time, floating point), captured at the time the packet was collected. It is expected that a closure callback be used, like so:

  my $id = $self−>{resolver}−>bgsend($host, $type, undef, sub {
        my ($reply, $reply_id, $timestamp) = @_;
        $self−>got_a_reply ($reply, $reply_id);

The callback can ignore the reply as an invalid packet sent to the listening port if the reply id does not match the return value from bgsend.

$nfound = $res−>poll_responses()

See if there are any "bgsend" response packets ready, and return the number of such packets delivered to their callbacks.


Call this to release pending requests from memory, when aborting backgrounded requests, or when the scan is complete. "Mail::SpamAssassin::PerMsgStatus::check" calls this before returning.

$packet = $res−>send($name, $type, $class)

Emulates "Net::DNS::Resolver::send()".


Little more than a stub for callers expecting this from "Net::DNS::Resolver".

If called immediately after a call to $res−>send this will return "query timed out" if the $res−>send DNS query timed out. Otherwise "unknown error or no error" will be returned.

No other errors are reported.


Reset socket when done with it.


Clean up for destruction.


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.