ipld-eth-server/vendor/github.com/aristanetworks/goarista/dscp/tos_unix.go
Matt K 293dd2e848 Add vendor dir (#16) (#4)
* Add vendor dir so builds dont require dep

* Pin specific version go-eth version
2018-01-29 13:44:18 -06:00

34 lines
931 B
Go

// Copyright (c) 2017 Arista Networks, Inc.
// Use of this source code is governed by the Apache License 2.0
// that can be found in the COPYING file.
package dscp
import (
"net"
"os"
"reflect"
"golang.org/x/sys/unix"
)
// This works for the UNIX implementation of netFD, i.e. not on Windows and Plan9.
// This kludge is needed until https://github.com/golang/go/issues/9661 is fixed.
// value can be the reflection of a connection or a dialer.
func setTOS(ip net.IP, value reflect.Value, tos byte) error {
netFD := value.Elem().FieldByName("fd").Elem()
fd := int(netFD.FieldByName("pfd").FieldByName("Sysfd").Int())
var proto, optname int
if ip.To4() != nil {
proto = unix.IPPROTO_IP
optname = unix.IP_TOS
} else {
proto = unix.IPPROTO_IPV6
optname = unix.IPV6_TCLASS
}
if err := unix.SetsockoptInt(fd, proto, optname, int(tos)); err != nil {
return os.NewSyscallError("setsockopt", err)
}
return nil
}