ARES_CREATE_QUERY(3)

πŸ“¦
version 1.34.9 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’… straight outta the Library Functions Manual, it's your girl ares_create_query(3) πŸ’…


πŸŽ€ NAME πŸŽ€

ares_create_query β€” compose a single-question DNS query buffer βœ¨πŸ¦‹


🫢 SYNOPSIS 🫢

#include <ares.h>

int ares_create_query(const char *name,
                      int dnsclass,
                      int type,
                      unsigned short id,
                      int rd,
                      unsigned char **buf,
                      int *buflen,
                      int max_udp_size)

πŸ’– DESCRIPTION πŸ’–

okay bestie, first things first, and I need you to hear me on this one:

This function is deprecated as of c-ares 1.22. Please use ares_dns_record_create(3) instead. No cap. She's retired, she's still here, but she's retired. πŸ’€

So, ares_create_query(3) composes a DNS query with a single question. Just the one. One question, one query, main character energy only.

The parameter name gives the query name as a NUL-terminated C string of period-separated labels, optionally ending with a period. And listen β€” periods and backslashes that live inside a label have to be escaped with a backslash. (the page spells it "backlash" and I love that for her, but yeah: backslash πŸ’…)

The parameters dnsclass and type give the class and the type of the query, using the values defined in <arpa/nameser.h>. Iconic, classic, we love a header file.

The parameter id gives a 16-bit identifier for the query. Sixteen bits of pure identity, slay.

The parameter rd should be nonzero if recursion is desired, and zero if it's not. That's it. That's the whole vibe check.

The query gets placed in an allocated buffer, a pointer to which will be stored in the variable pointed to by buf, and the length of which will be stored in the variable pointed to by buflen. So you hand her two pointers and she fills them in. 🫢

It is the caller's responsibility to free this buffer using ares_free_string(3) when it is no longer needed. Not me forgetting to free, couldn't be me, but like… don't be that girl. Free your buffer. 🧚

And finally, the parameter max_udp_size should be nonzero to activate EDNS. Usage of ares_create_query(3) with max_udp_size set to zero is equivalent to using ares_mkquery(3). Same energy, different name tag.


✨ RETURN VALUES ✨

ares_create_query can return any of the following values, and yes we're listing all of them:

  • ARES_SUCCESS β€” construction of the DNS query succeeded. We ate. πŸ‘‘
  • ARES_ENOTFOUND β€” the query name name refers to a .onion domain name. See RFC 7686. (she said no onions today πŸ™ˆ)
  • ARES_EBADNAME β€” the query name name could not be encoded as a domain name, either because it contained a zero-length label or because it contained a label of more than 63 characters. Long labels are not the move, bestie.
  • ARES_ENOMEM β€” memory was exhausted. 😭

🌈 AVAILABILITY 🌈

Added in c-ares 1.10.0. A whole era. ⭐


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, bestie!! πŸŽ€ this little love letter was dated 17 Aug 2012, and you just finished reading ARES_CREATE_QUERY(3) β€” go free your strings and hydrate, periodt πŸ’…πŸ’–πŸ¦‹