1
0

patch-rarpd_c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. --- rarpd-1.1.orig/rarpd.c 1999-11-17 01:51:22.000000000 +0100
  2. +++ rarpd-1.1/rarpd.c 2009-12-11 14:28:32.000000000 +0100
  3. @@ -65,18 +65,12 @@
  4. #define ETHERSTRLEN sizeof("00:00:00:00:00:00")
  5. #define IPSTRLEN sizeof(".xxx.xxx.xxx.xxx")
  6. -#ifdef NEW_LIBNET_INTERFACE
  7. -#define open_link_interface libnet_open_link_interface
  8. -#define link_int libnet_link_int
  9. -#define build_arp libnet_build_arp
  10. -#define get_ipaddr libnet_get_ipaddr
  11. -#define get_hwaddr libnet_get_hwaddr
  12. -#define build_ethernet libnet_build_ethernet
  13. -#define write_link_layer libnet_write_link_layer
  14. -
  15. -/* Temporary workaround */
  16. -#define ARP_H LIBNET_ARP_H
  17. -#endif
  18. +struct _ipv4_arp_data_ {
  19. + u_char ar_sha[6]; /* sender hardware address */
  20. + u_char ar_spa[4]; /* sender protocol address */
  21. + u_char ar_tha[6]; /* target hardware address */
  22. + u_char ar_tpa[4]; /* target protocol address */
  23. +};
  24. extern char pcap_version[];
  25. extern int optind;
  26. @@ -88,7 +82,7 @@ static int vflag; /
  27. static char *program_name;
  28. static pcap_t *pd;
  29. -static struct link_int *ln;
  30. +static libnet_t *ld;
  31. static char *device, *ethers;
  32. struct in_addr my_ipaddr;
  33. static u_char my_hwaddr[ETHERADDRLEN];
  34. @@ -285,23 +279,34 @@ void set_arp(struct in_addr *herip, unsi
  35. void send_rarpreply(unsigned char *dest_hwaddr,
  36. unsigned char *her_hwaddr, struct in_addr *her_ipaddr)
  37. {
  38. - char ebuf[PCAP_ERRBUF_SIZE];
  39. - u_char buf[ARP_H+ETH_H];
  40. -
  41. - memset(buf, 0, ARP_H + ETH_H);
  42. -
  43. - /* Ethernet header */
  44. - build_ethernet(dest_hwaddr, my_hwaddr, ETHERTYPE_REVARP, NULL, 0, buf);
  45. + int c;
  46. + libnet_ptag_t t;
  47. /* ARP header */
  48. - build_arp(ARPHRD_ETHER, ETHERTYPE_IP,
  49. + t = libnet_build_arp(ARPHRD_ETHER, ETHERTYPE_IP,
  50. ETHERADDRLEN, IPADDRLEN,
  51. ARPOP_REVREPLY,
  52. my_hwaddr, (u_char *)&(my_ipaddr.s_addr),
  53. her_hwaddr, (u_char *)&(her_ipaddr->s_addr),
  54. - NULL, 0, buf + ETH_H);
  55. + NULL, 0, ld, 0);
  56. + if (t == -1) {
  57. + syslog(LOG_ERR, "%s: Can't build ARP header: %s", program_name, libnet_geterror(ld));
  58. + exit(1);
  59. + }
  60. - write_link_layer(ln, (const u_char *)device, buf, ARP_H + ETH_H);
  61. + /* Ethernet header */
  62. + t = libnet_build_ethernet(dest_hwaddr, my_hwaddr, ETHERTYPE_REVARP, NULL, 0, ld, 0);
  63. + if (t == -1) {
  64. + syslog(LOG_ERR, "%s: Can't build ethernet header: %s", program_name,
  65. + libnet_geterror(ld));
  66. + exit(1);
  67. + }
  68. +
  69. + c = libnet_write(ld);
  70. + if (c == -1) {
  71. + syslog(LOG_ERR, "%s: Write error: %s", program_name, libnet_geterror(ld));
  72. + exit(1);
  73. + }
  74. }
  75. @@ -314,11 +319,13 @@ void process_arp(u_char *user, const str
  76. unsigned short pro, hrd, op;
  77. struct in_addr her_ipaddr;
  78. struct libnet_arp_hdr *ap;
  79. + struct _ipv4_arp_data_ *ad;
  80. struct hostent *hp;
  81. char *ipp;
  82. bp += sizeof(struct libnet_ethernet_hdr);
  83. ap = (struct libnet_arp_hdr *)bp;
  84. + ad = (struct _ipv4_arp_data_ *)(bp + sizeof(*ap));
  85. pro = EXTRACT_16BITS (&ap->ar_pro);
  86. hrd = EXTRACT_16BITS (&ap->ar_hrd);
  87. @@ -331,10 +338,10 @@ void process_arp(u_char *user, const str
  88. /* We only answer RARP requests */
  89. if (op != ARPOP_REVREQUEST) return;
  90. - sha = ap->ar_sha;
  91. - spa = ap->ar_spa;
  92. - tha = ap->ar_tha;
  93. - tpa = ap->ar_tpa;
  94. + sha = ad->ar_sha;
  95. + spa = ad->ar_spa;
  96. + tha = ad->ar_tha;
  97. + tpa = ad->ar_tpa;
  98. if (my_ether_ntohost(toret, tha)) {
  99. if (vflag) {
  100. @@ -399,6 +406,7 @@ int main(int argc, char **argv)
  101. int nofork, op, pid, syslogflags;
  102. bpf_u_int32 localnet, netmask;
  103. char ebuf[PCAP_ERRBUF_SIZE];
  104. + char errbuf[LIBNET_ERRBUF_SIZE];
  105. char *cmdbuf;
  106. struct bpf_program fcode;
  107. @@ -446,9 +454,9 @@ int main(int argc, char **argv)
  108. }
  109. }
  110. - ln = open_link_interface(device, ebuf);
  111. - if (ln == NULL) {
  112. - syslog(LOG_ERR, "%s: %s", program_name, ebuf);
  113. + ld = libnet_init(LIBNET_LINK, device, errbuf);
  114. + if (ld == NULL) {
  115. + syslog(LOG_ERR, "%s: %s", program_name, errbuf);
  116. exit(1);
  117. }
  118. @@ -465,8 +473,8 @@ int main(int argc, char **argv)
  119. }
  120. memset(&my_ipaddr, 0, sizeof(my_ipaddr));
  121. - my_ipaddr.s_addr = htonl(get_ipaddr(ln, device, ebuf));
  122. - memcpy(my_hwaddr, (char *)get_hwaddr(ln, device, ebuf), ETHERADDRLEN);
  123. + my_ipaddr.s_addr = libnet_get_ipaddr4(ld);
  124. + memcpy(my_hwaddr, (char *) libnet_get_hwaddr(ld), ETHERADDRLEN);
  125. setuid(getuid());