1 /*
2  * $smu-mark$
3  * $name: relid.c$
4  * $author: Salvatore Sanfilippo <antirez@invece.org>$
5  * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
6  * $license: This software is under GPL version 2 of license$
7  * $date: Fri Nov  5 11:55:49 MET 1999$
8  * $rev: 3$
9  */
10 
11 /* FIXME: maybe it's better to avoid division per seq_diff and
12    at least add an option to switch on/off this feature */
13 
14 /* $Id: relid.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
15 
16 #include "hping2.h"
17 #include "globals.h"
18 
relativize_id(int seqnum,int * ip_id)19 int relativize_id(int seqnum, int *ip_id)
20 {
21 	int seq_diff, backup_id;
22 	static int last_seq = 0, last_id = -1;
23 
24 	backup_id = *ip_id;
25 
26 	if (last_id == -1) {
27 		last_id = *ip_id;
28 		last_seq = seqnum;
29 	}
30 	else
31 	{
32 		if ( (seq_diff=(seqnum-last_seq)) > 0)
33 		{
34 			if (last_id > *ip_id) /* rew */
35 				*ip_id = ((65535-last_id)
36 				    + *ip_id)/seq_diff;
37 				else
38 				*ip_id = (*ip_id-last_id)
39 					/seq_diff;
40 			last_id = backup_id;
41 			last_seq = seqnum;
42 			return TRUE;
43 		} else {
44 			out_of_sequence_pkt++;
45 		}
46 	}
47 	return FALSE;
48 }
49