libdnet-1.10-nmap2.diff 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. o Made some code changes to intf.c (the patch below). This does the following:
  2. o Preserve the alias qualifier from interface name in more cases
  3. (e.g. don't blow away :2 from eth0:2 when it may still be needed.
  4. o Set the SO_BROADCAST flag on the interface list descriptor so that
  5. broadcast/network IPs can be investigated.
  6. o Update _match_intf_src so that it checks interface aliases for the
  7. given source address rather than only the main interface address.
  8. --- src/intf.c 2005-02-10 17:57:35.000000000 +0100
  9. +++ src/intf.c.oden 2005-12-10 20:16:15.000000000 +0100
  10. @@ -119,12 +119,16 @@
  11. intf_open(void)
  12. {
  13. intf_t *intf;
  14. + int one = 1;
  15. if ((intf = calloc(1, sizeof(*intf))) != NULL) {
  16. intf->fd = intf->fd6 = -1;
  17. if ((intf->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  18. return (intf_close(intf));
  19. +
  20. + setsockopt(intf->fd, SOL_SOCKET, SO_BROADCAST,
  21. + (const char *) &one, sizeof(one));
  22. #ifdef SIOCGIFNETMASK_IN6
  23. if ((intf->fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
  24. # ifdef EPROTONOSUPPORT
  25. @@ -472,6 +476,7 @@
  26. _intf_get_aliases(intf_t *intf, struct intf_entry *entry)
  27. {
  28. struct ifreq *ifr, *lifr;
  29. + struct ifreq tmpifr;
  30. struct addr *ap, *lap;
  31. char *p;
  32. @@ -492,9 +497,12 @@
  33. if ((p = strchr(ifr->ifr_name, ':')) != NULL)
  34. *p = '\0';
  35. - if (strcmp(ifr->ifr_name, entry->intf_name) != 0)
  36. + if (strcmp(ifr->ifr_name, entry->intf_name) != 0) {
  37. + if (p) *p = ':';
  38. continue;
  39. + }
  40. + if (p) *p = ':'; /* Fix the name back up */
  41. if (addr_ston(&ifr->ifr_addr, ap) < 0)
  42. continue;
  43. @@ -506,6 +514,10 @@
  44. if (ap->addr_ip == entry->intf_addr.addr_ip ||
  45. ap->addr_ip == entry->intf_dst_addr.addr_ip)
  46. continue;
  47. + strlcpy(tmpifr.ifr_name, ifr->ifr_name,
  48. + sizeof(tmpifr.ifr_name));
  49. + if (ioctl(intf->fd, SIOCGIFNETMASK, &tmpifr) == 0)
  50. + addr_stob(&tmpifr.ifr_addr, &ap->addr_bits);
  51. }
  52. #ifdef SIOCGIFNETMASK_IN6
  53. else if (ap->addr_type == ADDR_TYPE_IP6 && intf->fd6 != -1) {
  54. @@ -547,10 +559,22 @@
  55. static int
  56. _match_intf_src(const struct intf_entry *entry, void *arg)
  57. {
  58. + int matched = 0;
  59. + int cnt;
  60. struct intf_entry *save = (struct intf_entry *)arg;
  61. if (entry->intf_addr.addr_type == ADDR_TYPE_IP &&
  62. - entry->intf_addr.addr_ip == save->intf_addr.addr_ip) {
  63. + entry->intf_addr.addr_ip == save->intf_addr.addr_ip)
  64. + matched = 1;
  65. +
  66. + for (cnt = 0; !matched && cnt < (int) entry->intf_alias_num; cnt++) {
  67. + if (entry->intf_alias_addrs[cnt].addr_type != ADDR_TYPE_IP)
  68. + continue;
  69. + if (entry->intf_alias_addrs[cnt].addr_ip == save->intf_addr.addr_ip)
  70. + matched = 1;
  71. + }
  72. +
  73. + if (matched) {
  74. /* XXX - truncated result if entry is too small. */
  75. if (save->intf_len < entry->intf_len)
  76. memcpy(save, entry, save->intf_len);
  77. @@ -678,14 +702,18 @@
  78. if ((p = strchr(ifr->ifr_name, ':')) != NULL)
  79. *p = '\0';
  80. - if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0)
  81. + if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0) {
  82. + if (p) *p = ':';
  83. continue;
  84. + }
  85. memset(ebuf, 0, sizeof(ebuf));
  86. strlcpy(entry->intf_name, ifr->ifr_name,
  87. sizeof(entry->intf_name));
  88. entry->intf_len = sizeof(ebuf);
  89. + /* Repair the alias name back up. */
  90. + if (p) *p = ':';
  91. if (_intf_get_noalias(intf, entry) < 0)
  92. return (-1);
  93. if (_intf_get_aliases(intf, entry) < 0)