patch-arpd_c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. --- arpd.orig/arpd.c 2003-02-09 05:20:40.000000000 +0100
  2. +++ arpd/arpd.c 2014-03-16 08:11:53.000000000 +0100
  3. @@ -70,7 +70,7 @@ static int arpd_sig;
  4. static void
  5. usage(void)
  6. {
  7. - fprintf(stderr, "Usage: arpd [-d] [-i interface] [net]\n");
  8. + fprintf(stderr, "Usage: arpd [-d] [-i interface] [-a 'pcap_expr'] [{host|net|range} ...]\n");
  9. exit(1);
  10. }
  11. @@ -182,7 +182,7 @@ arpd_expandips(int naddresses, char **ad
  12. }
  13. static void
  14. -arpd_init(char *dev, int naddresses, char **addresses)
  15. +arpd_init(char *dev, char *and_pcap_exp, int naddresses, char **addresses)
  16. {
  17. struct bpf_program fcode;
  18. char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst;
  19. @@ -214,9 +214,13 @@ arpd_init(char *dev, int naddresses, cha
  20. errx(1, "bad interface configuration: not IP or Ethernet");
  21. arpd_ifent.intf_addr.addr_bits = IP_ADDR_BITS;
  22. - snprintf(filter, sizeof(filter), "arp %s%s%s and not ether src %s",
  23. + snprintf(filter, sizeof(filter), "arp %s%s%s and not ether src %s%s%s%s",
  24. dst ? "and (" : "", dst ? dst : "", dst ? ")" : "",
  25. - addr_ntoa(&arpd_ifent.intf_link_addr));
  26. + addr_ntoa(&arpd_ifent.intf_link_addr),
  27. + and_pcap_exp ? " and (" : "",
  28. + and_pcap_exp ? and_pcap_exp : "",
  29. + and_pcap_exp ? ")" : ""
  30. + );
  31. if ((arpd_pcap = pcap_open_live(dev, 128, 0, 500, ebuf)) == NULL)
  32. errx(1, "pcap_open_live: %s", ebuf);
  33. @@ -265,7 +269,7 @@ arpd_send(eth_t *eth, int op,
  34. spa->addr_ip, tha->addr_eth, tpa->addr_ip);
  35. if (op == ARP_OP_REQUEST) {
  36. - syslog(LOG_DEBUG, __FUNCTION__ ": who-has %s tell %s",
  37. + syslog(LOG_DEBUG, "%s: who-has %s tell %s", __FUNCTION__,
  38. addr_ntoa(tpa), addr_ntoa(spa));
  39. } else if (op == ARP_OP_REPLY) {
  40. syslog(LOG_INFO, "arp reply %s is-at %s",
  41. @@ -282,7 +286,7 @@ arpd_lookup(struct addr *addr)
  42. int error;
  43. if (addr_cmp(addr, &arpd_ifent.intf_addr) == 0) {
  44. - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
  45. + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
  46. addr_ntoa(addr), addr_ntoa(&arpd_ifent.intf_link_addr));
  47. return (0);
  48. }
  49. @@ -291,10 +295,10 @@ arpd_lookup(struct addr *addr)
  50. error = arp_get(arpd_arp, &arpent);
  51. if (error == -1) {
  52. - syslog(LOG_DEBUG, __FUNCTION__ ": no entry for %s",
  53. + syslog(LOG_DEBUG, "%s: no entry for %s", __FUNCTION__,
  54. addr_ntoa(addr));
  55. } else {
  56. - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
  57. + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
  58. addr_ntoa(addr), addr_ntoa(&arpent.arp_ha));
  59. }
  60. return (error);
  61. @@ -423,7 +427,7 @@ arpd_recv_cb(u_char *u, const struct pca
  62. if ((req = SPLAY_FIND(tree, &arpd_reqs, &tmp)) != NULL) {
  63. addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
  64. ethip->ar_sha, ETH_ADDR_LEN);
  65. - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
  66. + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
  67. addr_ntoa(&req->pa), addr_ntoa(&src.arp_ha));
  68. /* This address is claimed */
  69. @@ -445,9 +449,6 @@ arpd_recv(int fd, short type, void *ev)
  70. void
  71. terminate_handler(int sig)
  72. {
  73. - extern int event_gotsig;
  74. -
  75. - event_gotsig = 1;
  76. arpd_sig = sig;
  77. }
  78. @@ -464,15 +465,14 @@ int
  79. main(int argc, char *argv[])
  80. {
  81. struct event recv_ev;
  82. - extern int (*event_sigcb)(void);
  83. - char *dev;
  84. + char *dev, *and_pcap_exp;
  85. int c, debug;
  86. FILE *fp;
  87. dev = NULL;
  88. debug = 0;
  89. - while ((c = getopt(argc, argv, "di:h?")) != -1) {
  90. + while ((c = getopt(argc, argv, "a:di:h?")) != -1) {
  91. switch (c) {
  92. case 'd':
  93. debug = 1;
  94. @@ -480,6 +480,9 @@ main(int argc, char *argv[])
  95. case 'i':
  96. dev = optarg;
  97. break;
  98. + case 'a':
  99. + and_pcap_exp = optarg;
  100. + break;
  101. default:
  102. usage();
  103. break;
  104. @@ -489,9 +492,9 @@ main(int argc, char *argv[])
  105. argv += optind;
  106. if (argc == 0)
  107. - arpd_init(dev, 0, NULL);
  108. + arpd_init(dev, and_pcap_exp, 0, NULL);
  109. else
  110. - arpd_init(dev, argc, argv);
  111. + arpd_init(dev, and_pcap_exp, argc, argv);
  112. if ((fp = fopen(PIDFILE, "w")) == NULL)
  113. err(1, "fopen");
  114. @@ -524,7 +527,6 @@ main(int argc, char *argv[])
  115. perror("signal");
  116. return (-1);
  117. }
  118. - event_sigcb = arpd_signal;
  119. event_dispatch();