github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/ipv6/control_unix.go (about)

     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  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     6  
     7  package ipv6
     8  
     9  import "github.com/Andyfoo/golang/x/net/internal/socket"
    10  
    11  func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error {
    12  	opt.Lock()
    13  	defer opt.Unlock()
    14  	if so, ok := sockOpts[ssoReceiveTrafficClass]; ok && cf&FlagTrafficClass != 0 {
    15  		if err := so.SetInt(c, boolint(on)); err != nil {
    16  			return err
    17  		}
    18  		if on {
    19  			opt.set(FlagTrafficClass)
    20  		} else {
    21  			opt.clear(FlagTrafficClass)
    22  		}
    23  	}
    24  	if so, ok := sockOpts[ssoReceiveHopLimit]; ok && cf&FlagHopLimit != 0 {
    25  		if err := so.SetInt(c, boolint(on)); err != nil {
    26  			return err
    27  		}
    28  		if on {
    29  			opt.set(FlagHopLimit)
    30  		} else {
    31  			opt.clear(FlagHopLimit)
    32  		}
    33  	}
    34  	if so, ok := sockOpts[ssoReceivePacketInfo]; ok && cf&flagPacketInfo != 0 {
    35  		if err := so.SetInt(c, boolint(on)); err != nil {
    36  			return err
    37  		}
    38  		if on {
    39  			opt.set(cf & flagPacketInfo)
    40  		} else {
    41  			opt.clear(cf & flagPacketInfo)
    42  		}
    43  	}
    44  	if so, ok := sockOpts[ssoReceivePathMTU]; ok && cf&FlagPathMTU != 0 {
    45  		if err := so.SetInt(c, boolint(on)); err != nil {
    46  			return err
    47  		}
    48  		if on {
    49  			opt.set(FlagPathMTU)
    50  		} else {
    51  			opt.clear(FlagPathMTU)
    52  		}
    53  	}
    54  	return nil
    55  }