You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 lines
1.7 KiB

  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ipv6
  5. import (
  6. "net"
  7. "syscall"
  8. "golang.org/x/net/internal/iana"
  9. )
  10. const (
  11. // See ws2tcpip.h.
  12. sysIPV6_UNICAST_HOPS = 0x4
  13. sysIPV6_MULTICAST_IF = 0x9
  14. sysIPV6_MULTICAST_HOPS = 0xa
  15. sysIPV6_MULTICAST_LOOP = 0xb
  16. sysIPV6_JOIN_GROUP = 0xc
  17. sysIPV6_LEAVE_GROUP = 0xd
  18. sysIPV6_PKTINFO = 0x13
  19. sizeofSockaddrInet6 = 0x1c
  20. sizeofIPv6Mreq = 0x14
  21. sizeofIPv6Mtuinfo = 0x20
  22. sizeofICMPv6Filter = 0
  23. )
  24. type sockaddrInet6 struct {
  25. Family uint16
  26. Port uint16
  27. Flowinfo uint32
  28. Addr [16]byte /* in6_addr */
  29. Scope_id uint32
  30. }
  31. type ipv6Mreq struct {
  32. Multiaddr [16]byte /* in6_addr */
  33. Interface uint32
  34. }
  35. type ipv6Mtuinfo struct {
  36. Addr sockaddrInet6
  37. Mtu uint32
  38. }
  39. type icmpv6Filter struct {
  40. // TODO(mikio): implement this
  41. }
  42. var (
  43. ctlOpts = [ctlMax]ctlOpt{}
  44. sockOpts = [ssoMax]sockOpt{
  45. ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt},
  46. ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface},
  47. ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt},
  48. ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt},
  49. ssoJoinGroup: {iana.ProtocolIPv6, sysIPV6_JOIN_GROUP, ssoTypeIPMreq},
  50. ssoLeaveGroup: {iana.ProtocolIPv6, sysIPV6_LEAVE_GROUP, ssoTypeIPMreq},
  51. }
  52. )
  53. func (sa *sockaddrInet6) setSockaddr(ip net.IP, i int) {
  54. sa.Family = syscall.AF_INET6
  55. copy(sa.Addr[:], ip)
  56. sa.Scope_id = uint32(i)
  57. }
  58. func (mreq *ipv6Mreq) setIfindex(i int) {
  59. mreq.Interface = uint32(i)
  60. }