11-snapshot.t
来自「SinFP是一种新的识别对方计算机操作系统类型的工具」· T 代码 · 共 49 行
T
49 行
#!/usr/bin/perl -Tuse strict;use Test::More;use Net::Pcap;use lib 't';use Utils;my @sizes = (128, 512, 1024, 2048, 4096, 8192, int(10000*rand), int(10000*rand), int(10000*rand), int(10000*rand)); # snapshot sizesplan skip_all => "must be run as root" unless is_allowed_to_use_pcap();plan skip_all => "no network device available" unless find_network_device();plan tests => @sizes * 2 + 2;eval "use Test::Exception"; my $has_test_exception = !$@;my($dev,$pcap,$snapshot,$err) = ('','','','');# Testing error messagesSKIP: { skip "Test::Exception not available", 2 unless $has_test_exception; # snapshot() errors throws_ok(sub { Net::Pcap::snapshot() }, '/^Usage: Net::Pcap::snapshot\(p\)/', "calling snapshot() with no argument"); throws_ok(sub { Net::Pcap::snapshot(0) }, '/^p is not of type pcap_tPtr/', "calling snapshot() with incorrect argument type");}# Find a device$dev = find_network_device();for my $size (@sizes) { # Open the device $pcap = Net::Pcap::open_live($dev, $size, 1, 0, \$err); # Testing snapshot() $snapshot = 0; eval { $snapshot = Net::Pcap::snapshot($pcap) }; is( $@, '', "snapshot()" ); is( $snapshot, $size, " - snapshot has the expected size" ); Net::Pcap::close($pcap);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?