18 lines
261 B
Go
18 lines
261 B
Go
|
package converter
|
||
|
|
||
|
import (
|
||
|
"encoding/binary"
|
||
|
"net"
|
||
|
)
|
||
|
|
||
|
func IPv4ToInt(ip net.IP) int32 {
|
||
|
return int32(binary.BigEndian.Uint32(ip.To4()))
|
||
|
}
|
||
|
|
||
|
func IntToIPv4(n int32) net.IP {
|
||
|
b := make([]byte, 4)
|
||
|
binary.BigEndian.PutUint32(b, uint32(n))
|
||
|
return net.IP(b)
|
||
|
|
||
|
}
|