1 // Copyright 2012 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.
5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris
12 "golang.org/x/net/internal/iana"
13 "golang.org/x/net/internal/socket"
16 func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error {
19 if so, ok := sockOpts[ssoReceiveTTL]; ok && cf&FlagTTL != 0 {
20 if err := so.SetInt(c, boolint(on)); err != nil {
29 if so, ok := sockOpts[ssoPacketInfo]; ok {
30 if cf&(FlagSrc|FlagDst|FlagInterface) != 0 {
31 if err := so.SetInt(c, boolint(on)); err != nil {
35 opt.set(cf & (FlagSrc | FlagDst | FlagInterface))
37 opt.clear(cf & (FlagSrc | FlagDst | FlagInterface))
41 if so, ok := sockOpts[ssoReceiveDst]; ok && cf&FlagDst != 0 {
42 if err := so.SetInt(c, boolint(on)); err != nil {
51 if so, ok := sockOpts[ssoReceiveInterface]; ok && cf&FlagInterface != 0 {
52 if err := so.SetInt(c, boolint(on)); err != nil {
56 opt.set(FlagInterface)
58 opt.clear(FlagInterface)
65 func marshalTTL(b []byte, cm *ControlMessage) []byte {
66 m := socket.ControlMessage(b)
67 m.MarshalHeader(iana.ProtocolIP, sysIP_RECVTTL, 1)
71 func parseTTL(cm *ControlMessage, b []byte) {
72 cm.TTL = int(*(*byte)(unsafe.Pointer(&b[:1][0])))