Skip to content

Instantly share code, notes, and snippets.

@ammario
Last active February 7, 2025 05:24
Show Gist options
  • Select an option

  • Save ammario/649d4c0da650162efd404af23e25b86b to your computer and use it in GitHub Desktop.

Select an option

Save ammario/649d4c0da650162efd404af23e25b86b to your computer and use it in GitHub Desktop.

Revisions

  1. ammario revised this gist Aug 29, 2023. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion ipint.go
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    func ip2int(ip net.IP) uint32 {
    if len(ip) == 16 {
    return binary.BigEndian.Uint32(ip[12:16])
  2. ammario revised this gist Aug 29, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ipint.go
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@

    func ip2int(ip net.IP) uint32 {
    if len(ip) == 16 {
    panic("no sane way to convert ipv6 into uint32")
    return binary.BigEndian.Uint32(ip[12:16])
    }
    return binary.BigEndian.Uint32(ip)
    }
  3. ammario revised this gist Oct 7, 2022. No changes.
  4. ammario revised this gist Oct 7, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ipint.go
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    func ip2int(ip net.IP) uint32 {
    if len(ip) == 16 {
    return binary.BigEndian.Uint32(ip[12:16])
    panic("no sane way to convert ipv6 into uint32")
    }
    return binary.BigEndian.Uint32(ip)
    }
  5. ammario created this gist Jun 5, 2016.
    12 changes: 12 additions & 0 deletions ipint.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    func ip2int(ip net.IP) uint32 {
    if len(ip) == 16 {
    return binary.BigEndian.Uint32(ip[12:16])
    }
    return binary.BigEndian.Uint32(ip)
    }

    func int2ip(nn uint32) net.IP {
    ip := make(net.IP, 4)
    binary.BigEndian.PutUint32(ip, nn)
    return ip
    }