Commit 05f5c2a7 authored by Olav Kvittem's avatar Olav Kvittem

make pcap compile time activatable : #ifdef

parent 0916199b
Pipeline #20734 passed with stages
in 3 minutes and 2 seconds
......@@ -48,7 +48,9 @@
#include <netinet/ip6.h>
#include <netinet/udp.h>
#include <limits.h>
#ifdef PCAP
#include <pcap.h>
#endif
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
//#include <linux/if_packet.h> // provided by netpacket/packet.h
......@@ -110,8 +112,13 @@ char preffix[] = "::ffff:";
short opt_af_packet=0, opt_pcap=0;
short opt_ktime=0; // kernel packet time by ioctl
short opt_fork=0; // fork for write in separate process with noblock for improving packet loss
short pcap_enabled=0;
#ifdef PCAP
char pcap_dev[100]="";
pcap_t *main_pcap;
pcap_enabled=1;
#endif
// data structure for ouput ring buffer
int osize;
......@@ -266,6 +273,7 @@ int main(int argc, char **argv)
break;
case 'C': // pcap capture
#ifdef PCAP
if(optarg != NULL)
{
errno=0;
......@@ -277,6 +285,10 @@ int main(int argc, char **argv)
RUDEBUG1("crude: invalid commandline arguments!\n");
retval = -2;
}
#else
printf("Recompile and enable PCAP with -DPCAP\n");
retval= -2;
#endif
break;
case 'i':
......@@ -655,6 +667,7 @@ static int make_conn(unsigned short port, char *ifaddr,int use_ip6,unsigned int
return -3;
}
} else if (opt_pcap) {
#ifdef PCAP
struct bpf_program fp; /* The compiled filter */
char filter[100];
char errbuf[PCAP_ERRBUF_SIZE];
......@@ -669,11 +682,11 @@ static int make_conn(unsigned short port, char *ifaddr,int use_ip6,unsigned int
RUDEBUG1("Couldn't parse filter %s: %s\n", filter, pcap_geterr(main_pcap));
return(-1);
}
if ( pcap_setfilter(main_pcap, &fp) == -1) {
if ( pcap_setfilter(main_pcap, &fp) == -1) {
RUDEBUG1("Couldn't install filter %s: %s\n", filter, pcap_geterr(main_pcap));
return(-1);
}
#endif
} else {
if( (our_sock=socket(our_addr.ss_family ,SOCK_DGRAM,0) ) < 0)
......@@ -1048,6 +1061,7 @@ static int rec_to_file(unsigned short port, unsigned long limit)
while(1)
{
if ( opt_pcap){
#ifdef PCAP
if ( ( result= pcap_next_ex(main_pcap, &header, &packet)) < 1 ){
if ( result == 0 ) continue; // just timeout waiting for data
fprintf( stderr, "crude: error when receiving pcap packet: result %d , error %s \n",
......@@ -1055,6 +1069,7 @@ static int rec_to_file(unsigned short port, unsigned long limit)
rec_bytes=0;
};
rec_bytes = header->caplen;
#endif
} else {
rec_bytes = recvfrom(main_socket, buffer, PMAXSIZE, 0,
(struct sockaddr *)&src_addr, (socklen_t *)&src_len);
......@@ -1071,10 +1086,12 @@ static int rec_to_file(unsigned short port, unsigned long limit)
time1=(struct timeval){0}; // new packet - blank
if ( opt_pcap || opt_af_packet){ // raw packets unwrap
#ifdef PCAP
if ( opt_pcap) { // ether header
rude_data= (struct udp_data*) (packet + 14) ; // compile error : sizeof(struct ether_header);
memcpy(&time1, &header->ts, sizeof(struct timeval));
}
}
#endif
unsigned short iphdrlen;
unsigned char prot;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment