~ubuntu-branches/ubuntu/oneiric/libnetpacket-perl/oneiric

« back to all changes in this revision

Viewing changes to t/icmp.t

  • Committer: Bazaar Package Importer
  • Author(s): Ansgar Burchardt
  • Date: 2010-05-24 13:33:47 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100524133347-ena8blyqn9ulrj9s
Tags: 0.43.0-1
* New upstream release.
* Refresh patch.
* debian/copyright: Add information for new files.
* debian/rules: Use Build.PL explicitly.
* debian/control: Suggests: libnet-pcap-perl for capturing packets.
* Add myself to Uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use warnings;
 
3
 
 
4
use Test::More tests => 2;                      # last test to print
 
5
 
 
6
use NetPacket::Ethernet;
 
7
use NetPacket::IP;
 
8
use NetPacket::ICMP;
 
9
 
 
10
my $datagram = binarize( <<'END_DATAGRAM' );
 
11
00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 
 
12
00 54 00 00 40 00 40 01 3c a7 7f 00 00 01 7f 00 
 
13
00 01 08 00 d8 2f b6 6f 00 00 f8 11 c9 45 ba 05 
 
14
03 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 
 
15
16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 
 
16
26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 
 
17
36 37
 
18
END_DATAGRAM
 
19
 
 
20
my $eth = NetPacket::Ethernet->decode( $datagram );
 
21
my $ip = NetPacket::IP->decode( $eth->{data} );
 
22
my $icmp = NetPacket::ICMP->decode( $ip->{data} );
 
23
 
 
24
is $icmp->{cksum} => 55343, 'ICMP checksum';
 
25
 
 
26
# recompute the checksum
 
27
$icmp->checksum;
 
28
 
 
29
is $icmp->{cksum} => 55343, 'recomputed ICMP checksum';
 
30
 
 
31
sub binarize {
 
32
    my $string = shift;
 
33
 
 
34
    return join '' => map { chr hex } split ' ', $string;
 
35
}
 
36