Getting and parsing a HTTPS record

Brad House brad at brad-house.com
Thu Jan 16 15:05:42 CET 2025


And the docs for the HTTPS/SVCB params are here: 
https://c-ares.org/docs/ares_dns_opt_get_datatype.html  that provide a 
little more info (such as required datatype for known params) than the 
header currently does.

On 1/16/25 8:50 AM, Brad House wrote:
> Heh, I hate writing docs ... so, I made a few huge manpages.  If you 
> have someone that loves writing docs to help out, send them this way :)
>
> I wouldn't recommend using ares_dns_record_create() as you have to 
> jump through a lot of hoops to do things properly, like setting up 
> EDNS and whatnot.  Just use ares_query_dnsrec() which does the heavy 
> lifting for you.
>
> The worst part in all honesty is the 'option' syntax, as HTTPS/SVCB 
> have dynamic option/parameter records that can be attached, and can be 
> in any format.  I extracted some code from adig for printing those.  
> I'm not sure if you need all the data or if you're just looking for 
> some certain data.  The current/known params are:
>
> /*! SVCB (and HTTPS) RR known parameters */
> typedef enum {
>   /*! Mandatory keys in this RR (RFC 9460 Section 8) */
>   ARES_SVCB_PARAM_MANDATORY = 0,
>   /*! Additional supported protocols (RFC 9460 Section 7.1) */
>   ARES_SVCB_PARAM_ALPN = 1,
>   /*! No support for default protocol (RFC 9460 Section 7.1) */
>   ARES_SVCB_PARAM_NO_DEFAULT_ALPN = 2,
>   /*! Port for alternative endpoint (RFC 9460 Section 7.2) */
>   ARES_SVCB_PARAM_PORT = 3,
>   /*! IPv4 address hints (RFC 9460 Section 7.3) */
>   ARES_SVCB_PARAM_IPV4HINT = 4,
>   /*! RESERVED (held for Encrypted ClientHello) */
>   ARES_SVCB_PARAM_ECH = 5,
>   /*! IPv6 address hints (RFC 9460 Section 7.3) */
>   ARES_SVCB_PARAM_IPV6HINT = 6
> } ares_svcb_param_t;
>
> See my attached example, compile/run like:
>
> cc -I/usr/local/include -Wall -o ares-https ares-https.c -Wl,-rpath 
> /usr/local/lib -lcares
>
> ./ares-https www.cloudflare.com
> Result: Successful completion, timeouts: 0
> HTTPS Priority: 1
> HTTPS Target:
> HTTPS Params:
>     alpn(1)="h3, h2"
>     ipv4hint(4)=104.16.123.96, 104.16.124.96
>     ipv6hint(6)=2606:4700::6810:7b60, 2606:4700::6810:7c60
>
>
> -Brad
>
>
>
> On 1/16/25 3:05 AM, Daniel Stenberg via c-ares wrote:
>> Hi,
>>
>> I want is to create a request for a HTTPS record and get the answer 
>> or an error. I struggle to understand how to do this. The 
>> ares_dns_record_create is hard to follow and understand what sequence 
>> to use and how to glue everything together.
>>
>> I think the docs would benefit from being split up to document one 
>> function per man page as God intended. With examples showing how they 
>> can be used.
>>
>> This is my initial attempt to send off the HTTPS RR request:
>>
>>       ares_dns_record_create(&dnsrec, 0 /* id */, 0, /* flags */
>>                              ARES_OPCODE_QUERY, ARES_RCODE_NOERROR);
>>       ares_dns_record_query_add(dnsrec, hostname,
>>                                 ARES_REC_TYPE_HTTPS, ARES_CLASS_IN);
>>       ares_send_dnsrec((ares_channel)resolver_hgandle,
>>                        dnsrec, dnsrec_done_cb, data, NULL);
>>
>> But I simply cannot figure out how the dnsrec_done_cb callback should 
>> be written to parse the incoming reply?
>>
>> What helpers should I use?
>>


More information about the c-ares mailing list