ARES_PARSE_TXT_REPLY(3)

πŸ“¦
version 1.34.9 Β· 4 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

πŸ’– ares_parse_txt_reply(3) πŸ’–

okay bestie, sit down, hydrate, because today we're parsing TXT records and it's genuinely not that deep. this one lives in the Library Functions Manual, and yes it's the ares_parse_txt_reply page, the moment you've all been waiting for. ✨


🌸 NAME 🌸

ares_parse_txt_reply β€” parse a reply to a DNS query of type TXT. that's it. that's the job. lowkey iconic.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <ares.h>

int ares_parse_txt_reply(const unsigned char* abuf, int alen,
                         struct ares_txt_reply **txt_out);

int ares_parse_txt_reply_ext(const unsigned char* abuf, int alen,
                             struct ares_txt_ext **txt_out);

two functions. one include. we love a two-for-one. πŸ’…


✨ DESCRIPTION ✨

so ares_parse_txt_reply(3) and ares_parse_txt_reply_ext(3) take the response to a query of type TXT and turn it into a linked list β€” one element per sub-string, no skimping β€” of struct ares_txt_reply (or struct ares_txt_ext if you're fancy and called the _ext one).

the parameters abuf and alen give the contents of the response, fr fr. the result gets stored in allocated memory, and a pointer to it gets stored into the variable pointed to by txt_out.

🫢 important, bestie: it is the caller's responsibility to free the resulting txt_out structure when it is no longer needed, using ares_free_data(3). do NOT forget. that's a leak and we don't do leaks in this house. 😭

the structure ares_txt_reply contains the following fields:

struct ares_txt_reply {
  struct ares_txt_reply  *next;
  unsigned int  length;
  unsigned char *txt;
};

the structure ares_txt_ext contains the following fields:

struct ares_txt_ext {
  struct ares_txt_ext  *next;
  unsigned int  length;
  unsigned char *txt;
  unsigned char record_start;
};

now the tea on record_start β˜• β€” in struct ares_txt_ext, the record_start field is 1 if this structure is a start of a TXT record, and 0 if the structure is a continuation of a previous record. the linked list of the struct ares_txt_ext will have at least one item with record_start equal to 1, and may have some items with record_start equal to 0 between them. so like, the 1s are the main characters and the 0s are the supporting cast. πŸŽ€

these sequences of struct ares_txt_ext (starting from the item with record_start equal to 1, and ending right before the record start item) may be treated as either components of a single TXT record or as a multi-parted TXT record, depending on your particular use case. you get to decide. it's giving choose-your-own-adventure. 🌈


πŸ”₯ RETURN VALUES πŸ”₯

ares_parse_txt_reply (ares_parse_txt_reply_ext) can return any of the following values:

  • ARES_SUCCESS β€” the response was successfully parsed. slay. ate. no notes. πŸ‘‘
  • ARES_EBADRESP β€” the response was malformatted. πŸ’€ something's wrong with it, bestie.
  • ARES_ENODATA β€” the response did not contain an answer to the query. it's giving silence. πŸ™ˆ
  • ARES_ENOMEM β€” memory was exhausted. the vibes are depleted, we're out of room. 😭

πŸ’œ AVAILABILITY πŸ’œ

this function was first introduced in c-ares version 1.7.0. a classic. vintage. still hitting. ⭐


🌟 SEE ALSO 🌟


and that's the whole page, bestie!! 🫢 go forth and parse responsibly. this was the ares_parse_txt_reply(3) page from the Library Functions Manual, dated 27 October 2009 β€” mwah, ily, bye!! πŸ’–πŸŽ€πŸ¦‹