MCPcopy Create free account
hub / github.com/coder/envbox / mustNextIPv4

Function mustNextIPv4

dockerutil/network.go:30–46  ·  view source on GitHub ↗

Adapted from https://gist.github.com/udhos/b468fbfd376aa0b655b6b0c539a88c03#file-nextip-go-L31

(ip net.IP, inc int)

Source from the content-addressed store, hash-verified

28
29// Adapted from https://gist.github.com/udhos/b468fbfd376aa0b655b6b0c539a88c03#file-nextip-go-L31
30func mustNextIPv4(ip net.IP, inc int) net.IP {
31 ip4 := ip.To4()
32 if ip4 == nil {
33 panic(xerrors.Errorf("invalid IPv4 addr %s", ip.String()))
34 }
35 v := uint32(ip4[0]) << 24
36 v += uint32(ip4[1]) << 16
37 v += uint32(ip4[2]) << 8
38 v += uint32(ip4[3])
39 //nolint:gosec
40 v += uint32(inc)
41 v3 := byte(v & 0xFF)
42 v2 := byte((v >> 8) & 0xFF)
43 v1 := byte((v >> 16) & 0xFF)
44 v0 := byte((v >> 24) & 0xFF)
45 return net.IPv4(v0, v1, v2, v3)
46}

Callers 1

BridgeIPFromCIDRFunction · 0.85

Calls 2

ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected