⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 03-openlive.t

📁 SinFP是一种新的识别对方计算机操作系统类型的工具
💻 T
字号:
#!/usr/bin/perl -Tuse strict;use Test::More;use Net::Pcap;use lib 't';use Utils;plan 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 => 14;eval "use Test::Exception"; my $has_test_exception = !$@;my($dev,$pcap,$err) = ('','','');# Testing error messagesSKIP: {    skip "Test::Exception not available", 4 unless $has_test_exception;    # open_live() errors    throws_ok(sub {        Net::Pcap::open_live()    }, '/^Usage: Net::Pcap::open_live\(device, snaplen, promisc, to_ms, err\)/',        "calling open_live() with no argument");    throws_ok(sub {        Net::Pcap::open_live(0, 0, 0, 0, 0)    }, '/^arg5 not a reference/',        "calling open_live() with no reference for arg5");    # close() errors    throws_ok(sub {        Net::Pcap::close()    }, '/^Usage: Net::Pcap::close\(p\)/',        "calling close() with no argument");    throws_ok(sub {        Net::Pcap::close(0)    }, '/^p is not of type pcap_tPtr/',        "calling close() with incorrect argument type");}# Find a device$dev = find_network_device();# Testing open_live()eval { $pcap = Net::Pcap::open_live($dev, 1024, 1, 0, \$err) };is(   $@,   '', "open_live()" );is(   $err, '', " - \$err must be null: $err" ); $err = '';ok( defined $pcap, " - \$pcap is defined" );isa_ok( $pcap, 'SCALAR', " - \$pcap" );isa_ok( $pcap, 'pcap_tPtr', " - \$pcap" );# Testing close()eval { Net::Pcap::close($pcap) };is(   $@,   '', "close()" );is(   $err, '', " - \$err must be null: $err" ); $err = '';# Testing open_live() with fake device namemy $fakedev = 'this is not a device';eval { $pcap = Net::Pcap::open_live($fakedev, 1024, 1, 0, \$err) };is(   $@,   '', "open_live()" );if($^O eq 'MSWin32' or $^O eq 'cygwin') {    like( $err, '/^Error opening adapter:/', " - \$err must be set: $err" );} elsif($^O eq 'darwin' or $^O eq 'freebsd' or $^O eq 'openbsd') {    like( $err, "/^(?:BIOCSETIF: )?$fakedev: Device not configured/", " - \$err must be set: $err" );} else {    like( $err, '/^ioctl: (?:No such device)/', " - \$err must be set: $err" );}is( $pcap, undef, " - \$pcap isn't defined" );$err = '';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -