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

Wrong broadcast address #105

Open
virgiledelplace opened this issue Nov 27, 2018 · 8 comments
Open

Wrong broadcast address #105

virgiledelplace opened this issue Nov 27, 2018 · 8 comments

Comments

@virgiledelplace
Copy link

Hello community,

i got a problem with the IPAddress lib, i dont know if it's a bug, or just a mistake from me.

I have this address ' 46.17.68.76/31 ', i want to have the broadcast addess, then i make :

network = "46.17.68.76/31"
@ip     = IPAddress.parse(network)
puts @ip.broadcast 

the output : @address="255.255.255.255"

but for me the broadcast address for ' 46.17.68.76/31 ' is : 46.17.68.77

Thank's for your help!

@virgiledelplace virgiledelplace changed the title Wrong broadcast addresse Wrong broadcast address Nov 27, 2018
@crosson
Copy link

crosson commented Nov 27, 2018

The broadcast actually should be 255.255.255.255 on /31 links. The library is correct and I think I asked this same question some time back and a kind gentlemen pointed this out.

Checkout and search for section section 4.3.3.9,

@virgiledelplace
Copy link
Author

The broadcast actually should be 255.255.255.255 on /31 links. The library is correct and I think I asked this same question some time back and a kind gentlemen pointed this out.

Checkout and search for section section 4.3.3.9,

I don't find your question, can you give me the link pls ?

@crossonST
Copy link

Yes I looked earlier today. I could be wrong on memory. It was a very long time ago.

At any rate it looks be behaving correctly in line with rfc3021.

@virgiledelplace
Copy link
Author

Yes I looked earlier today. I could be wrong on memory. It was a very long time ago.

At any rate it looks be behaving correctly in line with rfc3021.

Yes i look this rules, but i dont understand how, it's work for /30 -> output : 46.17.68.79
But with /31, he output 255.255.255.255 ...

@crosson
Copy link

crosson commented Nov 28, 2018

Are you curious where this is done in the library? Or curious why /30 behaves differently? A /30 has 4 addresses so you have an address for a network, two hosts, and a broadcast. It doesn't have the problem defined inrfc3021. So yes /31 and /30 behave differently as they should.

@msimkins
Copy link

msimkins commented Nov 28, 2018 via email

@virgiledelplace
Copy link
Author

Hello guys,

thank's for your feedback.

Following your response, I discussed it with our network expert.

We use the / 31s with nat IP addresses, and the library works with direct ip addresses if I understood correctly.

So the library just does not work with how we use our IP addresses, I will try to modify the library to respond our needs, I will fork if it can serve.

Thank you.

@crossonST
Copy link

IDK if this helps at all but instead of using the broadcast object to get the last IP you could use the entries method.

Instead of
net.broadcast.address

Use

irb(main):014:0> net = IPAddress "192.168.1.0/31"
=> #<IPAddress::IPv4:0x00000000b30498 @address="192.168.1.0", @prefix=31, @octets=[192, 168, 1, 0], @u32=3232235776>
irb(main):015:0> net.entries.first.address
=> "192.168.1.0"
irb(main):016:0> net.entries.last.address
=> "192.168.1.1"
irb(main):017:0> net.entries
=> [#<IPAddress::IPv4:0x00000000b07f48 @address="192.168.1.0", @prefix=31, @octets=[192, 168, 1, 0], @u32=3232235776>, #<IPAddress::IPv4:0x00000000b07430 @address="192.168.1.1", @prefix=31, @octets=[192, 168, 1, 1], @u32=3232235777>]
irb(main):019:0> addresses = net.collect { |o| o.address }
=> ["192.168.1.0", "192.168.1.1"]
irb(main):020:0>

Which will return each object in your network inside an array which you can iterate over.

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

No branches or pull requests

4 participants