Add single-lane SLP support to .GOMP_SIMD_LANE vectorization
[official-gcc.git] / libgo / go / syscall / lsf_linux.go
blobf38de6209623fe5c0c5ed9452c578e28d53e06b2
1 // Copyright 2011 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.
5 // Linux socket filter
7 package syscall
9 import (
10 "unsafe"
13 // Deprecated: Use golang.org/x/net/bpf instead.
14 func LsfStmt(code, k int) *SockFilter {
15 return &SockFilter{Code: uint16(code), K: uint32(k)}
18 // Deprecated: Use golang.org/x/net/bpf instead.
19 func LsfJump(code, k, jt, jf int) *SockFilter {
20 return &SockFilter{Code: uint16(code), Jt: uint8(jt), Jf: uint8(jf), K: uint32(k)}
23 // Deprecated: Use golang.org/x/net/bpf instead.
24 func LsfSocket(ifindex, proto int) (int, error) {
25 var lsall SockaddrLinklayer
26 // This is missing SOCK_CLOEXEC, but adding the flag
27 // could break callers.
28 s, e := Socket(AF_PACKET, SOCK_RAW, proto)
29 if e != nil {
30 return 0, e
32 p := (*[2]byte)(unsafe.Pointer(&lsall.Protocol))
33 p[0] = byte(proto >> 8)
34 p[1] = byte(proto)
35 lsall.Ifindex = ifindex
36 e = Bind(s, &lsall)
37 if e != nil {
38 Close(s)
39 return 0, e
41 return s, nil
44 type iflags struct {
45 name [IFNAMSIZ]byte
46 flags uint16
49 // Deprecated: Use golang.org/x/net/bpf instead.
50 func SetLsfPromisc(name string, m bool) error {
51 s, e := cloexecSocket(AF_INET, SOCK_DGRAM, 0)
52 if e != nil {
53 return e
55 defer Close(s)
56 var ifl iflags
57 copy(ifl.name[:], []byte(name))
58 _, _, ep := Syscall(SYS_IOCTL, uintptr(s), SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
59 if ep != 0 {
60 return Errno(ep)
62 if m {
63 ifl.flags |= uint16(IFF_PROMISC)
64 } else {
65 ifl.flags &^= uint16(IFF_PROMISC)
67 _, _, ep = Syscall(SYS_IOCTL, uintptr(s), SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
68 if ep != 0 {
69 return Errno(ep)
71 return nil
74 // Deprecated: Use golang.org/x/net/bpf instead.
75 func AttachLsf(fd int, i []SockFilter) error {
76 var p SockFprog
77 p.Len = uint16(len(i))
78 p.Filter = (*SockFilter)(unsafe.Pointer(&i[0]))
79 return setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, unsafe.Pointer(&p), Socklen_t(unsafe.Sizeof(p)))
82 // Deprecated: Use golang.org/x/net/bpf instead.
83 func DetachLsf(fd int) error {
84 var dummy int
85 return setsockopt(fd, SOL_SOCKET, SO_DETACH_FILTER, unsafe.Pointer(&dummy), Socklen_t(unsafe.Sizeof(dummy)))