15_checksum_libnids.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. diff -Nur dsniff-2.4-old/dsniff.c dsniff-2.4/dsniff.c
  2. --- dsniff-2.4-old/dsniff.c 2009-09-15 00:11:20.318202445 +0300
  3. +++ dsniff-2.4/dsniff.c 2009-09-15 00:11:20.780452193 +0300
  4. @@ -70,6 +70,80 @@
  5. {
  6. }
  7. +
  8. +static int get_all_ifaces(struct ifreq **, int *);
  9. +static unsigned int get_addr_from_ifreq(struct ifreq *);
  10. +
  11. +int all_local_ipaddrs_chksum_disable()
  12. +{
  13. + struct ifreq *ifaces;
  14. + int ifaces_count;
  15. + int i, ind = 0;
  16. + struct nids_chksum_ctl *ctlp;
  17. + unsigned int tmp;
  18. +
  19. + if (!get_all_ifaces(&ifaces, &ifaces_count))
  20. + return -1;
  21. + ctlp =
  22. + (struct nids_chksum_ctl *) malloc(ifaces_count *
  23. + sizeof(struct
  24. + nids_chksum_ctl));
  25. + if (!ctlp)
  26. + return -1;
  27. + for (i = 0; i < ifaces_count; i++) {
  28. + tmp = get_addr_from_ifreq(ifaces + i);
  29. + if (tmp) {
  30. + ctlp[ind].netaddr = tmp;
  31. + ctlp[ind].mask = inet_addr("255.255.255.255");
  32. + ctlp[ind].action = NIDS_DONT_CHKSUM;
  33. + ind++;
  34. + }
  35. + }
  36. + free(ifaces);
  37. + nids_register_chksum_ctl(ctlp, ind);
  38. +}
  39. +
  40. +/* helper functions for Example 2 */
  41. +unsigned int get_addr_from_ifreq(struct ifreq *iface)
  42. +{
  43. + if (iface->ifr_addr.sa_family == AF_INET)
  44. + return ((struct sockaddr_in *) &(iface->ifr_addr))->
  45. + sin_addr.s_addr;
  46. + return 0;
  47. +}
  48. +
  49. +static int get_all_ifaces(struct ifreq **ifaces, int *count)
  50. +{
  51. + int ifaces_size = 8 * sizeof(struct ifreq);
  52. + struct ifconf param;
  53. + int sock;
  54. + unsigned int i;
  55. +
  56. + *ifaces = malloc(ifaces_size);
  57. + sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
  58. + if (sock <= 0)
  59. + return 0;
  60. + for (;;) {
  61. + param.ifc_len = ifaces_size;
  62. + param.ifc_req = *ifaces;
  63. + if (ioctl(sock, SIOCGIFCONF, &param))
  64. + goto err;
  65. + if (param.ifc_len < ifaces_size)
  66. + break;
  67. + free(*ifaces);
  68. + ifaces_size *= 2;
  69. + ifaces = malloc(ifaces_size);
  70. + }
  71. + *count = param.ifc_len / sizeof(struct ifreq);
  72. + close(sock);
  73. + return 1;
  74. + err:
  75. + close(sock);
  76. + return 0;
  77. +}
  78. +
  79. +
  80. +
  81. int
  82. main(int argc, char *argv[])
  83. {
  84. @@ -189,6 +263,8 @@
  85. warnx("using %s", nids_params.filename);
  86. }
  87. }
  88. +
  89. + all_local_ipaddrs_chksum_disable();
  90. nids_run();