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

   ## Summary
   
   `gethostbyname()`, `gethostbyaddr()` and `res_query()` give their errors in 
`h_errno`, but the C library had no function that gives the message for an 
`h_errno` value. Programs from other systems call `hstrerror()` or `herror()` 
for this and did not compile.
   
   This PR adds both functions to `libs/libc/netdb` and declares them in 
`<netdb.h>`, next to the other glibc-style interfaces, with `CONFIG_LIBC_NETDB`:
   
   - `hstrerror()` gives the message for 0, `HOST_NOT_FOUND`, `NO_DATA`, 
`NO_RECOVERY` and `TRY_AGAIN`, with the same texts as glibc. Other values give 
"Unknown resolver error".
   - `herror(s)` writes the message for `h_errno` to `stderr`, after `s` and ": 
" when `s` is not `NULL` and not empty.
   
   The second commit describes the two functions in 
`Documentation/reference/user/11_network.rst`.
   
   ## Impact
   
   Two new functions with `CONFIG_LIBC_NETDB`. Existing functions do not 
change. Every build mode (C library code).
   
   ## Testing
   
   Test program `hstrerr.c` on `qemu-armv8a:knsh` (QEMU with HVF), with 
`CONFIG_NET`, `CONFIG_NET_IPv4`, `CONFIG_NETDEV_LATEINIT`, 
`CONFIG_NET_SOCKOPTS`, `CONFIG_LIBC_NETDB` and `CONFIG_PIPES` (the `herror()` 
cases read `stderr` through a pipe). The expected texts are those of glibc.
   
   | Case | master | this PR |
   |---|---|---|
   | `hstrerror()` of 0, 1, 2, 3, 4 and 99 | does not compile | the glibc 
texts: PASS |
   | `herror("pfx")` with `h_errno` = `TRY_AGAIN` | does not compile | "pfx: 
Host name lookup failure": PASS |
   | `herror(NULL)`, `herror("")` | does not compile | the message alone: PASS |
   
   ostest exits with status 0 on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` (with 
the same options).
   
   Build, each OK: with the options above: `qemu-armv8a:nsh` (flat, arm64), 
`qemu-armv8a:knsh` (kernel, arm64), `rv-virt:nsh64` (flat, rv64), 
`rv-virt:pnsh64` (protected, rv64), `rv-virt:knsh64` (kernel, rv64); 
`qemu-armv8a:netnsh` with CMake; `lm3s6965-ek:qemu-protected` (protected, 
armv7-m) as it is.
   
   `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