added support for string type
[govpp.git] / vendor / github.com / google / gopacket / afpacket / sockopt_linux.go
1 // Copyright 2012 Google, Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree.
6
7 // +build linux
8
9 package afpacket
10
11 import (
12         "unsafe"
13
14         "golang.org/x/sys/unix"
15 )
16
17 // setsockopt provides access to the setsockopt syscall.
18 func setsockopt(fd, level, name int, val unsafe.Pointer, vallen uintptr) error {
19         _, _, errno := unix.Syscall6(
20                 unix.SYS_SETSOCKOPT,
21                 uintptr(fd),
22                 uintptr(level),
23                 uintptr(name),
24                 uintptr(val),
25                 vallen,
26                 0,
27         )
28         if errno != 0 {
29                 return error(errno)
30         }
31
32         return nil
33 }
34
35 // getsockopt provides access to the getsockopt syscall.
36 func getsockopt(fd, level, name int, val unsafe.Pointer, vallen uintptr) error {
37         _, _, errno := unix.Syscall6(
38                 unix.SYS_GETSOCKOPT,
39                 uintptr(fd),
40                 uintptr(level),
41                 uintptr(name),
42                 uintptr(val),
43                 vallen,
44                 0,
45         )
46         if errno != 0 {
47                 return error(errno)
48         }
49
50         return nil
51 }
52
53 // htons converts a short (uint16) from host-to-network byte order.
54 // Thanks to mikioh for this neat trick:
55 // https://github.com/mikioh/-stdyng/blob/master/afpacket.go
56 func htons(i uint16) uint16 {
57         return (i<<8)&0xff00 | i>>8
58 }