NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
00001 /***************************************************************************** 00002 * 00003 * Copyright (C) 2001 Uppsala University & Ericsson AB. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: Erik Nordstr�m, <erik.nordstrom@it.uu.se> 00020 * 00021 *****************************************************************************/ 00022 #ifndef NA_TIMER_QUEUE_H 00023 #define NA_TIMER_QUEUE_H 00024 00025 #ifndef NS_NO_GLOBALS 00026 00027 #ifndef _MSC_VER 00028 #include <sys/time.h> 00029 #endif 00030 00031 #include "NA_defs_aodv.h" 00032 #include "NA_list.h" 00033 00034 #ifdef NS_PORT 00035 typedef void (NA_AODVUU::*timeout_func_t) (void *); 00036 #else 00037 typedef void (*timeout_func_t) (void *); 00038 #endif 00039 00040 #ifdef AODV_USE_STL 00041 struct timer 00042 { 00043 int used; 00044 simtime_t timeout; 00045 timeout_func_t handler; 00046 void *data; 00047 }; 00048 #else 00049 struct timer 00050 { 00051 list_t l; 00052 int used; 00053 struct timeval timeout; 00054 timeout_func_t handler; 00055 void *data; 00056 }; 00057 #endif 00058 00059 static inline long timeval_diff(struct timeval *t1, struct timeval *t2) 00060 { 00061 long long res; /* We need this to avoid overflows while calculating... */ 00062 00063 if (!t1 || !t2) 00064 return -1; 00065 else 00066 { 00067 00068 res = t1->tv_sec; 00069 res = ((res - t2->tv_sec) * 1000000 + t1->tv_usec - t2->tv_usec) / 1000; 00070 return (long) res; 00071 } 00072 } 00073 00074 static inline int timeval_add_msec(struct timeval *t, unsigned long msec) 00075 { 00076 unsigned long long add; /* Protect against overflows */ 00077 00078 if (!t) 00079 return -1; 00080 00081 add = t->tv_usec + (msec * 1000); 00082 t->tv_sec += add / 1000000; 00083 t->tv_usec = add % 1000000; 00084 00085 return 0; 00086 } 00087 #endif /* NS_NO_GLOBALS */ 00088 00089 #ifndef NS_NO_DECLARATIONS 00090 void timer_queue_init(); 00091 int timer_remove(struct timer *t); 00092 void timer_set_timeout(struct timer *t, long msec); 00093 int timer_timeout_now(struct timer *t); 00094 #ifdef AODV_USE_STL 00095 simtime_t timer_age_queue(); 00096 #else 00097 struct timeval *timer_age_queue(); 00098 #endif 00099 00100 /* timer_init should be called for every newly allocated timer */ 00101 int timer_init(struct timer *t, timeout_func_t f, void *data); 00102 00103 #ifdef NS_PORT 00104 void timer_add(struct timer *t); 00105 #ifdef AODV_USE_STL 00106 void timer_timeout(const simtime_t &now); 00107 #else 00108 void timer_timeout(struct timeval *now); 00109 #endif 00110 00111 #ifdef DEBUG_TIMER_QUEUE 00112 void NS_CLASS printTQ(); 00113 #endif /* DEBUG_TIMER_QUEUE */ 00114 00115 #endif /* NS_PORT */ 00116 00117 #endif /* NS_NO_DECLARATIONS */ 00118 00119 #endif /* TIMER_QUEUE_H */