diff options
author | Tails developers <amnesia@boum.org> | 2014-12-19 00:40:08 +0100 |
---|---|---|
committer | Holger Levsen <holger@layer-acht.org> | 2014-12-21 09:45:40 +0100 |
commit | 51680b6ebb645d37ebdfcd122ca163b3a638aefa (patch) | |
tree | 337e128d2eac3cbc89ecbacf38851bfa33469cd5 /features/support/helpers/net_helper.rb | |
parent | 44bab3c86ca3d95837f4c50cc535206352385a46 (diff) | |
download | jenkins.debian.net-51680b6ebb645d37ebdfcd122ca163b3a638aefa.tar.xz |
files copied from https://git-tails.immerda.ch/tails - many thanks to the tails developers for their nice work and documentation of it - these files have been released under the GNU General Public License version 3 or (at your option) any later version
features/images has been omitted
Diffstat (limited to 'features/support/helpers/net_helper.rb')
-rw-r--r-- | features/support/helpers/net_helper.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/features/support/helpers/net_helper.rb b/features/support/helpers/net_helper.rb new file mode 100644 index 00000000..29119195 --- /dev/null +++ b/features/support/helpers/net_helper.rb @@ -0,0 +1,42 @@ +# +# Sniffer is a very dumb wrapper to start and stop tcpdumps instances, possibly +# with customized filters. Captured traffic is stored in files whose name +# depends on the sniffer name. The resulting captured packets for each sniffers +# can be accessed as an array through its `packets` method. +# +# Use of more rubyish internal ways to sniff a network like with pcap-able gems +# is waaay to much resource consumming, notmuch reliable and soooo slow. Let's +# not bother too much with that. :) +# +# Should put all that in a Module. + +class Sniffer + + attr_reader :name, :pcap_file, :pid + + def initialize(name, bridge_name) + @name = name + @bridge_name = bridge_name + @bridge_mac = File.open("/sys/class/net/#{@bridge_name}/address", "rb").read.chomp + @pcap_file = "#{$tmp_dir}/#{name}.pcap" + end + + def capture(filter="not ether src host #{@bridge_mac} and not ether proto \\arp and not ether proto \\rarp") + job = IO.popen("/usr/sbin/tcpdump -n -i #{@bridge_name} -w #{@pcap_file} -U '#{filter}' >/dev/null 2>&1") + @pid = job.pid + end + + def stop + begin + Process.kill("TERM", @pid) + rescue + # noop + end + end + + def clear + if File.exist?(@pcap_file) + File.delete(@pcap_file) + end + end +end |