Skip to content

net: preserve IPv6 selection for dual-stack sockets - #409

Open
hja-oss wants to merge 8 commits into
lsof-org:masterfrom
hja-oss:fix/darwin-dual-stack-selection
Open

hja-oss wants to merge 8 commits into
lsof-org:masterfrom
hja-oss:fix/darwin-dual-stack-selection

Conversation

@hja-oss

@hja-oss hja-oss commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Keep IPv4-mapped sockets IPv6 for selection on Darwin, Linux, FreeBSD, NetBSD, and OpenBSD, while preserving dotted IPv4 address display. These sockets match IPv6 filters, not IPv4 filters, consistent with the documented socket-family rule.

Treat bracketed IPv4-mapped addresses as IPv6 even without an explicit 6 qualifier. Normalize Darwin’s IPv4-compatible representation before matching.

Extend regression coverage for TCP and connected UDP sockets, qualified and unqualified mapped-address filters, numeric display, and exit status. Clarify the selection rules in the man pages.

@jiegec jiegec changed the title darwin: match dual-stack sockets with IPv6 filters fix dual-stack socket selection for IPv4-mapped addresses Nov 23, 2026
@jiegec
jiegec force-pushed the fix/darwin-dual-stack-selection branch from cd1429e to 1fa8912 Compare November 23, 2026 06:44
@jiegec
jiegec force-pushed the fix/darwin-dual-stack-selection branch from 1fa8912 to cf09ca2 Compare November 23, 2026 06:47
@jiegec
jiegec force-pushed the fix/darwin-dual-stack-selection branch from cf09ca2 to 0f0cbe1 Compare November 23, 2026 06:47
@jiegec

jiegec commented Nov 23, 2026

Copy link
Copy Markdown
Member

@hja-oss I have unified the dual stack socket behavior across different dialects, please check if it is a better solution

@hja-oss

hja-oss commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Hey, my original PR was intentionally limited to Darwin and aimed to preserve IPv4 matching. But, separating socket-family selection from address display looks like a cleaner way to align the dialects with the documented behavior. I am all in with your changes going broader and changing how existing IPv4 filters select dual-stack connections on other dialects. This is your call, if you are ok doing it in a single PR, I am also ok.

Just a quick note from myside, maybe it would be good to clarify the intended behavior of an unqualified mapped-address filter such as -i@[::ffff:127.0.0.1]? As I read the parser, it is still treated as IPv4, whereas the explicitly qualified -i6 form is treated as IPv6, see (https://github.com/hja-oss/lsof/blob/0f0cbe195f6d03ee5d0595df4a369607f2445380/src/arg.c#L1393-L1406):
For an IPv4-mapped address:

  • i6@[::ffff:127.0.0.1] sets ft to 6, so the filter keeps the IPv6 address and uses AF_INET6.
  • i@[::ffff:127.0.0.1] has no family qualifier, so it enters the else branch: the parser extracts the IPv4 portion and uses AF_INET.

@hja-oss hja-oss changed the title fix dual-stack socket selection for IPv4-mapped addresses net: preserve IPv6 selection for dual-stack sockets Nov 25, 2026
@hja-oss

hja-oss commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@jiegec I have done some changes but I’ve kept your cross-dialect approach and updated the parser so -i@[::ffff:127.0.0.1] is treated as IPv6, just like the explicit -i6 form. I also clarified the man pages and extended the tests, including connected UDP coverage.
Give your feedback on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants