update to remove packet direction requirement when sniffing on OpenBSD loopback interfaces

This commit is contained in:
Michael Rash 2011-10-28 23:01:06 -04:00
parent cde71b1b27
commit b1b830f744

View File

@ -57,6 +57,7 @@ pcap_capture(fko_srv_options_t *opts)
int pcap_errcnt = 0; int pcap_errcnt = 0;
int pending_break = 0; int pending_break = 0;
int promisc = 0; int promisc = 0;
int set_direction = 1;
int status; int status;
pid_t child_pid; pid_t child_pid;
@ -77,17 +78,10 @@ pcap_capture(fko_srv_options_t *opts)
if(pcap == NULL) if(pcap == NULL)
{ {
log_msg(LOG_ERR, "* pcap_open_live error: %s\n", errstr); log_msg(LOG_ERR, "[*] pcap_open_live error: %s\n", errstr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* We are only interested on seeing packets coming into the interface.
*/
if (pcap_setdirection(pcap, PCAP_D_IN) < 0)
if(opts->verbose)
log_msg(LOG_WARNING, "* Warning: pcap error on setdirection: %s.",
pcap_geterr(pcap));
if (pcap == NULL) if (pcap == NULL)
{ {
log_msg(LOG_ERR, "[*] pcap error: %s", errstr); log_msg(LOG_ERR, "[*] pcap error: %s", errstr);
@ -129,6 +123,11 @@ pcap_capture(fko_srv_options_t *opts)
case DLT_LINUX_SLL: case DLT_LINUX_SLL:
opts->data_link_offset = 16; opts->data_link_offset = 16;
break; break;
#elif defined(__OpenBSD__)
case DLT_LOOP:
set_direction = 0;
opts->data_link_offset = 4;
break;
#endif #endif
case DLT_NULL: case DLT_NULL:
opts->data_link_offset = 4; opts->data_link_offset = 4;
@ -138,6 +137,13 @@ pcap_capture(fko_srv_options_t *opts)
break; break;
} }
/* We are only interested on seeing packets coming into the interface.
*/
if (set_direction && (pcap_setdirection(pcap, PCAP_D_IN) < 0))
if(opts->verbose)
log_msg(LOG_WARNING, "[*] Warning: pcap error on setdirection: %s.",
pcap_geterr(pcap));
/* Set our pcap handle nonblocking mode. /* Set our pcap handle nonblocking mode.
* *
* NOTE: This is simply set to 0 for now until we find a need * NOTE: This is simply set to 0 for now until we find a need