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

📄 16-setnonblock.t

📁 SinFP是一种新的识别对方计算机操作系统类型的工具
💻 T
字号:
#!/usr/bin/perl -Tuse strict;use File::Spec;use Test::More;use Net::Pcap;use lib 't';use Utils;plan skip_all => "pcap_setnonblock() and pcap_getnonblock() are not available"  unless is_available('pcap_setnonblock');plan tests => 23;eval "use Test::Exception"; my $has_test_exception = !$@;my($dev,$pcap,$r,$err) = ('','','','');# Testing error messagesSKIP: {    skip "Test::Exception not available", 4 unless $has_test_exception;    # setnonblock() errors    throws_ok(sub {        Net::Pcap::setnonblock()    }, '/^Usage: Net::Pcap::setnonblock\(p\, nb, err\)/',        "calling setnonblock() with no argument");    throws_ok(sub {        Net::Pcap::setnonblock(0, 0, 0)    }, '/^p is not of type pcap_tPtr/',        "calling setnonblock() with incorrect argument type");    # getnonblock() errors    throws_ok(sub {        Net::Pcap::getnonblock()    }, '/^Usage: Net::Pcap::getnonblock\(p\, err\)/',        "calling getnonblock() with no argument");    throws_ok(sub {        Net::Pcap::getnonblock(0, 0)    }, '/^p is not of type pcap_tPtr/',        "calling getnonblock() with incorrect argument type");}SKIP: {    skip "must be run as root", 13 unless is_allowed_to_use_pcap();    skip "no network device available", 13 unless find_network_device();    # Find a device and open it    $dev = find_network_device();    $pcap = Net::Pcap::open_live($dev, 1024, 1, 0, \$err);    isa_ok( $pcap, 'pcap_tPtr', "\$pcap" );    for my $state (0, 1) {        # Testing setnonblock()        eval { $r = Net::Pcap::setnonblock($pcap, $state, \$err) };        is( $@,   '', "setnonblock() state=$state" );        is( $err, '', " - err must be null" );        is( $r,    0, " - should return zero" );        # Testing getnonblock()        eval { $r = Net::Pcap::getnonblock($pcap, \$err) };        is( $@,     '', "getnonblock()" );        is( $err,   '', " - err must be null" );        is( $r, $state, " - state must be $state" );    }    Net::Pcap::close($pcap);}# Open a sample dump$pcap = Net::Pcap::open_offline(File::Spec->catfile(qw(t samples ping-ietf-20pk-be.dmp)), \$err);isa_ok( $pcap, 'pcap_tPtr', "\$pcap" );# Testing error messagesSKIP: {    skip "Test::Exception not available", 2 unless $has_test_exception;    throws_ok(sub {        Net::Pcap::setnonblock($pcap, 0, 0)    }, '/^arg3 not a reference/',        "calling setnonblock() with incorrect argument type for arg3");    throws_ok(sub {        Net::Pcap::getnonblock($pcap, 0)    }, '/^arg2 not a reference/',        "calling getnonblock() with incorrect argument type for arg2");}# Testing getnonblock()eval { $r = Net::Pcap::getnonblock($pcap, \$err) };is( $@,   '', "getnonblock()" );is( $err, '', " - err must be null" );is( $r,    0, " - state must be 0 for savefile" );Net::Pcap::close($pcap);

⌨️ 快捷键说明

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