Coder Social home page Coder Social logo

c-robinson / iplib Goto Github PK

View Code? Open in Web Editor NEW
138.0 138.0 23.0 147 KB

A library for working with IP addresses and networks in Go

License: MIT License

Go 100.00%
cidr go golang-library golang-tools ip ipaddress ipaddresses ipv4 ipv4-address ipv6 ipv6-address ipv6-subnetting library subnet subnet-calculator subnetting

iplib's People

Contributors

0xd61 avatar c-robinson avatar luisdavim avatar pic4xiu avatar ryanfolsom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

iplib's Issues

NextNet seems to return the wrong value

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

Integer overflow on 32bit targets

This line causes an integer overflow when compiling for arm.

iplib/net6.go

Line 337 in d4ce4cb

sizes := []int{math.MaxUint32}

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

Incorrect Example Using iplib.Net4

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

test suite issue on 32-bit archs: cannot use MaxIPv4 (untyped int constant 4294967295) as int value in argument to t.Errorf (overflows)

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.