Annotation of embedaddon/hping2/rtt.c, revision 1.1.1.1
1.1 misho 1: /*
2: * $smu-mark$
3: * $name: rtt.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: #include <time.h>
12: #include <stdio.h>
13:
14: #include "hping2.h"
15: #include "globals.h"
16:
17: void minavgmax(float ms_delay)
18: {
19: static int avg_counter = 0;
20:
21: if (rtt_min == 0 || ms_delay < rtt_min)
22: rtt_min = ms_delay;
23: if (rtt_max == 0 || ms_delay > rtt_max)
24: rtt_max = ms_delay;
25: avg_counter++;
26: rtt_avg = (rtt_avg*(avg_counter-1)/avg_counter)+(ms_delay/avg_counter);
27: }
28:
29: int rtt(int *seqp, int recvport, float *ms_delay)
30: {
31: long sec_delay = 0, usec_delay = 0;
32: int i, tablepos = -1, status;
33:
34: if (*seqp != 0) {
35: for (i = 0; i < TABLESIZE; i++)
36: if (delaytable[i].seq == *seqp) {
37: tablepos = i;
38: break;
39: }
40: } else {
41: for (i=0; i<TABLESIZE; i++)
42: if (delaytable[i].src == recvport) {
43: tablepos = i;
44: break;
45: }
46: if (i != TABLESIZE)
47: *seqp = delaytable[i].seq;
48: }
49:
50: if (tablepos != -1)
51: {
52: status = delaytable[tablepos].status;
53: delaytable[tablepos].status = S_RECV;
54:
55: sec_delay = time(NULL) - delaytable[tablepos].sec;
56: usec_delay = get_usec() - delaytable[tablepos].usec;
57: if (sec_delay == 0 && usec_delay < 0)
58: usec_delay += 1000000;
59:
60: *ms_delay = (sec_delay * 1000) + ((float)usec_delay / 1000);
61: minavgmax(*ms_delay);
62: }
63: else
64: {
65: *ms_delay = 0; /* not in table.. */
66: status = 0; /* we don't know if it's DUP */
67: }
68:
69: /* SANITY CHECK */
70: if (*ms_delay < 0)
71: {
72: printf("\n\nSANITY CHECK in rtt.c FAILED!\n");
73: printf("- seqnum = %d\n", *seqp);
74: printf("- status = %d\n", status);
75: printf("- get_usec() = %ld\n", (long int) get_usec());
76: printf("- delaytable.usec = %ld\n",
77: (long int) delaytable[tablepos].usec);
78: printf("- usec_delay = %ld\n", usec_delay);
79: printf("- time(NULL) = %ld\n", (long int) time(NULL));
80: printf("- delaytable.sec = %ld\n",
81: (long int) delaytable[tablepos].sec);
82: printf("- sec_delay = %ld\n", sec_delay);
83: printf("- ms_delay = %f\n", *ms_delay);
84: printf("END SANITY CHECK REPORT\n\n");
85: }
86:
87: return status;
88: }
89:
90: void delaytable_add(int seq, int src, time_t sec, time_t usec, int status)
91: {
92: delaytable[delaytable_index % TABLESIZE].seq = seq;
93: delaytable[delaytable_index % TABLESIZE].src = src;
94: delaytable[delaytable_index % TABLESIZE].sec = sec;
95: delaytable[delaytable_index % TABLESIZE].usec = usec;
96: delaytable[delaytable_index % TABLESIZE].status = status;
97: delaytable_index++;
98: }
99:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>