File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / hping2 / relid.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 22:11:37 2012 UTC (12 years, 4 months ago) by misho
Branches: hping2, MAIN
CVS tags: v2_0_0rc3p7, v2_0_0rc3p5, v2_0_0rc3p4, v2_0_0rc3p0, v2_0_0rc3, HEAD
hping2

    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: #include "hping2.h"
   15: #include "globals.h"
   16: 
   17: int relativize_id(int seqnum, int *ip_id)
   18: {
   19: 	int seq_diff, backup_id;
   20: 	static int last_seq = 0, last_id = -1;
   21: 
   22: 	backup_id = *ip_id;
   23: 
   24: 	if (last_id == -1) {
   25: 		last_id = *ip_id;
   26: 		last_seq = seqnum;
   27: 	}
   28: 	else
   29: 	{
   30: 		if ( (seq_diff=(seqnum-last_seq)) > 0)
   31: 		{
   32: 			if (last_id > *ip_id) /* rew */
   33: 				*ip_id = ((65535-last_id)
   34: 				    + *ip_id)/seq_diff;
   35: 				else
   36: 				*ip_id = (*ip_id-last_id)
   37: 					/seq_diff;
   38: 			last_id = backup_id;
   39: 			last_seq = seqnum;
   40: 			return TRUE;
   41: 		} else {
   42: 			out_of_sequence_pkt++;
   43: 		}
   44: 	}
   45: 	return FALSE;
   46: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>