[Coral-dev] Sequence number arithmetic in perl

Markus Peuhkuri puhuri@netlab.hut.fi
Wed, 20 Nov 2002 20:03:59 +0200 (EET)


David Moore writes:
 > Why are you using `use integer'?  performance?

Performance is not an issue as this is just proof-of-concept trial.
I'm not sure about this, but based on perl docs perl uses signed ints,
and if the number is larger than 2**31-1, it gets "promoted" to float.

Actually, if I have code like:
my $tcp_up = new Unpacker("tcp", [ "th_sport", "th_dport", "th_seq",
		    "th_ack", "th_off", "th_flags" ]);
...
  my($th_sport, $th_dport, $th_seq, $th_ack, $th_off, $th_flags) 
      = $tcp_up->unpack($ip_record, $ip_hl * 4);

then $th_seq, $th_ack are *negative* values (if they are larger than
2**31-1).

What i'm looking for is perl-routines for 
int before(u32 seq1, u32 seq2);
int after(u32 seq1, u32 seq2);
/* is s2<=s1<=s3 ? */
int between(u32 seq1, u32 seq2, u32 seq3)
int difference(u32 seq1, u32 seq2);

-- 
Markus Peuhkuri        ! internet: Markus.Peuhkuri@hut.fi
HUT/Networking Lab.    ! http://www.iki.fi/puhuri/
P.O.Box 3000, 02015 HUT! tel: +358-9-451 2467 fax: +358-9-451 2474
Finland, EUROPE        ! gsm: +358-40-50 19683