David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 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 | package ipv4 |
| 6 | |
| 7 | import "syscall" |
| 8 | |
| 9 | // TOS returns the type-of-service field value for outgoing packets. |
| 10 | func (c *genericOpt) TOS() (int, error) { |
| 11 | if !c.ok() { |
| 12 | return 0, syscall.EINVAL |
| 13 | } |
| 14 | so, ok := sockOpts[ssoTOS] |
| 15 | if !ok { |
| 16 | return 0, errOpNoSupport |
| 17 | } |
| 18 | return so.GetInt(c.Conn) |
| 19 | } |
| 20 | |
| 21 | // SetTOS sets the type-of-service field value for future outgoing |
| 22 | // packets. |
| 23 | func (c *genericOpt) SetTOS(tos int) error { |
| 24 | if !c.ok() { |
| 25 | return syscall.EINVAL |
| 26 | } |
| 27 | so, ok := sockOpts[ssoTOS] |
| 28 | if !ok { |
| 29 | return errOpNoSupport |
| 30 | } |
| 31 | return so.SetInt(c.Conn, tos) |
| 32 | } |
| 33 | |
| 34 | // TTL returns the time-to-live field value for outgoing packets. |
| 35 | func (c *genericOpt) TTL() (int, error) { |
| 36 | if !c.ok() { |
| 37 | return 0, syscall.EINVAL |
| 38 | } |
| 39 | so, ok := sockOpts[ssoTTL] |
| 40 | if !ok { |
| 41 | return 0, errOpNoSupport |
| 42 | } |
| 43 | return so.GetInt(c.Conn) |
| 44 | } |
| 45 | |
| 46 | // SetTTL sets the time-to-live field value for future outgoing |
| 47 | // packets. |
| 48 | func (c *genericOpt) SetTTL(ttl int) error { |
| 49 | if !c.ok() { |
| 50 | return syscall.EINVAL |
| 51 | } |
| 52 | so, ok := sockOpts[ssoTTL] |
| 53 | if !ok { |
| 54 | return errOpNoSupport |
| 55 | } |
| 56 | return so.SetInt(c.Conn, ttl) |
| 57 | } |