github.com/cilium/cilium@v1.16.2/pkg/byteorder/byteorder.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package byteorder
     5  
     6  import (
     7  	"net"
     8  	"net/netip"
     9  )
    10  
    11  // NetIPv4ToHost32 converts an net.IP to a uint32 in host byte order. ip
    12  // must be a IPv4 address, otherwise the function will panic.
    13  func NetIPv4ToHost32(ip net.IP) uint32 {
    14  	ipv4 := ip.To4()
    15  	_ = ipv4[3] // Assert length of ipv4.
    16  	return Native.Uint32(ipv4)
    17  }
    18  
    19  func NetIPAddrToHost32(ip netip.Addr) uint32 {
    20  	ipv4 := ip.As4()
    21  	return Native.Uint32(ipv4[:])
    22  }