github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/ipv4/genericopt_posix.go (about)

     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.
     4  
     5  // +build darwin dragonfly freebsd linux netbsd openbsd windows
     6  
     7  package ipv4
     8  
     9  import "syscall"
    10  
    11  // TOS returns the type-of-service field value for outgoing packets.
    12  func (c *genericOpt) TOS() (int, error) {
    13  	if !c.ok() {
    14  		return 0, syscall.EINVAL
    15  	}
    16  	fd, err := c.sysfd()
    17  	if err != nil {
    18  		return 0, err
    19  	}
    20  	return getInt(fd, &sockOpts[ssoTOS])
    21  }
    22  
    23  // SetTOS sets the type-of-service field value for future outgoing
    24  // packets.
    25  func (c *genericOpt) SetTOS(tos int) error {
    26  	if !c.ok() {
    27  		return syscall.EINVAL
    28  	}
    29  	fd, err := c.sysfd()
    30  	if err != nil {
    31  		return err
    32  	}
    33  	return setInt(fd, &sockOpts[ssoTOS], tos)
    34  }
    35  
    36  // TTL returns the time-to-live field value for outgoing packets.
    37  func (c *genericOpt) TTL() (int, error) {
    38  	if !c.ok() {
    39  		return 0, syscall.EINVAL
    40  	}
    41  	fd, err := c.sysfd()
    42  	if err != nil {
    43  		return 0, err
    44  	}
    45  	return getInt(fd, &sockOpts[ssoTTL])
    46  }
    47  
    48  // SetTTL sets the time-to-live field value for future outgoing
    49  // packets.
    50  func (c *genericOpt) SetTTL(ttl int) error {
    51  	if !c.ok() {
    52  		return syscall.EINVAL
    53  	}
    54  	fd, err := c.sysfd()
    55  	if err != nil {
    56  		return err
    57  	}
    58  	return setInt(fd, &sockOpts[ssoTTL], ttl)
    59  }