Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an option to show ipv4, ipv6 or both #3959

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

voiceroy
Copy link

@voiceroy voiceroy commented Feb 26, 2025

Fixes #3956.

Users can now set family to ipv4, ipv6, ipv4_6 to show the IPv4, IPv6, or both. With the default being ipv4.

@voiceroy voiceroy changed the title Provide an option to show ipv4 or ipv6 or both of them Provide an option to show ipv4, ipv6 or both Feb 26, 2025
Comment on lines 332 to 336
} else if (addr_pref_ == ip_addr_pref::IPV4_6) {
final_ipaddr_ = ipaddr_;
final_ipaddr_ += " | ";
final_ipaddr_ += ipaddr6_;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to put each address family on each own line?

I've just tried the patch out, and

  1. the first line gets really long with both in there, esp. since IPv6 address tend to be long.
  2. on dual-stack, the netmask is displayed incorrectly, as it takes the one from legacy IPv4 for both. E.g. it displays 192.168.0.10 | fc00::1/24 via 192.168.0.1 if your interface has both 192.168.0.10/24 and fc00::1/64 as address.
  3. on dual-stack, only the gateway for the legacy IPv4 net is displayed.

Putting each address family on its own line would fix both problems.

Copy link
Author

@voiceroy voiceroy Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Something like this? Would a newline be good, or some other character?
else if (addr_pref_ == ip_addr_pref::IPV4_6) {
    final_ipaddr_ = ipaddr_;
    final_ipaddr_ += "\n";
    final_ipaddr_ += ipaddr6_;
  }
  1. Adding new format replacements will fix it
  2. There's a bug that affects gateway address retrieval 1564, 1279. Personally I haven't got any results with {gwaddr} in the format string.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Something like this? Would a newline be good, or some other character?

Yes, that's what I had in mind too. 👍

  1. There's a bug that affects gateway address retrieval 1564, 1279. Personally I haven't got any results with {gwaddr} in the format string.

I see. I'd say that this is out of scope for this PR then. I might also look into this in the future, after this has been merged - to fix the immediate issues first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the changes and verify that they work as intended?

@voiceroy voiceroy force-pushed the ip-address-display branch from a111762 to 5e4dac1 Compare March 5, 2025 09:59
42LoCo42 added a commit to 42LoCo42/obscura that referenced this pull request Mar 5, 2025
42LoCo42 added a commit to 42LoCo42/obscura that referenced this pull request Mar 5, 2025
@voiceroy voiceroy requested a review from christoph-heiss March 7, 2025 08:05
@VAWVAW
Copy link
Contributor

VAWVAW commented Mar 8, 2025

Could you add different {ipaddr4} and {ipaddr6} formats so that users have more flexibility?

My use case is that I want only the ipv4 address in the bar but both addresses in the tooltip.

Copy link

@christoph-heiss christoph-heiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more, small change :^)

The format (apart from the broken netmask as already discussed) now seems fine. It's kinda sad that still only a minority of people care about IPv6, seeing the state of this module.

Anyway; one more thing I noticed: when a legacy v4 address is added, the module updates fine. But if the legacy address is removed again, it completely disappears from the bar.

Comment on lines +333 to +334
final_ipaddr_ = ipaddr_;
final_ipaddr_ += '\n';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final_ipaddr_ = ipaddr_;
final_ipaddr_ += '\n';
if (!ipaddr_.empty()) {
final_ipaddr_ = ipaddr_;
final_ipaddr_ += '\n';
}

Small nit; to avoid an unnecessary newline/empty line.

@voiceroy
Copy link
Author

voiceroy commented Mar 9, 2025

Could you add different {ipaddr4} and {ipaddr6} formats so that users have more flexibility?

My use case is that I want only the ipv4 address in the bar but both addresses in the tooltip.

I think you can just display ipv4 in the bar and ipv4_6 in the tooltip.

@VAWVAW
Copy link
Contributor

VAWVAW commented Mar 9, 2025

I think you can just display ipv4 in the bar and ipv4_6 in the tooltip.

How would I do this? As far a I see, setting family affects the format of {ipaddr} in both format and tooltip-format.

@voiceroy
Copy link
Author

voiceroy commented Mar 9, 2025

I think you can just display ipv4 in the bar and ipv4_6 in the tooltip.

How would I do this? As far a I see, setting family affects the format of {ipaddr} in both format and tooltip-format.

Oh yeah, sorry. Didn't think about that. Maybe you can create a separate pr for that if you don't mind.

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.

network module only shown ipv6 address
3 participants