1
0

patch-arpd_c 3.6 KB

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