pfc.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Taken from fli4l 3.0
  3. * Make sure you compile it against the same libpcap version used in libreCMC
  4. */
  5. #include <stdlib.h>
  6. #include <sys/types.h>
  7. #include <sys/time.h>
  8. #include <string.h>
  9. #include <linux/types.h>
  10. #include <linux/ppp_defs.h>
  11. #include <pcap.h>
  12. #include <pcap-bpf.h>
  13. int main (int argc, char ** argv)
  14. {
  15. pcap_t *pc; /* Fake struct pcap so we can compile expr */
  16. struct bpf_program filter; /* Filter program for link-active pkts */
  17. u_int32_t netmask=0;
  18. int dflag = 3;
  19. if (argc == 4)
  20. {
  21. if (!strcmp (argv[1], "-d"))
  22. {
  23. dflag = atoi (argv[2]);
  24. argv += 2;
  25. argc -=2;
  26. }
  27. }
  28. if (argc != 2)
  29. {
  30. printf ("usage; %s [ -d <debug_level> ] expression\n", argv[0]);
  31. return 1;
  32. }
  33. pc = pcap_open_dead(DLT_PPP_PPPD, PPP_HDRLEN);
  34. if (pcap_compile(pc, &filter, argv[1], 1, netmask) == 0)
  35. {
  36. printf ("#\n# Expression: %s\n#\n", argv[1]);
  37. bpf_dump (&filter, dflag);
  38. return 0;
  39. }
  40. else
  41. {
  42. printf("error in active-filter expression: %s\n", pcap_geterr(pc));
  43. }
  44. return 1;
  45. }