python-ipy icon indicating copy to clipboard operation
python-ipy copied to clipboard

.broadcast() returns IPv4('0.0.0.2') for IPv6('::2/128')

Open jn0 opened this issue 5 years ago • 3 comments

https://github.com/autocracy/python-ipy/blob/b8eb507bf2e94e878e092b16746d2cd8a058294f/IPy.py#L821 missing IP version propagation as compared to https://github.com/autocracy/python-ipy/blob/b8eb507bf2e94e878e092b16746d2cd8a058294f/IPy.py#L811

Reproduce with:

import IPy; print(IPy.IP('::3/128').broadcast().version()) # 4

In general, I'd prefer to have .first_address() and .last_address() methods as IPv6 address has no "broadcast" part.

// random losses of edits observed //

jn0 avatar Nov 30 '20 11:11 jn0

So I should raise an error on .broadcast() when it's v6?

IPRange[0] and IPRange[-1] I think will provide you with first and last. I'll look later.

autocracy avatar Dec 01 '20 20:12 autocracy

So I should raise an error on .broadcast() when it's v6?

I think, no. It will break lots of code. As a first mitigation I'd propose to pass the version info (like in .net() method).

Please, keep in mind that, for instance, https://github.com/irrdnet/irrd makes heavy use of .net()/.broadcast() (yepp, instead of ip[0]/ip[-1]) and is a production code (not mine :smile: )

jn0 avatar Dec 02 '20 12:12 jn0

I think you're generally right here. Patch encouraged, otherwise I'll code it up next time I get nudged to do a release for other reasons.

autocracy avatar Dec 15 '20 19:12 autocracy