Skip to content

Instantly share code, notes, and snippets.

@MalteJ
Created December 7, 2018 18:25
Show Gist options
  • Save MalteJ/61976b6a433253bb07c732018f4cad0d to your computer and use it in GitHub Desktop.
Save MalteJ/61976b6a433253bb07c732018f4cad0d to your computer and use it in GitHub Desktop.
func macToIPv6LinkLocal(mac []byte) (net.IP, error) {
if len(mac) != 6 {
return nil, fmt.Errorf("Invalid MAC address")
}
ipv6 := net.IP{0xfe, 0x80, 0, 0, 0, 0, 0, 0, mac[0] ^ 0x02, mac[1], mac[2], 0xff, 0xfe, mac[3], mac[4], mac[5]}
if !ipv6.IsLinkLocalUnicast() {
return nil, fmt.Errorf("invalid calculation")
}
return ipv6, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment