c-robinson / iplib Goto Github PK
View Code? Open in Web Editor NEWA library for working with IP addresses and networks in Go
License: MIT License
A library for working with IP addresses and networks in Go
License: MIT License
See this example:
package main
import (
"fmt"
"github.com/c-robinson/iplib"
)
func GetNextSubnet(lastCIDR string, nextSize int) {
lastNet := iplib.Net4FromStr(lastCIDR)
if nextSize == 0 {
nextSize, _ = lastNet.Mask().Size()
}
nextNet := lastNet.NextNet(nextSize)
fmt.Printf("Next net: %s\n", nextNet)
}
func main() {
GetNextSubnet("10.80.6.0/24", 18)
}
Outputs:
Next net: 10.80.0.0/18
Am I doing something wrong?
If I use the same subnet size, I get an expected result
GetNextSubnet("10.80.6.0/24", 0) // 0 default to the same size
output:
Next net: 10.80.7.0/24
and with:
GetNextSubnet("10.80.6.0/24", 22)
it goes backwards?
Next net: 10.80.4.0/22
This line causes an integer overflow when compiling for arm.
Line 337 in d4ce4cb
The solution would be to use uint32 instead of int for the datatype.
The error message is:
vendor/github.com/c-robinson/iplib/net6.go:337:21: constant 4294967295 overflows int
Hi,
I found incorrect dos in readme file related to using iplib.Net4. In this line:
n := NewNet4(net.ParseIP("192.168.0.0"), 16)
it should be:
n := iplib.NewNet4(net.ParseIP("192.168.0.0"), 16)
and in this one:
fmt.Println(n.Network()) // 192.168.0.0
it should be:
fmt.Println(n.IP()) // 192.168.0.0
Hi,
I'm packaging your software for Debian (as a build-dependency for https://www.crowdsec.net/) and I'm seeing the following test failure on 32-bit archs (e.g. armel, armhf, i386 as seen on https://ci.debian.net/packages/g/golang-github-c-robinson-iplib/):
dh_auto_test -O--builddirectory=_build -O--buildsystem=golang
cd _build && go test -vet=off -v -p 32 github.com/c-robinson/iplib github.com/c-robinson/iplib/iana github.com/c-robinson/iplib/iid
# github.com/c-robinson/iplib [github.com/c-robinson/iplib.test]
src/github.com/c-robinson/iplib/iplib_test.go:362:30: cannot use MaxIPv4 (untyped int constant 4294967295) as int value in argument to t.Errorf (overflows)
FAIL github.com/c-robinson/iplib [build failed]
It can be trivially reproduced in an i386 chroot on an amd64 machine.
Casting the constant explicitly to uint
in that error message does the trick, but maybe it should or could have been declared a uint32
in the first place? That being said, I don't know anything about Go, so I'll just mention the patch I'm considering applying to iplib_test.go
in the Debian package until I've gotten some feedback here:
- t.Errorf("want %d got %d", MaxIPv4, i)
+ t.Errorf("want %d got %d", uint(MaxIPv4), i)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.