~ubuntu-branches/ubuntu/trusty/libnetpacket-perl/trusty-proposed

« back to all changes in this revision

Viewing changes to t/checksum.t

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2009-11-21 15:18:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091121151828-2jq4kk0shmm0ti3e
Tags: 0.41.1-1
New Upstream Version (Closes: #557161)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use warnings;
 
3
 
 
4
use Test::More tests => 3;
 
5
 
 
6
use NetPacket::TCP;
 
7
use NetPacket::UDP;
 
8
 
 
9
my $ip = { 
 
10
        src_ip => '127.0.0.1',
 
11
        dest_ip => '192.168.0.1',
 
12
};
 
13
 
 
14
bless $ip, 'NetPacket::IP';
 
15
 
 
16
my $tcp = {
 
17
        dest_port => 22,
 
18
        src_port => 13,
 
19
        seqnum => 1,
 
20
        acknum => 2,
 
21
        winsize => 32,
 
22
        urg => 0,
 
23
        hlen => 5,
 
24
        data => "DEADBEEF",
 
25
};
 
26
 
 
27
bless $tcp, 'NetPacket::TCP';
 
28
 
 
29
is NetPacket::TCP::checksum( $tcp, $ip ) => 25303;
 
30
 
 
31
$tcp->{data} = "DEADBEEF\x01";
 
32
my $odd_checksum = NetPacket::TCP::checksum( $tcp, $ip );
 
33
 
 
34
is $odd_checksum => 25046, 'TCP padding done correctly';
 
35
 
 
36
my $udp = {
 
37
        src_port => 13,
 
38
        dest_port => 14,
 
39
        len => 15,
 
40
        data => "foo",
 
41
};
 
42
 
 
43
bless $udp, 'NetPacket::UDP';
 
44
 
 
45
is NetPacket::UDP::checksum( $udp, $ip ) => 49177, 'UDP padding';