Skip to contentSkip to conversation

how to receive arp packet from queue to application

DISCUSSION sat 1 participant 1 message Oct 30, 2015 netfilter

lore
Share & tools
lore

sat

author
#0 lore raw

I have added rule in nftables which will filter ARP packets. I am sending packet in queue but I am not able receive these packets in our application but using same application I can receive IP packet. Application which I am using.

main()
{
int fd;
char buf[65535];
int len=0;
handle =nfq_open();

   if(handle ==NULL)
    {
     printf("error in nfq_open\n");
     return 1;
    }
  if(nfq_unbind_pf(handle,AF_INET)<0)
    {
       printf("error during nfq_unbind_pf\n");
       exit(1);
    }

  if(nfq_bind_pf(handle,AF_INET)<0)
   {
      printf("error in binding\n");
      exit(1);
   }

  qh=nfq_create_queue(handle,0,&callback,NULL);

  if(qh==NULL)
  {
     printf("error to create new queue\n");
     exit(1);
  }


  if(nfq_set_mode(qh,NFQNL_COPY_PACKET,0xffff)<0)
  {
     printf("error to set mode \n");
     exit(1);
  }

  if(nfq_set_queue_maxlen(qh,NFQ_MAX_LEN)<0)
  {
     printf("error setting queue size\n");
  }

  fd =nfq_fd(handle);

  if(fd== (-1))
  {
   printf("error in opening nft queue\n");
   exit(1);
  }

  while(1)
  {
    len = recv(fd, buf, sizeof(buf), 0);
    printf("pkt received in main thread buf: %s length :%d\n",buf,len);

  nfq_destroy_queue(qh);

  printf("closing library handle\n");
  nfq_close(handle); /* closing the handler */

}