ebt_ulog based arpwatch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.3 KiB

15 years ago
  1. /***************************************************************************
  2. * Copyright (C) 07/2007 by Olaf Rempel *
  3. * razzor@kopf-tisch.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; version 2 of the License *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. #include <getopt.h>
  23. #include <time.h>
  24. #include "configfile.h"
  25. #include "datastore.h"
  26. #include "event.h"
  27. #include "logging.h"
  28. #include "netlink.h"
  29. #define DEFAULT_CONFIG "brarpwatch.conf"
  30. #define DEFAULT_LOGFILE "brarpwatch.log"
  31. static struct option opts[] = {
  32. {"config", 1, 0, 'c'},
  33. {"debug", 0, 0, 'd'},
  34. {"help", 0, 0, 'h'},
  35. {0, 0, 0, 0}
  36. };
  37. int main(int argc, char *argv[])
  38. {
  39. char *config = DEFAULT_CONFIG;
  40. int code, arg = 0, debug = 0;
  41. do {
  42. code = getopt_long(argc, argv, "c:dh", opts, &arg);
  43. switch (code) {
  44. case 'c': /* config */
  45. config = optarg;
  46. break;
  47. case 'd': /* debug */
  48. debug = 1;
  49. break;
  50. case 'h': /* help */
  51. printf("Usage: brarpwatch [options]\n"
  52. "Options: \n"
  53. " --config -c configfile use this configfile\n"
  54. " --debug -d do not fork and log to stderr\n"
  55. " --help -h this help\n"
  56. "\n");
  57. exit(0);
  58. break;
  59. case '?': /* error */
  60. exit(-1);
  61. break;
  62. default: /* unknown / all options parsed */
  63. break;
  64. }
  65. } while (code != -1);
  66. /* parse config file */
  67. if (config_parse(config))
  68. exit(1);
  69. if (datastore_init() < 0)
  70. exit(1);
  71. if (netlink_init() < 0) {
  72. datastore_close();
  73. exit(1);
  74. }
  75. #if 0
  76. unsigned char mac[6];
  77. unsigned char mac2[6];
  78. unsigned char mac3[6];
  79. unsigned int ip = 0x01000a0a;
  80. unsigned int ip2 = 0x02000a0a;
  81. long stamp = time(NULL);
  82. // subnet not found
  83. ds_check_update_ip("eth0", ip +1, mac, stamp++);
  84. // wrong dev not found
  85. ds_check_update_ip("eth1", ip, mac, stamp++);
  86. // ok
  87. ds_check_update_ip("eth0", ip, mac, stamp++);
  88. // wrong dev
  89. ds_check_update_ip("eth1", ip, mac, stamp++);
  90. // update
  91. ds_check_update_ip("eth0", ip, mac, stamp++);
  92. // warn
  93. ds_check_update_ip("eth0", ip, mac2, stamp++);
  94. // warn
  95. ds_check_update_ip("eth0", ip, mac3, stamp++);
  96. // ok
  97. ds_check_update_ip("eth0", ip2, mac, stamp++);
  98. #endif
  99. event_loop();
  100. netlink_close();
  101. datastore_close();
  102. return 0;
  103. }