mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-11-15 04:36:19 +08:00
1d96981e11
Co-authored-by: Thomas Misilo <tmisilo@ksu.edu> Co-authored-by: Jeffrey Cafferata <jeffrey@jcid.nl>
26 lines
662 B
Go
26 lines
662 B
Go
package rfc4183
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// reverseIPv6 returns the ipv6.arpa string suitable for reverse DNS lookups.
|
|
func reverseIPv6(ip []byte, maskbits int) (arpa string, err error) {
|
|
// Must be IPv6
|
|
if len(ip) != 16 {
|
|
return "", fmt.Errorf("not IPv6")
|
|
}
|
|
|
|
buf := []byte("x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.ip6.arpa")
|
|
// Poke hex digits into the template
|
|
pos := 128/4*2 - 2 // Position of the last "x"
|
|
for _, v := range ip {
|
|
buf[pos] = hexDigit[v>>4]
|
|
buf[pos-2] = hexDigit[v&0xF]
|
|
pos = pos - 4
|
|
}
|
|
// Return only the parts without x's
|
|
return string(buf[(128-maskbits)/4*2:]), nil
|
|
}
|
|
|
|
const hexDigit = "0123456789abcdef"
|