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

Allow reading unmasked address when passed a CIDR string #67

Open
TJNII opened this issue Mar 2, 2024 · 0 comments
Open

Allow reading unmasked address when passed a CIDR string #67

TJNII opened this issue Mar 2, 2024 · 0 comments

Comments

@TJNII
Copy link

TJNII commented Mar 2, 2024

This behavior caught me by surprise:

> ip = IPAddr.new('1.2.3.4/16')
=> #<IPAddr: IPv4:1.2.0.0/255.255.0.0>       
> ip.to_s
=> "1.2.0.0"           

Looking at the code I believe this is happening at https://github.com/ruby/ipaddr/blob/master/lib/ipaddr.rb#L649-L651, which is a very old commit, so this behavior is clearly expected. For my use case I need the host bits unmasked, so I want to parse 1.2.3.4/16 and be able to read back something like ip.address as 1.2.3.4 and the netmask as 255.255.0.0. It looks like that's not currently possible with this gem, which surprises me. Am I overlooking a method, or is there a nuance in the CIDR spec implemented here I've forgotten?

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

No branches or pull requests

1 participant