<commit_before>= Usage of Pcaprub

Pcaprub is a ruby wrapper to the libpcap libary. It provides a common method to access the c bindings defined in libpcap. 
 
== Basics of Pcaprub  

  require "rubygems"
  require "pcaprub"

  mypcap = Pcap.new  


== Setting up a live Capture

  dev = ::Pcap.lookupdev

  snaplength = 65535
  promiscous_mode = true 
  timeout = 0 
  
  system("ifconfig", dev, "up")
  
  capture = ::Pcap.open_live(dev, snaplength, promiscous_mode, timeout)  
  
== Open an existing pcap file
  
  pcapfile = File.dirname(__FILE__) + "/foo.pcap"
  
  if(not File.exists?(pcapfile))
    raise RuntimeError, "The PCAP file #{pcapfile} could not be found"
  end
  
  capture = ::Pcap.open_offline(pcapfile)
  
== Setting a BPF Filter
  
  bpf = "ip and not net 10.0.0.0/8"
  
  capture.setfilter(bpf)

== Reading Capture Statistics

Packets Received 
  capture.stats['recv']

Packets Dropped  
	capture.stats['drop']

Packets Dropped by Interface
	capture.stats['ifdrop']

== Running the Capture

Sniffing a set number of packets and also letting the user Interrupt Early

  capture_packets = 100
  
  begin
    capture.each do |packet|
      p packet 
      # Handling the number of packets to process
      capture_packets -= 1
      if capture_packets == 0
        break
      end
    end
    
  # ^C to stop sniffing
  rescue Interrupt
    puts "\nPacket Capture stopped by interrupt signal."
    
  rescue Exception => e
    puts "\nERROR: #{e}"
    retry
  end
	
== Examming the DataLink
<commit_msg>type fix<commit_after>= Usage of Pcaprub

Pcaprub is a ruby wrapper to the libpcap libary. It provides a common method to access the c bindings defined in libpcap. 

Many of the methods require the Pcap instance to be "ready". 

 - "Ready" is defined as being initiated with open_live open_dead or open_offline.
 
== Basics of Pcaprub  

  require "rubygems"
  require "pcaprub"

  mypcap = Pcap.new  


== Setting up a live Capture

  dev = ::Pcap.lookupdev

  snaplength = 65535
  promiscous_mode = true 
  timeout = 0 
  
  system("ifconfig", dev, "up")
  
  capture = ::Pcap.open_live(dev, snaplength, promiscous_mode, timeout)  
  
== Open an existing pcap file
  
  pcapfile = File.dirname(__FILE__) + "/foo.pcap"
  
  if(not File.exists?(pcapfile))
    raise RuntimeError, "The PCAP file #{pcapfile} could not be found"
  end
  
  capture = ::Pcap.open_offline(pcapfile)
  
== Setting a BPF Filter
  
  bpf = "ip and not net 10.0.0.0/8"
  
  capture.setfilter(bpf)

== Reading Capture Statistics

Packets Received 
  capture.stats['recv']

Packets Dropped  
	capture.stats['drop']

Packets Dropped by Interface
	capture.stats['ifdrop']

== Running the Capture

Sniffing a set number of packets and also letting the user Interrupt Early

  capture_packets = 100
  
  begin
    capture.each do |packet|
      p packet 
      # Handling the number of packets to process
      capture_packets -= 1
      if capture_packets == 0
        break
      end
    end
    
  # ^C to stop sniffing
  rescue Interrupt
    puts "\nPacket Capture stopped by interrupt signal."
    
  rescue Exception => e
    puts "\nERROR: #{e}"
    retry
  end
	
== Examining the DataLink

{'fraction_non_alphanumeric': 0.08121668234556287, 'fraction_numerical': 0.01066164941988084, 'mean_word_length': 2.909313725490196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2161049', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1057, 'n_words': 357}