mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-09 23:27:58 +02:00
[client] Add embeddable library (#3239)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"net"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@ -26,3 +27,22 @@ type RemoveHookFunc func(connID ConnectionID) error
|
||||
func GenerateConnID() ConnectionID {
|
||||
return ConnectionID(uuid.NewString())
|
||||
}
|
||||
|
||||
func GetLastIPFromNetwork(network *net.IPNet, fromEnd int) net.IP {
|
||||
// Calculate the last IP in the CIDR range
|
||||
var endIP net.IP
|
||||
for i := 0; i < len(network.IP); i++ {
|
||||
endIP = append(endIP, network.IP[i]|^network.Mask[i])
|
||||
}
|
||||
|
||||
// convert to big.Int
|
||||
endInt := big.NewInt(0)
|
||||
endInt.SetBytes(endIP)
|
||||
|
||||
// subtract fromEnd from the last ip
|
||||
fromEndBig := big.NewInt(int64(fromEnd))
|
||||
resultInt := big.NewInt(0)
|
||||
resultInt.Sub(endInt, fromEndBig)
|
||||
|
||||
return resultInt.Bytes()
|
||||
}
|
||||
|
Reference in New Issue
Block a user