func listenPacket(ifi *net.Interface, proto uint16, cfg Config) (*packetConn, error) {
	filename := "eth-packet-socket"
	// Enabling overriding the socket type via config.
	typ := unix.SOCK_RAW
	if cfg.LinuxSockDGRAM {
		filename = "packet-socket"
		typ = unix.SOCK_DGRAM
	}

	// Open a packet socket using specified socket type. Do not specify
	// a protocol to avoid capturing packets which to not match cfg.Filter.
	// The later call to bind() will set up the correct protocol for us.
	sock, err := unix.Socket(unix.AF_PACKET, typ, 0)
	if err != nil {
		return nil, err
	}

	if err := unix.SetNonblock(sock, true); err != nil {
		return nil, err
	}

	// When using Go 1.12+, the SetNonblock call we just did puts the file
	// descriptor into non-blocking mode. In that case, os.NewFile
	// registers the file descriptor with the runtime poller, which is then
	// used for all subsequent operations.
	//
	// See also: https://golang.org/pkg/os/#NewFile
	f := os.NewFile(uintptr(sock), filename)
	sc, err := f.SyscallConn()
	if err != nil {
		return nil, err
	}

	// Wrap raw socket in socket interface.
	pc, err := newPacketConn(ifi, &sysSocket{f: f, rc: sc}, htons(proto), cfg.Filter)
	if err != nil {
		return nil, err
	}

	pc.noCumulativeStats = cfg.NoCumulativeStats
	return pc, nil
}
// listenPacket creates a net.PacketConn which can be used to send and receive
// data at the device driver level.
listenPacket creates a net.PacketConn which can be used to send and receive
data at the device driver level.
// listenPacket creates a net . PacketConn which can be used to send and receive // data at the device driver level .
func listenPacket(ifi *net.Interface, proto uint16, cfg Config) (*packetConn, error) {
	filename := "eth-packet-socket"
	typ := unix.SOCK_RAW
	if cfg.LinuxSockDGRAM {
		filename = "packet-socket"
		typ = unix.SOCK_DGRAM
	}
	sock, err := unix.Socket(unix.AF_PACKET, typ, 0)
	if err != nil {
		return nil, err
	}
	if err := unix.SetNonblock(sock, true); err != nil {
		return nil, err
	}
	 See also: https:golang.org/pkg/os/#NewFile
	f := os.NewFile(uintptr(sock), filename)
	sc, err := f.SyscallConn()
	if err != nil {
		return nil, err
	}
	 Wrap raw socket in socket interface.
	pc, err := newPacketConn(ifi, &sysSocket{f: f, rc: sc}, htons(proto), cfg.Filter)
	if err != nil {
		return nil, err
	}
	pc.noCumulativeStats = cfg.NoCumulativeStats
	return pc, nil
}
func listenPacket ( ifi * net . Interface , proto uint16 , cfg Config ) ( * packetConn , error ) { filename := " " typ := unix . SOCK_RAW if cfg . LinuxSockDGRAM { filename = " " typ = unix . SOCK_DGRAM } sock , err := unix . Socket ( unix . AF_PACKET , typ , 0 ) if err != nil { return nil , err } if err := unix . SetNonblock ( sock , true ) ; err != nil { return nil , err } f := os . NewFile ( uintptr ( sock ) , filename ) sc , err := f . SyscallConn ( ) if err != nil { return nil , err } pc , err := newPacketConn ( ifi , & sysSocket { f : f , rc : sc } , htons ( proto ) , cfg . Filter ) if err != nil { return nil , err } pc . noCumulativeStats = cfg . NoCumulativeStats return pc , nil }
listenPacket creates a net.PacketConn which can be used to send and receive
data at the device driver level.
listenPacket creates a net . PacketConn which can be used to send and receive data at the device driver level .
// Enabling overriding the socket type via config. // Open a packet socket using specified socket type. Do not specify // a protocol to avoid capturing packets which to not match cfg.Filter. // The later call to bind() will set up the correct protocol for us. // When using Go 1.12+, the SetNonblock call we just did puts the file // descriptor into non-blocking mode. In that case, os.NewFile // registers the file descriptor with the runtime poller, which is then // used for all subsequent operations. // // See also: https://golang.org/pkg/os/#NewFile // Wrap raw socket in socket interface.