| 257 | | packet = (u_char *) pcap_next(pcap_global_descriptor, &useless); |
| 258 | | DEBUG_MSG("received a packet\n") |
| 259 | | if (NULL == packet) { |
| 260 | | /* if pcap_next returns, there is an error on the link, so we close it and try to reopen it */ |
| 261 | | DEBUG_MSG("pcap_next returned a null pointer [errormessage : %s]\n", pcap_geterr(pcap_global_descriptor)); |
| 262 | | if (Options.ReadFromFile != NULL) { |
| | 261 | pcap_result = pcap_next_ex(pcap_global_descriptor, &header, (const u_char **) &packet); |
| | 262 | DEBUG_MSG("pcap_next_ex returned %i\n", pcap_result); |
| | 263 | switch (pcap_result) { |
| | 264 | case 1: |
| | 265 | /* A packet was received, nothing to do! */ |
| | 266 | DEBUG_MSG("packet time/length/size %i %i %i\n", header->ts, header->caplen, header->len); |
| | 267 | break; |
| | 268 | case 0: |
| | 269 | /* pcap_next_ex reached a time out, check if there is someting to dump and if not, continue */ |
| | 270 | /* FIXME: ungly code duplication here! */ |
| | 271 | /* handle HUP signal */ |
| | 272 | if (SigHup) { |
| | 273 | struct AllLogsType *pTempLog; |
| | 274 | for (pTempLog = pAllLogs; pTempLog; pTempLog = pTempLog->Next) { |
| | 275 | data_dump(pTempLog); |
| | 276 | data_clear(pTempLog); |
| | 277 | } |
| | 278 | |
| | 279 | Clean(); |
| | 280 | ReInit(); |
| | 281 | SigHup = 0; |
| | 282 | } |
| | 283 | |
| | 284 | /* handle USR1 signal */ |
| | 285 | if (SigDump) { |
| | 286 | for (pTempLog = pAllLogs; pTempLog; pTempLog = pTempLog->Next) { |
| | 287 | data_dump(pTempLog); |
| | 288 | } |
| | 289 | SigDump = 0; |
| | 290 | } |
| | 291 | |
| | 292 | continue; |
| | 293 | break; |
| | 294 | |
| | 295 | case -2: |
| 273 | | } |
| 274 | | closepcap(); |
| 275 | | sleep(2); |
| 276 | | while (!openpcap(device, promisc)) { |
| 277 | | sleep(2); |
| 278 | | } |
| 279 | | continue; |
| | 304 | break; |
| | 305 | |
| | 306 | default: |
| | 307 | /* If pcap_next returns with -1, there is an error on the link, so we close it and try to reopen it |
| | 308 | Other return codes should not exist, but as I don't know what could hapen, we'll handel them like a -1 return code. |
| | 309 | */ |
| | 310 | DEBUG_MSG("pcap_next_ex error [errormessage : %s]\n", pcap_geterr(pcap_global_descriptor)); |
| | 311 | |
| | 312 | closepcap(); |
| | 313 | sleep(2); |
| | 314 | while (!openpcap(device, promisc)) { |
| | 315 | sleep(2); |
| | 316 | } |
| | 317 | continue; |
| | 318 | break; |
| | 319 | |
| | 320 | |