Linux::SocketFilter - interface to Linux's socket packet filtering
Linux::SocketFilter
use Linux::SocketFilter qw( :bpf pack_sock_filter ); use IO::Socket::Packet; use Socket qw( SOCK_DGRAM ); my $sock = IO::Socket::Packet->new( IfIndex => 0, Type => SOCK_DGRAM, ) or die "Cannot socket - $!"; $sock->attach_filter( pack_sock_filter( BPF_RET|BPF_IMM, 0, 0, 20 ) ); while( my $addr = $sock->recv( my $buffer, 20 ) ) { printf "Packet: %v02x\n", $buffer; }
This module contains the constants and structure definitions to use Linux's socket packet filtering mechanism.
The following constants are exported:
SO_ATTACH_FILTER SO_DETACH_FILTER
BPF_LD BPF_LDX BPF_ST BPF_STX BPF_ALU BPF_JMP BPF_RET BPF_MISC BPF_W BPF_H BPF_B BPF_IMM BPF_ABS BPF_IND BPF_MEM PBF_LEN BPF_MSH BPF_ADD BPF_SUB BPF_MUL BPF_DIV BPF_OR BPF_AND BPF_LSH BPF_RSH BPF_NEG BPF_JA BPF_JEQ BPF_JGT BPF_JGE BPF_JSET BPF_K BPF_X BPF_A BPF_TAX BPF_TXA
This entire set of constants is also exported under the tag name :bpf.
:bpf
SKF_AD_OFF SKF_AD_PROTOCOL SKF_AD_PKTTYPE SKF_AD_IFINDEX SKF_NET_OFF SKF_LL_OFF
This entire set of constants is also exported under the tag name :skf.
:skf
Pack or unpack a single BPF instruction.
The following exported functions are also provided as methods on the IO::Socket class.
IO::Socket
Attaches the given filter program to the given socket. The program should be a string formed by concatenating multiple calls to pack_sock_filter() to build the filter program, or by using Linux::SocketFilter::Assembler.
pack_sock_filter()
Detaches the current filter from the socket, returning it to accepting all packets.
Paul Evans <leonerd@leonerd.org.uk>
To install Linux::SocketFilter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Linux::SocketFilter
CPAN shell
perl -MCPAN -e shell install Linux::SocketFilter
For more information on module installation, please visit the detailed CPAN module installation guide.