Class: FFI::PCap::BPFProgram
- Inherits:
-
Struct
- Object
- Struct
- FFI::PCap::BPFProgram
- Includes:
- DRY::StructHelper
- Defined in:
- lib/ffi/pcap/bpf_program.rb
Overview
Structure for pcap_compile()
, pcap_setfilter()
, etc.
See bpf_program struct in pcap-bpf.h
Class Method Summary collapse
-
.compile(expr, opts = {}) ⇒ BPFProgram
Compiles a bpf filter without a pcap device being open.
Instance Method Summary collapse
Class Method Details
.compile(expr, opts = {}) ⇒ BPFProgram
Compiles a bpf filter without a pcap device being open. Downside is no error messages are available, whereas they are when you use open_dead() and use compile() on the resulting Dead.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ffi/pcap/bpf_program.rb', line 69 def self.compile(expr, opts={}) datalink = (opts[:datalink] || 1) dl = datalink.kind_of?(DataLink) ? datalink : DataLink.new(datalink) slen = (opts[:snaplen] || DEFAULT_SNAPLEN) optimize = (opts[:optimize] || 1) mask = (opts[:netmask] || 0) code = new() r = PCap.pcap_compile_nopcap(slen, dl.value, code, expr, optimize, mask) raise(LibError, "pcap_compile_nopcap(): unspecified error") if r < 0 return code end |
Instance Method Details
#free! ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ffi/pcap/bpf_program.rb', line 31 def free! unless @closed @freed = true PCap.pcap_freecode(self) end end |
#freed? ⇒ Boolean
38 39 40 |
# File 'lib/ffi/pcap/bpf_program.rb', line 38 def freed? @freed == true end |
#instructions ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ffi/pcap/bpf_program.rb', line 20 def instructions i = 0 sz = BPFInstruction.size Array.new(self.bf_len) do ins = BPFInstruction.new( self[:bf_insn] + i ) i += sz ins end end |