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

« back to all changes in this revision

Viewing changes to t/udp-checksum.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
 
 
2
use Test::More;
 
3
 
 
4
my $data = <<'END_DATA';
 
5
01005e2a2501003048770072080045000110000040000111cccc53a6443fef2a25017
 
6
d5a7d5a00fc7d37050000f40000010ff30f804100160000000022482ac57077827dd9
 
7
0000010ff30f804100076b65737472616c00067379736d6f6e000a4469736b4672656
 
8
52e2f6d000773000c70657263656e742d757365646640fef86073000b7061636b6574
 
9
2d74797065690000000073000b6465736372697074696f6e7300154469736b2053706
 
10
16365207374617469737469637373000d7570646174652d706572696f647100000000
 
11
000493e073000a62797465732d66726565710000002248a1800073000e726573756c7
 
12
42d6d6573736167657300077375636365737373000e6d65676162797465732d667265
 
13
6571000000000002248a
 
14
END_DATA
 
15
 
 
16
$data =~ s/\s+//g;    # remove all spaces
 
17
 
 
18
my $datagram = join "", map { chr hex } $data =~ /(..)/g;
 
19
 
 
20
use NetPacket::Ethernet;
 
21
use NetPacket::IP;
 
22
use NetPacket::UDP;
 
23
 
 
24
my $pkt = NetPacket::Ethernet->decode($datagram);
 
25
 
 
26
my $ip_pkt = NetPacket::IP->decode( $pkt->{data} );
 
27
$pkt = NetPacket::UDP->decode( $ip_pkt->{data} );
 
28
 
 
29
is $pkt->{cksum} => 32055, 'original checksum';
 
30
 
 
31
$pkt->checksum($ip_pkt);
 
32
 
 
33
is $pkt->{cksum} => 32055, 're-computed checksum';
 
34
 
 
35
done_testing;
 
36