syncthing/vendor/golang.org/x/net/ipv6/sockopt_unix.go
Jakob Borg 65aaa607ab Use Go 1.5 vendoring instead of Godeps
Change made by:

- running "gvt fetch" on each of the packages mentioned in
  Godeps/Godeps.json
- `rm -rf Godeps`
- tweaking the build scripts to not mention Godeps
- tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly
  (to avoid testing vendor)
- tweaking the build scripts to not juggle GOPATH for Godeps and instead
  set GO15VENDOREXPERIMENT.

This also results in some updated packages at the same time I bet.

Building with Go 1.3 and 1.4 still *works* but won't use our vendored
dependencies - the user needs to have the actual packages in their
GOPATH then, which they'll get with a normal "go get". Building with Go
1.6+ will get our vendored dependencies by default even when not using
our build script, which is nice.

By doing this we gain some freedom in that we can pick and choose
manually what to include in vendor, as it's not based on just dependency
analysis of our own code. This is also a risk as we might pick up
dependencies we are unaware of, as the build may work locally with those
packages present in GOPATH. On the other hand the build server will
detect this as it has no packages in it's GOPATH beyond what is included
in the repo.

Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
2016-03-05 21:21:24 +01:00

123 lines
3.3 KiB
Go

// Copyright 2013 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.
// +build darwin dragonfly freebsd linux netbsd openbsd
package ipv6
import (
"net"
"os"
"unsafe"
)
func getInt(fd int, opt *sockOpt) (int, error) {
if opt.name < 1 || opt.typ != ssoTypeInt {
return 0, errOpNoSupport
}
var i int32
l := sysSockoptLen(4)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(i), nil
}
func setInt(fd int, opt *sockOpt, v int) error {
if opt.name < 1 || opt.typ != ssoTypeInt {
return errOpNoSupport
}
i := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), sysSockoptLen(4)))
}
func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
if opt.name < 1 || opt.typ != ssoTypeInterface {
return nil, errOpNoSupport
}
var i int32
l := sysSockoptLen(4)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
if i == 0 {
return nil, nil
}
ifi, err := net.InterfaceByIndex(int(i))
if err != nil {
return nil, err
}
return ifi, nil
}
func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error {
if opt.name < 1 || opt.typ != ssoTypeInterface {
return errOpNoSupport
}
var i int32
if ifi != nil {
i = int32(ifi.Index)
}
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), sysSockoptLen(4)))
}
func getICMPFilter(fd int, opt *sockOpt) (*ICMPFilter, error) {
if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
return nil, errOpNoSupport
}
var f ICMPFilter
l := sysSockoptLen(sysSizeofICMPv6Filter)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
return &f, nil
}
func setICMPFilter(fd int, opt *sockOpt, f *ICMPFilter) error {
if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
return errOpNoSupport
}
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), sysSizeofICMPv6Filter))
}
func getMTUInfo(fd int, opt *sockOpt) (*net.Interface, int, error) {
if opt.name < 1 || opt.typ != ssoTypeMTUInfo {
return nil, 0, errOpNoSupport
}
var mi sysIPv6Mtuinfo
l := sysSockoptLen(sysSizeofIPv6Mtuinfo)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil {
return nil, 0, os.NewSyscallError("getsockopt", err)
}
if mi.Addr.Scope_id == 0 {
return nil, int(mi.Mtu), nil
}
ifi, err := net.InterfaceByIndex(int(mi.Addr.Scope_id))
if err != nil {
return nil, 0, err
}
return ifi, int(mi.Mtu), nil
}
func setGroup(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
if opt.name < 1 {
return errOpNoSupport
}
switch opt.typ {
case ssoTypeIPMreq:
return setsockoptIPMreq(fd, opt, ifi, grp)
case ssoTypeGroupReq:
return setsockoptGroupReq(fd, opt, ifi, grp)
default:
return errOpNoSupport
}
}
func setSourceGroup(fd int, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
if opt.name < 1 || opt.typ != ssoTypeGroupSourceReq {
return errOpNoSupport
}
return setsockoptGroupSourceReq(fd, opt, ifi, grp, src)
}