Swatantra-66 opened a new pull request, #3913:
URL: https://github.com/apache/nuttx-apps/pull/3913

   ## Summary
   
   Companion to `apache/nuttx` PR #20691 (addressing review suggestion from 
@casaroli).
   
   Previously, `cmd_nslookup()` in `nshlib/nsh_netcmds.c` called 
`getaddrinfo()` with `hints == NULL`.
   When `ai_socktype` is unspecified (`0`), POSIX-compliant `getaddrinfo()` 
(such as after `apache/nuttx` PR #20691) performs multi-transport expansion and 
returns distinct records for all supported transports (both `SOCK_STREAM` and 
`SOCK_DGRAM`), causing `nslookup` to iterate and print duplicate IP entries for 
every host.
   
   Additionally, per IEEE Std 1003.1 (POSIX):
   1. `ai_canonname` should be explicitly requested via `hints.ai_flags = 
AI_CANONNAME`.
   2. `ai_canonname` is only guaranteed to be set on the first returned 
`addrinfo` structure (`info->ai_canonname`). For hosts with multiple addresses 
(e.g., dual-stack IPv4/IPv6 or multiple A records), subsequent 
`next->ai_canonname` entries can be `NULL`.
   
   This PR:
   1. Defines and passes `struct addrinfo hints` with `hints.ai_socktype = 
SOCK_STREAM` so that `cmd_nslookup()` receives a single clean record per 
resolved IP address.
   2. Sets `hints.ai_flags = AI_CANONNAME` to formally request the canonical 
name.
   3. Uses `info->ai_canonname != NULL ? info->ai_canonname : argv[1]` across 
all output rows so each address line prints the host name safely without 
passing `NULL` to `%s`.
   
   ## Impact
   
   `nshlib`: `nslookup` command displays single, clean entries per IP address 
with the canonical host name properly populated.
   Zero breaking changes to other NSH commands.
   0 `nxstyle` errors.
   
   ## Testing
   
   Verified with `git diff --check` (0 whitespace errors).
   Validated column length and code style against `nxstyle` guidelines (max 
line 75 chars, 0 tabs, clean variable scoping).
   


-- 
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