github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/net/ipv6/sys_windows.go (about)

     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  
     5  package ipv6
     6  
     7  import (
     8  	"net"
     9  	"syscall"
    10  
    11  	"github.com/hxx258456/ccgo/net/internal/iana"
    12  	"github.com/hxx258456/ccgo/net/internal/socket"
    13  
    14  	"golang.org/x/sys/windows"
    15  )
    16  
    17  const (
    18  	sizeofSockaddrInet6 = 0x1c
    19  
    20  	sizeofIPv6Mreq     = 0x14
    21  	sizeofIPv6Mtuinfo  = 0x20
    22  	sizeofICMPv6Filter = 0
    23  )
    24  
    25  type sockaddrInet6 struct {
    26  	Family   uint16
    27  	Port     uint16
    28  	Flowinfo uint32
    29  	Addr     [16]byte /* in6_addr */
    30  	Scope_id uint32
    31  }
    32  
    33  type ipv6Mreq struct {
    34  	Multiaddr [16]byte /* in6_addr */
    35  	Interface uint32
    36  }
    37  
    38  type ipv6Mtuinfo struct {
    39  	Addr sockaddrInet6
    40  	Mtu  uint32
    41  }
    42  
    43  type icmpv6Filter struct {
    44  	// TODO(mikio): implement this
    45  }
    46  
    47  var (
    48  	ctlOpts = [ctlMax]ctlOpt{}
    49  
    50  	sockOpts = map[int]*sockOpt{
    51  		ssoHopLimit:           {Option: socket.Option{Level: iana.ProtocolIPv6, Name: windows.IPV6_UNICAST_HOPS, Len: 4}},
    52  		ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: windows.IPV6_MULTICAST_IF, Len: 4}},
    53  		ssoMulticastHopLimit:  {Option: socket.Option{Level: iana.ProtocolIPv6, Name: windows.IPV6_MULTICAST_HOPS, Len: 4}},
    54  		ssoMulticastLoopback:  {Option: socket.Option{Level: iana.ProtocolIPv6, Name: windows.IPV6_MULTICAST_LOOP, Len: 4}},
    55  		ssoJoinGroup:          {Option: socket.Option{Level: iana.ProtocolIPv6, Name: windows.IPV6_JOIN_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
    56  		ssoLeaveGroup:         {Option: socket.Option{Level: iana.ProtocolIPv6, Name: windows.IPV6_LEAVE_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
    57  	}
    58  )
    59  
    60  func (sa *sockaddrInet6) setSockaddr(ip net.IP, i int) {
    61  	sa.Family = syscall.AF_INET6
    62  	copy(sa.Addr[:], ip)
    63  	sa.Scope_id = uint32(i)
    64  }
    65  
    66  func (mreq *ipv6Mreq) setIfindex(i int) {
    67  	mreq.Interface = uint32(i)
    68  }