blob: 119bf841b6d382d2038228659c201883dd8437a2 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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
5package ipv4
6
7import "syscall"
8
9// TOS returns the type-of-service field value for outgoing packets.
10func (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.
23func (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.
35func (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.
48func (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}