casaroli opened a new pull request, #20750:
URL: https://github.com/apache/nuttx/pull/20750

   ## Summary
   
   `res_query()` and `res_search()` send a DNS query for any record type (for 
example MX, TXT or SRV) and return the raw answer. Programs that need records 
other than addresses use them. NuttX had neither, and no `arpa/nameser.h` to 
parse the answer.
   
   This PR adds:
   
   - `include/arpa/nameser.h`: the `NS_*` sizes, the `ns_opcode`, `ns_rcode`, 
`ns_class` and `ns_type` values, the 
`NS_GET16`/`NS_PUT16`/`NS_GET32`/`NS_PUT32` macros, `HEADER`, and the BIND 4 
names (`PACKETSZ`, `C_IN`, `T_MX`, `GETSHORT`, ...).
   - `res_mkquery()`: builds a query with a random ID and recursion desired. It 
is always built with `CONFIG_LIBC_NETDB`.
   - `res_send()`: sends over UDP to the name servers of the DNS client, with 
the same timeouts and retries. It skips a server that answers `SERVFAIL` or 
`REFUSED`, and ignores an answer with a wrong ID. There is no TCP fallback: a 
truncated answer comes back with the `TC` bit set.
   - `res_query()`: maps the response code to `h_errno`. `res_search()` is the 
same, because NuttX has no search list.
   
   `res_send()`, `res_query()` and `res_search()` need 
`CONFIG_NETDB_DNSCLIENT`. The last commit describes the four functions in 
`Documentation/reference/user/11_network.rst`.
   
   ## Impact
   
   New header and functions. Nothing else changes.
   
   ## Testing
   
   A test program on `qemu-armv8a:netnsh` (QEMU user networking, DNS server 
10.0.2.3): the query built by `res_mkquery()` has the expected layout, 
`res_query()` for `example.com` returns 2 A records, `res_search()` gives the 
same answer, and a name that does not exist gives `HOST_NOT_FOUND`. The same 
test passes against the macOS host resolver.
   
   Builds: `qemu-armv8a:knsh`, `qemu-armv8a:nsh`, `qemu-armv8a:netnsh`. 
`tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to