compiler: rationalize external symbol names
[official-gcc.git] / libgo / go / syscall / lsf_linux.go
blob16b702a9840d7d95957fa605c3e679d6b89580f6
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 s, e := Socket(AF_PACKET, SOCK_RAW, proto)
27 if e != nil {
28 return 0, e
30 p := (*[2]byte)(unsafe.Pointer(&lsall.Protocol))
31 p[0] = byte(proto >> 8)
32 p[1] = byte(proto)
33 lsall.Ifindex = ifindex
34 e = Bind(s, &lsall)
35 if e != nil {
36 Close(s)
37 return 0, e
39 return s, nil
42 type iflags struct {
43 name [IFNAMSIZ]byte
44 flags uint16
47 // Deprecated: Use golang.org/x/net/bpf instead.
48 func SetLsfPromisc(name string, m bool) error {
49 s, e := Socket(AF_INET, SOCK_DGRAM, 0)
50 if e != nil {
51 return e
53 defer Close(s)
54 var ifl iflags
55 copy(ifl.name[:], []byte(name))
56 _, _, ep := Syscall(SYS_IOCTL, uintptr(s), SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
57 if ep != 0 {
58 return Errno(ep)
60 if m {
61 ifl.flags |= uint16(IFF_PROMISC)
62 } else {
63 ifl.flags &^= uint16(IFF_PROMISC)
65 _, _, ep = Syscall(SYS_IOCTL, uintptr(s), SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
66 if ep != 0 {
67 return Errno(ep)
69 return nil
72 // Deprecated: Use golang.org/x/net/bpf instead.
73 func AttachLsf(fd int, i []SockFilter) error {
74 var p SockFprog
75 p.Len = uint16(len(i))
76 p.Filter = (*SockFilter)(unsafe.Pointer(&i[0]))
77 return setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, unsafe.Pointer(&p), Socklen_t(unsafe.Sizeof(p)))
80 // Deprecated: Use golang.org/x/net/bpf instead.
81 func DetachLsf(fd int) error {
82 var dummy int
83 return setsockopt(fd, SOL_SOCKET, SO_DETACH_FILTER, unsafe.Pointer(&dummy), Socklen_t(unsafe.Sizeof(dummy)))