This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/vendor/golang.org/x/net/ipv4/sys_freebsd.go

74 lines
2.3 KiB
Go
Raw Normal View History

2016-07-26 01:30:28 +05:30
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ipv4
import (
"net"
"runtime"
"strings"
"syscall"
"unsafe"
)
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
}
sockOpts = [ssoMax]sockOpt{
ssoTOS: {sysIP_TOS, ssoTypeInt},
ssoTTL: {sysIP_TTL, ssoTypeInt},
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
ssoJoinGroup: {sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
ssoLeaveGroup: {sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
ssoJoinSourceGroup: {sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
ssoLeaveSourceGroup: {sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
ssoBlockSourceGroup: {sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
ssoUnblockSourceGroup: {sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
}
)
func init() {
freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
if freebsdVersion >= 1000000 {
sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
}
if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
archs, _ := syscall.Sysctl("kern.supported_archs")
for _, s := range strings.Fields(archs) {
if s == "amd64" {
freebsd32o64 = true
break
}
}
}
}
func (gr *sysGroupReq) setGroup(grp net.IP) {
sa := (*sysSockaddrInet)(unsafe.Pointer(&gr.Group))
sa.Len = sysSizeofSockaddrInet
sa.Family = syscall.AF_INET
copy(sa.Addr[:], grp)
}
func (gsr *sysGroupSourceReq) setSourceGroup(grp, src net.IP) {
sa := (*sysSockaddrInet)(unsafe.Pointer(&gsr.Group))
sa.Len = sysSizeofSockaddrInet
sa.Family = syscall.AF_INET
copy(sa.Addr[:], grp)
sa = (*sysSockaddrInet)(unsafe.Pointer(&gsr.Source))
sa.Len = sysSizeofSockaddrInet
sa.Family = syscall.AF_INET
copy(sa.Addr[:], src)
}