Net::LibResolv(3pm)
πΈ Net::LibResolv β the Perl wrapper around libresolv, bestie π
okay so this is the manual page for Net::LibResolv, part of the User Contributed Perl Documentation fam. she's a Perl wrapper around libresolv and she's here to make DNS queries happen. periodt. β¨
π NAME
"Net::LibResolv" β a Perl wrapper around libresolv π
β¨ SYNOPSIS
here's the whole vibe in one go, no cap:
use Net::LibResolv qw( res_query NS_C_IN NS_T_A $h_errno );
use Net::DNS::Packet;
my $answer = res_query( "www.cpan.org", NS_C_IN, NS_T_A );
defined $answer or die "DNS failure - $h_errno\n";
foreach my $rr ( Net::DNS::Packet->new( \$answer )->answer ) {
print $rr->string, "\n";
}
like, literally just look at her go π₯
π¦ DESCRIPTION
so the libresolv library gives you functions that use the platform's standard DNS resolver to go perform DNS queries. iconic behaviour honestly.
this Perl module wraps the two primary functions, res_query(3) and res_search(3), so you can call them from Perl. π«Ά
and here's the thing you need to know: the return value from each function is a byte buffer containing the actual DNS response packet. that's it. raw bytes. you're gonna have to parse it somehow to get the useful info out of it β most likely by using Net::DNS. the packet is giving mystery box and you gotta open it yourself π
π FUNCTIONS
$answer = res_query( $dname, $class, $type )
calls the res_query(3) function on the given domain name, class and type number. returns the answer byte buffer on success, or "undef" on failure π β and on failure it sets the value of the $h_errno package variable.
$dname should be a plain string. $class and $type should be numerical codes. check the "CONSTANTS" section for convenient definitions, iykyk β¨
$answer = res_search( $dname, $class, $type )
calls the res_search(3) function on the given domain name, class and type number. returns the answer byte buffer on success, or "undef" on failure π β and on failure it sets the value of the $h_errno package variable.
$dname should be a plain string. $class and $type should be numerical codes. see the "CONSTANTS" section for convenient definitions π
π VARIABLES
$h_errno
after an error from "res_query" or "res_search", this variable gets set to the error value, as a dual-valued scalar. so: its numerical value will be one of the error constants (see below), and its string value will be an error message version of the same β similar to the $! perl core variable. she's versatile like that π
if( !defined( my $answer = res_query( ... ) ) ) {
print "Try again later...\n" if $h_errno == TRY_AGAIN;
}
defined( my $answer = res_query( ... ) ) or
die "Cannot res_query() - $h_errno\n";
π CONSTANTS
Class IDs
this set of constants defines values for the $class parameter. typically only "NS_C_IN" is actually used, for Internet π β the others are just chilling there.
NS_C_IN NS_C_CHAOS NS_C_HS
NS_C_INVALD NS_C_NONE NS_C_ANY
yes bestie, NS_C_INVALD is spelled exactly like that in the original. don't come for me, I'm just the messenger π
$id = class_name2value( $name )
$name = class_value2name( $id )
functions to convert between class names and ID values. glow-up in both directions β¨
Type IDs
the following are examples of constants that define values for the $type parameter. (they all follow the same naming pattern, named after the record type, so only a few are listed here β the rest are out there living their truth π
)
NS_T_A NS_T_NS NS_T_CNAME NS_T_PTR NS_T_MX NS_T_TXT NS_T_SRV NS_T_AAAA
NS_T_INVALID NS_T_ANY
$id = type_name2value( $name )
$name = type_value2name( $id )
functions to convert between type names and ID values. same deal, both directions, slay π
Errors
the following constants define error values for $h_errno:
HOST_NOT_FOUND NO_ADDRESS NO_DATA NO_RECOVERY TRY_AGAIN
heads up π¨ β the values of"NO_ADDRESS"and"NO_DATA"may be the same. so don't go assuming they're different just because they have different names, okay? π
πΈ SEE ALSO
- Net::DNS β Perl interface to the DNS resolver π¦
π AUTHOR
Paul Evans <leonerd@leonerd.org.uk> π
and that's the whole page, bestie!! this was perl v5.42.2, dated 2026-02-15, written by the legend Paul Evans himself β go forth and resolve some DNS, you absolute icon π«Άβ¨π
π¦ where this page comes from
- alpine 3.24: perl-net-libresolv-doc 0.03-r3 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms