简体   繁体   中英

pfring could not capture inbound packets on Ethernet of Raspberry Pi 3 B

I have installed PFRING-6.6.0 (loaded "pf_ring.ko") on my x86_64 machine running Ubuntu 14.04 to capture all incoming packets on "eth0" whose source or destination port is "2404" (see the code below). and the code is working fine. The following code creates a pfring socket with given BPF filter and the socket should capture only incoming "2404" packets
But my problem is though I have installed the same PFRING on my Raspberry Pi 3 B machine running Ubuntu-mate 16.04, the same code is not able to capture the incoming packets. (I have changed the device name to "eth0"). is this architecture related problem ?.. how resolve this ?.

char *device = "eth0";
pfring *pd;
int main(int argc, char *argv[]) {

               /* hard coaded filters */
              char *bpfFilter "(ip host 10.180.6.105 && ip host 10.180.5.179) && tcp port 2404"; 
               u_int32_t flags = 0;
               int i = 0;
               flags |= PF_RING_REENTRANT;
               flags |= PF_RING_PROMISC;
               flags |= PF_RING_HW_TIMESTAMP;
               flags |= PF_RING_STRIP_HW_TIMESTAMP;
               flags |= PF_RING_CHUNK_MODE;
               flags |= PF_RING_IXIA_TIMESTAMP;

                  pd = pfring_open(device, 256, flags);
                  if (pd == NULL) {
                     fprintf(stderr, "pfring_open error [%s] (pf_ring not loaded or interface %s is down ?)\n",
                      strerror(errno), device);
                     exit(0);
                  } 
                  if ((pfring_set_direction(pd, 1)) != 0)   /* 0=RX+TX, 1=RX only, 2=TX only */     
                     fprintf (stderr, "capture direction not set\n");
                  if ((pfring_set_socket_mode(pd, recv_only_mode)) != 0)
                     fprintf(stderr, "pfring_set_socket_mode unsuccessfull\n");
                  if ((pfring_set_bpf_filter(pd, bpfFilter)) < 0)
                     fprintf(stderr, "pfring_set_bpf_filter unsuccessfull\n");
                  else
                      fprintf(stderr, "set_bpf_filter successfull\n");

                  pfring_set_poll_duration(pd, 500);

                  if (pfring_enable_ring(pd) != 0) {
                     printf("Failed to enable ring :-(\n");
                     pfring_close(pd);     
                  } 
                  while(1) {
                        if ((ret = pfring_is_pkt_available(pd)) == 0) {     
                           printf("No incomming packet %d\n");
                           continue;
                        }
                        if ((ret = pfring_loop(pd[RTUnum], RTUProcesssPacket, (u_char*)&RTUnum, 0)) != 0) {
                           fprintf(stderr, "Failed to capture packet\n");
                           sleep(1);
                        }
                  }  
}

void RTUProcesssPacket(const struct pfring_pkthdr *h,
                       const u_char *packet, const u_char *user_bytes) { 
      log packets into pcap file;
      parse the packet;
      apply IDS rules();
   }

OUTPUT:
(ip host 10.180.6.105 && ip host 10.180.5.179) && tcp port 2404
set_bpf_filter successfull

No incomming packet
No incomming packet
No incomming packet
No incomming packet
No incomming packet

据我了解,rpi是64位架构,而raspian os只有32位

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM