Net::LDNS(3)

NAME
    Net::LDNS - DNS-talking module based on the ldns C library

SYNOPSIS
    my $resolver = Net::LDNS->new('8.8.8.8');
    my $packet   = $resolver->query('www.iis.se');
    say $packet->string;

DESCRIPTION
"Net::LDNS" represents a resolver, which is the part of the system responsible for sending queries and receiving answers to them.

EXPORTABLE FUNCTIONS

lib_version()
    Returns the ldns version string. Can be exported, but is not by default.

to_idn($name, ...)
    Takes a number of strings and returns a list of them converted to IDNA format. Assumes that the strings have been converted to Perl's internal encoding before it's called. Can be exported, but is not by default.

    This function requires that GNU libidn was present when Net::LDNS was compiled. If not, calling "to_idn" will result in an exception getting thrown.

has_idn()
    Takes no arguments. Returns true if libidn was present at compilation, false if not.

has_gost()
    Takes no arguments. Returns true if GOST support was present at compilation, false if not.

load_zonefile($filename)
    Load all resource records in a zone file, returning them as a list.

CLASS METHOD

new($addr,...)
    Creates a new resolver object. If given no arguments, if will pick up nameserver addresses from the system configuration (/etc/resolv.conf or equivalent). If given a single argument that is "undef", it will not know of any nameservers and all attempts to send queries will throw exceptions. If given one or more arguments that are not "undef", attempts to parse them as IPv4 and IPv6 addresses will be made, and if successful make up a list of servers to send queries to. If an argument cannot be parsed as an IP address, an exception will be thrown.

INSTANCE METHODS

query($name, $type, $class)
    Send a query for the given triple. If type or class are not provided they default to A and IN, respectively. Returns a Net::LDNS::Packet or undef.

name2addr($name)
    Asks this resolver to look up A and AAAA records for the given name, and return a list of the IP addresses (as strings). In scalar context, returns the number of addresses found.

addr2name($addr)
    Takes an IP address, asks the resolver to do PTR lookups and returns the names found. In scalar context, returns the number of names found.

recurse($flag)
    Returns the setting of the recursion flag. If given an argument, it will be treated as a boolean and the flag set accordingly.

debug($flag)
    Gets and optionally sets the debug flag.

dnssec($flag)
    Get and optionally sets the DNSSEC flag.

cd($flag)
    Get and optionally sets the CD flag.

igntc($flag)
    Get and optionally sets the igntc flag.

usevc($flag)
    Get and optionally sets the usevc flag.

retry($count)
    Get and optionally set the number of retries.

retrans($seconds)
    Get and optionally set the number of seconds between retries.

port($port)
    Get and optionally set the destination port for requests.

edns_size($size)
    Get and optionally set the EDNS0 UDP maximum size.

axfr( $domain, $callback, $class )
    Perform an AXFR operation. $callback must be a code reference, which will be called once for every received resource record with the RR object as its one and only argument. After every such call, the return value of the callback will be examined, and if the value is false the AXFR process will be aborted. The return value of the "axfr()" method itself will be true if the transfer completed normally, and false if it was aborted because the callback returned a false value.

    If anything goes wrong during the process, an exception will be thrown.

    As an example, saving all the RRs received from an AXFR can be done like this:

        my @rrs;
        $resolver->axfr( $domain, sub { my ($rr) = @_; push @rrs, $rr; return 1;} );

axfr_start($domain,$class)
    Deprecated. Use axfr() instead.

    Set this resolver object up for a zone transfer of the specified domain. If $class is not given, it defaults to IN.

axfr_next()
    Deprecated. Use axfr() instead.

    Get the next RR in the zone transfer. axfr_start() must have been done before this is called, and after this is called axfr_complete() should be used to check if there are more records to get. If there's any problem, an exception will be thrown. Basically, the sequence should be something like:

        $res->axfr_start('example.org');
        do {
            push @rrlist, $res->axfr_next;
        } until $res->axfr_complete;

axfr_complete()
    Deprecated. Use axfr() instead.

    Returns false if there is a started zone transfer with more records to get, and true if the started transfer has completed.

axfr_last_packet()
    Deprecated. Use axfr() instead.

    If axfr_next() threw an exception, this method returns the Net::LDNS::Packet that made it do so. The packet's RCODE is likely to say what the problem was (for example, NOTAUTH or NXDOMAIN).

timeout($time)
    Get and/or set the socket timeout for the resolver.

source($addr)
    Get and/or set the IP address the resolver should try to send its queries from.