File: relid.c

package info (click to toggle)
hping2 2.rc3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 756 kB
  • ctags: 951
  • sloc: ansic: 6,706; makefile: 110; sh: 83
file content (46 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* 
 * $smu-mark$ 
 * $name: relid.c$ 
 * $author: Salvatore Sanfilippo <antirez@invece.org>$ 
 * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ 
 * $license: This software is under GPL version 2 of license$ 
 * $date: Fri Nov  5 11:55:49 MET 1999$ 
 * $rev: 3$ 
 */ 

/* FIXME: maybe it's better to avoid division per seq_diff and
   at least add an option to switch on/off this feature */

#include "hping2.h"
#include "globals.h"

int relativize_id(int seqnum, int *ip_id)
{
	int seq_diff, backup_id;
	static int last_seq = 0, last_id = -1;

	backup_id = *ip_id;

	if (last_id == -1) {
		last_id = *ip_id;
		last_seq = seqnum;
	}
	else
	{
		if ( (seq_diff=(seqnum-last_seq)) > 0)
		{
			if (last_id > *ip_id) /* rew */
				*ip_id = ((65535-last_id)
				    + *ip_id)/seq_diff;
				else
				*ip_id = (*ip_id-last_id)
					/seq_diff;
			last_id = backup_id;
			last_seq = seqnum;
			return TRUE;
		} else {
			out_of_sequence_pkt++;
		}
	}
	return FALSE;
}