Skip to content

Commit

Permalink
Add option to disable promiscuous mode
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Sep 10, 2013
1 parent 99a808f commit 2785e46
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/include/pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ struct fr_pcap {
char errbuf[PCAP_ERRBUF_SIZE]; //!< Last error on this interface.
fr_pcap_type_t type; //!< What type of handle this is.
char *name; //!< Name of file or interface.
bool promiscuous; //!< Whether the interface is in promiscuous mode
//!< only valid for live capture handles.

pcap_t *handle; //!< libpcap handle.
pcap_dumper_t *dumper; //!< libpcap dumper handle.
Expand Down
1 change: 1 addition & 0 deletions src/include/radsniff.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ struct rs {
bool to_stdout; //!< Were writing pcap data to stdout.

bool from_auto; //!< From list was auto-generated.
bool promiscuous; //!< Capture in promiscuous mode.
bool print_packet; //!< Print packet info, disabled with -W

bool do_sort; //!< Whether we sort attributes in the packet.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int fr_pcap_open(fr_pcap_t *pcap)
if (pcap_set_timeout(pcap->handle, PCAP_NONBLOCK_TIMEOUT) != 0) {
goto error;
}
if (pcap_set_promisc(pcap->handle, true) != 0) {
if (pcap_set_promisc(pcap->handle, pcap->promiscuous) != 0) {
goto error;
}
if (pcap_set_buffer_size(pcap->handle, SNAPLEN * 10000) != 0) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/radsniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ static void NEVER_RETURNS usage(int status)
fprintf(output, " -h This help message.\n");
fprintf(output, " -i <interface> Capture packets from interface (defaults to all if supported).\n");
fprintf(output, " -I <file> Read packets from file (overrides input of -F).\n");
fprintf(output, " -m Don't put interface(s) into promiscuous mode.\n");
fprintf(output, " -p <port> Filter packets by port (default is 1812).\n");
fprintf(output, " -q Print less debugging information.\n");
fprintf(output, " -r <filter> RADIUS attribute filter.\n");
Expand Down Expand Up @@ -980,11 +981,13 @@ int main(int argc, char *argv[])
* Set some defaults
*/
conf->print_packet = true;
conf->limit = -1;
conf->promiscuous = true;

/*
* Get options
*/
while ((opt = getopt(argc, argv, "c:d:DFf:hi:I:p:qr:s:Svw:xXW:P:O:")) != EOF) {
while ((opt = getopt(argc, argv, "c:d:DFf:hi:I:mp:qr:s:Svw:xXW:P:O:")) != EOF) {
switch (opt) {
case 'c':
limit = atoi(optarg);
Expand Down Expand Up @@ -1048,6 +1051,9 @@ int main(int argc, char *argv[])
in_head = &(*in_head)->next;
conf->from_file = true;
break;
case 'm':
conf->promiscuous = false;
break;

case 'p':
port = atoi(optarg);
Expand Down Expand Up @@ -1319,6 +1325,7 @@ int main(int argc, char *argv[])
for (in_p = in;
in_p;
in_p = in_p->next) {
in_p->promiscuous = conf->promiscuous;
if (fr_pcap_open(in_p) < 0) {
if (!conf->from_auto) {
ERROR("Failed opening pcap handle for %s", in_p->name);
Expand Down

0 comments on commit 2785e46

Please sign in to comment.