libsres(3)
π libsres β bestie's guide to sending queries & catching responses π
okay so this is libsres(3), from the Programmer's Manual section (section 3, the "we write C and we're cute about it" section π
). it's the DNS resolver library bestie, and yes she comes with a whole personality. let's go πΈ
β¨ NAME β¨
query_send(), response_rcv(), get() β send queries to a DNS name server and receive responses back. it's giving "ask the internet a question and hope she answers" π¦
clone_ns(), clone_ns_list(), free_name_server(), free_name_servers() β manage name server lists. clone her, copy her, free her, clean up the whole friend group π
print_response() β display the answers that came back from the name server. the reveal moment π₯
β¨ SYNOPSIS β¨
#include <resolver.h>
int query_send(const char *name,
const unsigned short type,
const unsigned short class,
struct name_server *nslist,
int edns0_size,
int *trans_id);
int response_recv(int *trans_id,
fd_set *pending_desc,
struct timeval *closest_event,
struct name_server **respondent,
unsigned char **response,
size_t *response_length);
int get(const char *name_n,
const unsigned short type_h,
const unsigned short class_h,
struct name_server *nslist,
struct name_server **respondent,
unsigned char **response,
size_t *response_length);
int clone_ns(struct name_server **cloned_ns,
struct name_server *ns);
int clone_ns_list(struct name_server **ns_list,
struct name_server *orig_ns_list);
void free_name_server(struct name_server **ns);
void free_name_servers(struct name_server **ns);
void print_response(unsigned char *response,
size_t response_length);
β¨ DESCRIPTION β¨
okay so like, query_send() sends a query off to the name servers you listed in nslist. the query itself is the <name, class, type> tuple (iconic trio, no notes β¨), and trans_id gives you a handle to this whole transaction inside the libsres library. and the buffer size that gets advertised in the EDNS0 option? you set that with the ends0_size argument. slay.
response_recv() returns the answers, if there are any, from the name server that actually responded for the query identified by trans_id. the response shows up in response, and the name server who answered comes back in respondent. the length of the response, in bytes, lands in response_length. she tells you everything π«Ά
get() is the wrapper bestie around query_send() and response_recv(). it sends the request, then blocks until some name server responds or until the request times out. and hear me on this one: the libsres library does not automatically follow referrals β responses containing referrals are treated as valid responses. periodt.
the memory that *respondent points to is internally allocated by the libsres library, so you have to free it with free_name_server(). you can free a whole list of name servers with free_name_servers(). wanna make a copy of a name server? that's clone_ns(). copy of a whole name server list? that's clone_ns_list(). match made in heaven π
print_response() is the convenient way to display the answers returned in response by the name server. the unboxing β¨
π the name_server structure π
she's defined in resolver.h like this, and she's exactly this, don't touch:
#define NS_MAXCDNAME 255
struct name_server
{
unsigned char ns_name_n[NS_MAXCDNAME];
void *ns_tsig;
unsigned int ns_security_options;
unsigned int ns_status;
unsigned long ns_options;
int ns_retry;
int ns_retrans;
struct name_server *ns_next;
int ns_number_of_addresses;
struct sockaddr_storage **ns_address;
};
ns_name_nβ the name of the zone this name server is authoritative for. her whole domain, literally.ns_tsigβ the tsig key that should be used to protect messages sent to this name server. β οΈ this field is currently unused and must be set toNULL. don't come for her, she's not active yet.ns_security_optionsβ the security options for the zone. β οΈ this field is currently unused and must be set toZONE_USE_NOTHING. respect the assignment bestie.ns_statusβ the status of the zone, i.e. how the zone info was obtained. the invoker must set this value toSR_ZI_STATUS_UNSET. zone info obtained through referrals has a value ofSR_ZI_STATUS_LEARNEDfor this field. glow-up arc πns_optionsβ specifies additional resolver flags. the currently defined flags are:SR_QUERY_RECURSE, which sets the "Recursion Desired" flagSR_QUERY_SET_DO, which sets the "DNSSEC OK" bit in the EDNS0 headerSR_QUERY_SET_CD, which sets the "DNSSEC CD" bit in the EDNS0 headerSR_QUERY_DEBUG, which enables debugging- and
SR_QUERY_VALIDATING_STUB_FLAGSsets bothSR_QUERY_SET_DOandSR_QUERY_SET_CD. two for one, we love a bundle π
ns_retryβ the maximum number of attempts that must be made to get a name from an unresponsive name server before giving up. know your limits βns_retransβ the retransmission interval, in seconds, for queries sent to unresponsive name servers. give her a sec πns_nextβ the address of the next name server in the list. the group chat chain πns_number_of_addressesβ the number of elements in the arrayns_addresses. β οΈ this field is currently unused. (yes the heading saysns_addresses, we report what the page says, no cap)ns_addressesβ the IP address of the name server. where she lives π
β¨ OTHER SYMBOLS EXPORTED β¨
the libsres library also exports these BIND functions, and you can find their documentation in the BIND sources and documentation manuals (go read those, i'm not doing their whole job for them π):
res_nametoclass
res_nametotype
ns_name_ntop
ns_name_pton
ns_name_unpack
ns_parse_ttl
p_class
p_section
p_type
and here's the tea: the p_type() function exported from libsres has been augmented so it recognizes the various DNSSEC type codes such as DNSKEY, RRSIG, NSEC, NSEC3 and DLV. she got upgraded and she ate π₯
β¨ RETURN VALUES β¨
every one of these, no skipping, we are thorough in this household π
SR_UNSETβ No error.SR_CALL_ERRORβ An invalid parameter was passed toget(),query_send(), orresponse_recv().SR_INTERNAL_ERRORβ The resolver encountered some internal error.SR_TSIG_ERRORβ The resolver encountered some TSIG-related error. this is currently not implemented.SR_NO_ANSWERβ No answers were received from any name server.SR_NO_ANSWER_YETβ No answer currently available; the query is still active. she's still cooking π³SR_HEADER_ERRORβ The length and count of records in the header were incorrect.SR_NXDOMAINβ The queried name did not exist. she's not real bestie πSR_FORMERRβ The name server was not able to parse the query message.SR_SERVFAILβ The name server was not reachable.SR_NOTIMPLβ A particular functionality is not yet implemented.SR_REFUSEDβ The name server refused to answer this query. rude.SR_DNS_GENERIC_FAILUREβ Other failure returned by the name server and reflected in the returned message RCODE.SR_EDNS_VERSION_ERRORβ The EDNS version was not recognizedSR_NAME_EXPANSION_FAILUREβ A failure was encountered while trying to expand a compressed domain name.
β¨ CURRENT STATUS β¨
- There is currently no support for IPv6. yeah. i know. π
- There is limited support for specifying resolver policy; members of the
struct name_serverare still subject to change. so don't get too attached to her fields, they might glow up again π
β¨ COPYRIGHT β¨
Copyright 2004-2013 SPARTA, Inc. All rights reserved. See the COPYING file included with the dnssec-tools package for details.
β¨ SEE ALSO β¨
okay that's the whole page bestie, you're officially educated ππ this was libsres(3) from the Programmer's Manual, and the page footer said it was generated by perl v5.14.3 on 2013-02-27 β so shoutout to that vintage energy, she's been iconic since 2013 and she's still serving π«Άβ¨π
π¦ where this page comes from
- arch rolling: dnssec-tools 2.2.3-16 Β· BSD
- fedora 43: dnssec-tools-libs-devel 2.2.3-30.fc43 Β· LicenseRef-Callaway-BSD
- fedora 43: dnssec-tools-libs-devel 2.2.3-30.fc43 Β· LicenseRef-Callaway-BSD
- fedora 44: dnssec-tools-libs-devel 2.2.3-32.fc44 Β· LicenseRef-Callaway-BSD
- fedora 44: dnssec-tools-libs-devel 2.2.3-32.fc44 Β· LicenseRef-Callaway-BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms