Skip to content

Don't narrow -i to one IP version when -i4 or -i6 follows it - #384

Closed
Ar-maan05 wants to merge 2 commits into
lsof-org:masterfrom
Ar-maan05:inet-version-after-all
Closed

Ar-maan05 wants to merge 2 commits into
lsof-org:masterfrom
Ar-maan05:inet-version-after-all

Conversation

@Ar-maan05

Copy link
Copy Markdown
Contributor

-i -i4 drops IPv6 files, while -i4 -i and -i4 -i6 list both:

-i -i4
before: IPv4 TCP 127.0.0.1:40403
        IPv4 UDP ...
after:  IPv4 TCP 127.0.0.1:43717
        IPv6 TCP [::1]:47787
        IPv4 UDP ...

plain -i leaves FnetTy at 0 meaning "all versions", but the -i4/-i6 code reads 0 as "not set yet" and narrows it. the comment right above says these combine logicaly (-i[46] then -i[64] is the same as -i), so now a following -i4/-i6 keeps all versions.

added case-20-inet-version-after-all.bash with an IPv6 listner. it fails before and passes after, make check is clean.

A plain -i selects all IP versions and leaves FnetTy at 0, but a following -i4 or -i6 treated 0 as unset and narrowed the selection to that version, so "-i -i4" listed no IPv6 files. The comment says sequential -i, -i4 and -i6 combine logically, so keep all versions selected.
Some CI containers have no IPv6 address on lo, so nc cannot bind ::1. Skip like case-20-inet6-socket-endpoint does.
@jiegec

jiegec commented Nov 9, 2026

Copy link
Copy Markdown
Member

Hmm, it contradicts with the docs in the manpage.

@kurok

kurok commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

One thing worth checking before this goes in: the man page already describes the behaviour this change removes. lsof.8 says that -i4 or -i6 given after a plain -i is the same as giving -i4 or -i6 by itself, so the narrowing looks intentional rather than a leftover from reading 0 as "unset". The same wording is in Lsof.8 and docs/manpage.md.

It also shifts a related case: -i4 -i6 -i4 now selects every version, where the documented rules (-i4 then -i6 equals -i, then -i4 after -i equals -i4) would give IPv4 only.

If the new semantics are what the maintainers want, the three doc files should be updated in this PR so they do not contradict the code. Otherwise this is probably a documentation clarification rather than a bug fix.

@Ar-maan05

Copy link
Copy Markdown
Contributor Author

you're right, i missed that the man page spells this out (-i4/-i6 after -i narrows it), so its intended behavior and not a bug. closing this, thanks for looking!

@Ar-maan05 Ar-maan05 closed this Nov 9, 2026
@Ar-maan05
Ar-maan05 deleted the inet-version-after-all branch November 9, 2026 14:29
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.

3 participants