// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Linux socket filter

package syscall

import (
	
)

// Deprecated: Use golang.org/x/net/bpf instead.
func (,  int) *SockFilter {
	return &SockFilter{Code: uint16(), K: uint32()}
}

// Deprecated: Use golang.org/x/net/bpf instead.
func (, , ,  int) *SockFilter {
	return &SockFilter{Code: uint16(), Jt: uint8(), Jf: uint8(), K: uint32()}
}

// Deprecated: Use golang.org/x/net/bpf instead.
func (,  int) (int, error) {
	var  SockaddrLinklayer
	// This is missing SOCK_CLOEXEC, but adding the flag
	// could break callers.
	,  := Socket(AF_PACKET, SOCK_RAW, )
	if  != nil {
		return 0, 
	}
	 := (*[2]byte)(unsafe.Pointer(&.Protocol))
	[0] = byte( >> 8)
	[1] = byte()
	.Ifindex = 
	 = Bind(, &)
	if  != nil {
		Close()
		return 0, 
	}
	return , nil
}

type iflags struct {
	name  [IFNAMSIZ]byte
	flags uint16
}

// Deprecated: Use golang.org/x/net/bpf instead.
func ( string,  bool) error {
	,  := Socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0)
	if  != nil {
		return 
	}
	defer Close()
	var  iflags
	copy(.name[:], []byte())
	, ,  := Syscall(SYS_IOCTL, uintptr(), SIOCGIFFLAGS, uintptr(unsafe.Pointer(&)))
	if  != 0 {
		return Errno()
	}
	if  {
		.flags |= uint16(IFF_PROMISC)
	} else {
		.flags &^= uint16(IFF_PROMISC)
	}
	_, _,  = Syscall(SYS_IOCTL, uintptr(), SIOCSIFFLAGS, uintptr(unsafe.Pointer(&)))
	if  != 0 {
		return Errno()
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func ( int,  []SockFilter) error {
	var  SockFprog
	.Len = uint16(len())
	.Filter = (*SockFilter)(unsafe.Pointer(&[0]))
	return setsockopt(, SOL_SOCKET, SO_ATTACH_FILTER, unsafe.Pointer(&), unsafe.Sizeof())
}

// Deprecated: Use golang.org/x/net/bpf instead.
func ( int) error {
	var  int
	return setsockopt(, SOL_SOCKET, SO_DETACH_FILTER, unsafe.Pointer(&), unsafe.Sizeof())
}