Repository navigation
nshlib/nsh_netcmds: set AI_CANONNAME and SOCK_STREAM hints in cmd_nslookup - #3913
Open
Swatantra-66 wants to merge 1 commit into
Open
Swatantra-66 wants to merge 1 commit into
Swatantra-66 wants to merge 1 commit into
Conversation
…ookup cmd_nslookup() previously called getaddrinfo() with hints == NULL. When ai_socktype is unspecified (0), getaddrinfo() performs multi-transport expansion and returns distinct records for all supported transports (both SOCK_STREAM and SOCK_DGRAM), resulting in duplicate IP entries being printed for each host. Additionally, IEEE Std 1003.1 (POSIX) specifies that ai_canonname is only guaranteed in the first returned addrinfo structure when AI_CANONNAME is explicitly set in hints.ai_flags. This commit: 1. Specifies AI_CANONNAME and SOCK_STREAM in hints so cmd_nslookup() returns a single record per IP address. 2. Uses the first result's ai_canonname with a fallback to argv[1] across all rows. 3. Fixes pre-existing nxstyle declaration blank line warnings in wget_callback() and cmd_wget(). Signed-off-by: Swatantra Yadav <maverickswatantra@gmail.com>
Swatantra-66
force-pushed
the
fix/nsh-nslookup-hints
branch
from
October 25, 2026 11:51
01871cd to
6466934
Compare
xiaoxiang781216
approved these changes
Oct 25, 2026
casaroli
approved these changes
Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to apache/nuttx#20691 (addressing review suggestion from @casaroli).
Previously,
cmd_nslookup()innshlib/nsh_netcmds.ccalledgetaddrinfo()withhints == NULL.When
ai_socktypeis unspecified (0), POSIX-compliantgetaddrinfo()(such as afterapache/nuttxPR #20691) performs multi-transport expansion and returns distinct records for all supported transports (bothSOCK_STREAMandSOCK_DGRAM), causingnslookupto iterate and print duplicate IP entries for every host.Additionally, per IEEE Std 1003.1 (POSIX):
ai_canonnameshould be explicitly requested viahints.ai_flags = AI_CANONNAME.ai_canonnameis only guaranteed to be set on the first returnedaddrinfostructure (info->ai_canonname). For hosts with multiple addresses (e.g., dual-stack IPv4/IPv6 or multiple A records), subsequentnext->ai_canonnameentries can beNULL.This PR:
struct addrinfo hintswithhints.ai_socktype = SOCK_STREAMso thatcmd_nslookup()receives a single clean record per resolved IP address.hints.ai_flags = AI_CANONNAMEto formally request the canonical name.info->ai_canonname != NULL ? info->ai_canonname : argv[1]across all output rows so each address line prints the host name safely without passingNULLto%s.Impact
nshlib:nslookupcommand displays single, clean entries per IP address with the canonical host name properly populated.Zero breaking changes to other NSH commands.
0
nxstyleerrors.Testing
Verified with
git diff --check(0 whitespace errors).Validated column length and code style against
nxstyleguidelines (max line 75 chars, 0 tabs, clean variable scoping).