|
Lines 1-160
Link Here
|
| 1 |
Remove attempts to set arbitrary limits on stack-sizes for different |
|
|
| 2 |
threads, which cause segfaults (due, presumably, to the limits being |
| 3 |
too low). |
| 4 |
|
| 5 |
-mi |
| 6 |
|
| 7 |
--- src/defs.h 2010-09-27 19:02:01.000000000 -0400 |
| 8 |
+++ src/defs.h 2015-03-23 16:39:53.000000000 -0400 |
| 9 |
@@ -30,8 +30,2 @@ |
| 10 |
//#define FASTMODE_INTERVAL 250000000 // one quarter of a second |
| 11 |
#define FASTMODE_INTERVAL 100000000 // one tenth of a second |
| 12 |
- |
| 13 |
-// stack sizes for the different threads |
| 14 |
-#define SS_PB 2048 // PacketBuffer |
| 15 |
-#define SS_S 4096 // Sniffer 2048 -> segfault on freebsd |
| 16 |
-#define SS_TCC 4096 // TCContainer |
| 17 |
-#define SS_TUI 5120 // TextUI. 4096 -> segfault on solaris |
| 18 |
--- src/PacketBuffer.cc 2010-09-27 19:02:01.000000000 -0400 |
| 19 |
+++ src/PacketBuffer.cc 2015-03-23 16:23:36.000000000 -0400 |
| 20 |
@@ -53,14 +53,6 @@ |
| 21 |
// Start up maintenence thread |
| 22 |
// |
| 23 |
- pthread_attr_t attr; |
| 24 |
- if( pthread_attr_init( &attr ) != 0 ) |
| 25 |
- throw GenericError("pthread_attr_init() failed"); |
| 26 |
- |
| 27 |
- // TODO: there is no man page for this call on linux. Not sure what it |
| 28 |
- // may return. On some systems it may not be supported at all |
| 29 |
- // (should return ENOSYS). Should be safe to ignore return val. |
| 30 |
- pthread_attr_setstacksize( &attr, SS_PB ); |
| 31 |
|
| 32 |
- if( pthread_create(&maint_thread_tid,&attr,pbmaint_thread_func,this) != 0 ) |
| 33 |
+ if (pthread_create(&maint_thread_tid, NULL, pbmaint_thread_func, this) != 0) |
| 34 |
throw GenericError("pthread_create() returned an error"); |
| 35 |
|
| 36 |
--- src/Sniffer.cc 2010-09-27 19:02:22.000000000 -0400 |
| 37 |
+++ src/Sniffer.cc 2015-03-23 16:25:10.000000000 -0400 |
| 38 |
@@ -55,5 +66,5 @@ |
| 39 |
} |
| 40 |
|
| 41 |
-void Sniffer::init(char *iface, char *fexp, char *test_file) |
| 42 |
+void Sniffer::init(const char *iface, const char *fexp, const char *test_file) |
| 43 |
{ |
| 44 |
assert(pcap_initted==false); |
| 45 |
@@ -89,6 +102,4 @@ |
| 46 |
// prepare the filter |
| 47 |
// |
| 48 |
- struct bpf_program filter; // the filter for the sniffer |
| 49 |
- char *filter_app = fexp; // The filter expression |
| 50 |
bpf_u_int32 mask; // The netmask of our sniffing device |
| 51 |
bpf_u_int32 net; // The IP of our sniffing device |
| 52 |
@@ -102,28 +113,23 @@ |
| 53 |
mask = 0; |
| 54 |
} |
| 55 |
- if( pcap_compile(handle, &filter, filter_app, 0, net) == -1 ) |
| 56 |
- { |
| 57 |
- pcap_close(handle); |
| 58 |
- throw PcapError("pcap_compile",pcap_geterr(handle)); |
| 59 |
- } |
| 60 |
- if( pcap_setfilter(handle, &filter) ) // apply filter to sniffer |
| 61 |
- { |
| 62 |
- pcap_freecode(&filter); |
| 63 |
- pcap_close(handle); |
| 64 |
- throw PcapError("pcap_setfilter",pcap_geterr(handle)); |
| 65 |
+ if (fexp != NULL && fexp[0] != '\0') { |
| 66 |
+ struct bpf_program filter; // the filter for the sniffer |
| 67 |
+ if (pcap_compile(handle, &filter, fexp, 0, net) == -1) |
| 68 |
+ { |
| 69 |
+ pcap_close(handle); |
| 70 |
+ throw PcapError("pcap_compile", pcap_geterr(handle)); |
| 71 |
+ } |
| 72 |
+ if (pcap_setfilter(handle, &filter)) // apply filter to sniffer |
| 73 |
+ { |
| 74 |
+ pcap_freecode(&filter); |
| 75 |
+ pcap_close(handle); |
| 76 |
+ throw PcapError("pcap_setfilter", pcap_geterr(handle)); |
| 77 |
+ } |
| 78 |
+ pcap_freecode(&filter); // filter code not needed after setfilter |
| 79 |
} |
| 80 |
- pcap_freecode(&filter); // filter code not needed after setfilter |
| 81 |
- |
| 82 |
- pcap_initted=true; |
| 83 |
- |
| 84 |
|
| 85 |
- pthread_attr_t attr; |
| 86 |
- |
| 87 |
- if( pthread_attr_init( &attr ) != 0 ) |
| 88 |
- throw GenericError("pthread_attr_init() failed"); |
| 89 |
- |
| 90 |
- pthread_attr_setstacksize( &attr, SS_S ); |
| 91 |
+ pcap_initted=true; |
| 92 |
|
| 93 |
- if( pthread_create(&sniffer_tid,&attr,sniffer_thread_func,this) != 0 ) |
| 94 |
+ if (pthread_create(&sniffer_tid, NULL, sniffer_thread_func, this) != 0) |
| 95 |
throw GenericError("pthread_create() failed."); |
| 96 |
|
| 97 |
@@ -163,9 +170,11 @@ |
| 98 |
void Sniffer::processPacket( const pcap_pkthdr *header, const u_char *packet ) |
| 99 |
{ |
| 100 |
- assert( pthread_mutex_lock(&pb_mutex)==0 ); |
| 101 |
+ |
| 102 |
+ if (pthread_mutex_lock(&pb_mutex) != 0) |
| 103 |
+ return; |
| 104 |
|
| 105 |
if( pb==NULL ) |
| 106 |
{ |
| 107 |
- assert( pthread_mutex_unlock(&pb_mutex) == 0 ); |
| 108 |
+ pthread_mutex_unlock(&pb_mutex); |
| 109 |
return; |
| 110 |
} |
| 111 |
@@ -193,5 +202,5 @@ |
| 112 |
pb->pushPacket(n); |
| 113 |
|
| 114 |
- assert( pthread_mutex_unlock(&pb_mutex) == 0 ); |
| 115 |
+ pthread_mutex_unlock(&pb_mutex); |
| 116 |
} |
| 117 |
|
| 118 |
--- src/Sniffer.h 2010-09-27 19:02:22.000000000 -0400 |
| 119 |
+++ src/Sniffer.h 2015-03-23 15:07:57.000000000 -0400 |
| 120 |
@@ -43,5 +43,5 @@ |
| 121 |
// init performs some constructor-like activity. It is separate |
| 122 |
// so that exceptions don't have to be thrown in the constructor. |
| 123 |
- void init(char *iface, char *fexp, char *test_file); |
| 124 |
+ void init(const char *iface, const char *fexp, const char *test_file); |
| 125 |
|
| 126 |
// set the place where sniffed packets are sent for further |
| 127 |
--- src/TCContainer.cc 2010-09-27 19:02:01.000000000 -0400 |
| 128 |
+++ src/TCContainer.cc 2015-03-23 16:23:05.000000000 -0400 |
| 129 |
@@ -47,15 +47,8 @@ |
| 130 |
state=TSTATE_IDLE; |
| 131 |
|
| 132 |
- pthread_attr_t attr; |
| 133 |
- |
| 134 |
pthread_mutex_init( &conlist_lock, NULL ); |
| 135 |
pthread_mutex_init( &state_mutex, NULL ); |
| 136 |
|
| 137 |
- if( pthread_attr_init( &attr ) != 0 ) |
| 138 |
- throw GenericError("pthread_attr_init() failed"); |
| 139 |
- |
| 140 |
- pthread_attr_setstacksize( &attr, SS_TCC ); |
| 141 |
- |
| 142 |
- if( pthread_create(&maint_thread_tid,&attr,maint_thread_func,this) != 0 ) |
| 143 |
+ if( pthread_create(&maint_thread_tid, NULL, maint_thread_func, this) != 0 ) |
| 144 |
throw GenericError("pthread_create() failed."); |
| 145 |
|
| 146 |
--- src/TextUI.cc 2011-08-03 13:34:45.000000000 -0400 |
| 147 |
+++ src/TextUI.cc 2015-03-23 16:24:20.000000000 -0400 |
| 148 |
@@ -80,11 +80,5 @@ |
| 149 |
run_displayer = true; |
| 150 |
|
| 151 |
- pthread_attr_t attr; |
| 152 |
- if( pthread_attr_init( &attr ) != 0 ) |
| 153 |
- throw GenericError("pthread_attr_init() failed"); |
| 154 |
- |
| 155 |
- pthread_attr_setstacksize( &attr, SS_TUI ); |
| 156 |
- |
| 157 |
- if( pthread_create(&displayer_tid,&attr,displayer_thread_func,this) != 0 ) |
| 158 |
+ if (pthread_create(&displayer_tid, NULL, displayer_thread_func, this) != 0) |
| 159 |
throw GenericError("pthread_create() returned an error."); |
| 160 |
|