15-is_swapped.t

来自「SinFP是一种新的识别对方计算机操作系统类型的工具」· T 代码 · 共 33 行

T
33
字号
#!/usr/bin/perl -Tuse strict;use File::Spec;use Test::More;use Net::Pcap;plan tests => 5;my($pcap,$err) = ('','');# from perlport/"Numbers endianness and Width"my $is_big_endian    = unpack("h*", pack("s", 1)) =~ /01/;my $is_little_endian = unpack("h*", pack("s", 1)) =~ /^1/;is( $is_big_endian, !$is_little_endian, "checking flags consistency" );diag("This platform has been detected as a ".($is_big_endian?"big":"little")." endian architecture");# make these values numbers because is_swapped() return 0 or 1, not true or false$is_big_endian += 0;  $is_little_endian += 0;# testing with a big endian dump$pcap = Net::Pcap::open_offline(File::Spec->catfile(qw(t samples ping-ietf-20pk-be.dmp)), \$err);isa_ok( $pcap, 'pcap_tPtr', "\$pcap" );is( Net::Pcap::is_swapped($pcap) , $is_little_endian, "testing with a big endian dump" );Net::Pcap::close($pcap);# testing with a little endian dump$pcap = Net::Pcap::open_offline(File::Spec->catfile(qw(t samples ping-ietf-20pk-le.dmp)), \$err);isa_ok( $pcap, 'pcap_tPtr', "\$pcap" );is( Net::Pcap::is_swapped($pcap) , $is_big_endian, "testing with a little endian dump" );Net::Pcap::close($pcap);

⌨️ 快捷键说明

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