gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

sys_freebsd.go (4267B)


      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 	"runtime"
     10 	"strings"
     11 	"syscall"
     12 	"unsafe"
     13 
     14 	"golang.org/x/net/internal/iana"
     15 	"golang.org/x/net/internal/socket"
     16 
     17 	"golang.org/x/sys/unix"
     18 )
     19 
     20 var (
     21 	ctlOpts = [ctlMax]ctlOpt{
     22 		ctlTrafficClass: {unix.IPV6_TCLASS, 4, marshalTrafficClass, parseTrafficClass},
     23 		ctlHopLimit:     {unix.IPV6_HOPLIMIT, 4, marshalHopLimit, parseHopLimit},
     24 		ctlPacketInfo:   {unix.IPV6_PKTINFO, sizeofInet6Pktinfo, marshalPacketInfo, parsePacketInfo},
     25 		ctlNextHop:      {unix.IPV6_NEXTHOP, sizeofSockaddrInet6, marshalNextHop, parseNextHop},
     26 		ctlPathMTU:      {unix.IPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
     27 	}
     28 
     29 	sockOpts = map[int]sockOpt{
     30 		ssoTrafficClass:        {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_TCLASS, Len: 4}},
     31 		ssoHopLimit:            {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_UNICAST_HOPS, Len: 4}},
     32 		ssoMulticastInterface:  {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_MULTICAST_IF, Len: 4}},
     33 		ssoMulticastHopLimit:   {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_MULTICAST_HOPS, Len: 4}},
     34 		ssoMulticastLoopback:   {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_MULTICAST_LOOP, Len: 4}},
     35 		ssoReceiveTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_RECVTCLASS, Len: 4}},
     36 		ssoReceiveHopLimit:     {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_RECVHOPLIMIT, Len: 4}},
     37 		ssoReceivePacketInfo:   {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_RECVPKTINFO, Len: 4}},
     38 		ssoReceivePathMTU:      {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_RECVPATHMTU, Len: 4}},
     39 		ssoPathMTU:             {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_PATHMTU, Len: sizeofIPv6Mtuinfo}},
     40 		ssoChecksum:            {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.IPV6_CHECKSUM, Len: 4}},
     41 		ssoICMPFilter:          {Option: socket.Option{Level: iana.ProtocolIPv6ICMP, Name: unix.ICMP6_FILTER, Len: sizeofICMPv6Filter}},
     42 		ssoJoinGroup:           {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.MCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
     43 		ssoLeaveGroup:          {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.MCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
     44 		ssoJoinSourceGroup:     {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.MCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
     45 		ssoLeaveSourceGroup:    {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.MCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
     46 		ssoBlockSourceGroup:    {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.MCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
     47 		ssoUnblockSourceGroup:  {Option: socket.Option{Level: iana.ProtocolIPv6, Name: unix.MCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
     48 	}
     49 )
     50 
     51 func init() {
     52 	if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
     53 		archs, _ := syscall.Sysctl("kern.supported_archs")
     54 		for _, s := range strings.Fields(archs) {
     55 			if s == "amd64" {
     56 				compatFreeBSD32 = true
     57 				break
     58 			}
     59 		}
     60 	}
     61 }
     62 
     63 func (sa *sockaddrInet6) setSockaddr(ip net.IP, i int) {
     64 	sa.Len = sizeofSockaddrInet6
     65 	sa.Family = syscall.AF_INET6
     66 	copy(sa.Addr[:], ip)
     67 	sa.Scope_id = uint32(i)
     68 }
     69 
     70 func (pi *inet6Pktinfo) setIfindex(i int) {
     71 	pi.Ifindex = uint32(i)
     72 }
     73 
     74 func (mreq *ipv6Mreq) setIfindex(i int) {
     75 	mreq.Interface = uint32(i)
     76 }
     77 
     78 func (gr *groupReq) setGroup(grp net.IP) {
     79 	sa := (*sockaddrInet6)(unsafe.Pointer(&gr.Group))
     80 	sa.Len = sizeofSockaddrInet6
     81 	sa.Family = syscall.AF_INET6
     82 	copy(sa.Addr[:], grp)
     83 }
     84 
     85 func (gsr *groupSourceReq) setSourceGroup(grp, src net.IP) {
     86 	sa := (*sockaddrInet6)(unsafe.Pointer(&gsr.Group))
     87 	sa.Len = sizeofSockaddrInet6
     88 	sa.Family = syscall.AF_INET6
     89 	copy(sa.Addr[:], grp)
     90 	sa = (*sockaddrInet6)(unsafe.Pointer(&gsr.Source))
     91 	sa.Len = sizeofSockaddrInet6
     92 	sa.Family = syscall.AF_INET6
     93 	copy(sa.Addr[:], src)
     94 }