ruby / ruby/ipaddr

Allow reading unmasked address when passed a CIDR string

Open
#67 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
82
Forks
42
Avg merge
2h 24m
Merged PRs (30d)
3

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/ipaddr.rb at lines 649-651 and trace how a CIDR string is parsed and stored. Compare the current address and netmask accessors with the requested behavior, then define the API change so the unmasked address and netmask can both be read back for 1.2.3.4/16.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.