202-protocol_api.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. This API extension is used by ead (Emergency Access Daemon)
  2. --- a/pcap-linux.c
  3. +++ b/pcap-linux.c
  4. @@ -425,7 +425,7 @@ static int iface_get_id(int fd, const ch
  5. static int iface_get_mtu(int fd, const char *device, char *ebuf);
  6. static int iface_get_arptype(int fd, const char *device, char *ebuf);
  7. #ifdef HAVE_PF_PACKET_SOCKETS
  8. -static int iface_bind(int fd, int ifindex, char *ebuf);
  9. +static int iface_bind(int fd, int ifindex, char *ebuf, unsigned short proto);
  10. #ifdef IW_MODE_MONITOR
  11. static int has_wext(int sock_fd, const char *device, char *ebuf);
  12. #endif /* IW_MODE_MONITOR */
  13. @@ -1059,7 +1059,7 @@ pcap_can_set_rfmon_linux(pcap_t *handle)
  14. * (We assume that if we have Wireless Extensions support
  15. * we also have PF_PACKET support.)
  16. */
  17. - sock_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  18. + sock_fd = socket(PF_PACKET, SOCK_RAW, p->opt.proto);
  19. if (sock_fd == -1) {
  20. (void)pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
  21. "socket: %s", pcap_strerror(errno));
  22. @@ -1456,6 +1456,9 @@ pcap_activate_linux(pcap_t *handle)
  23. handle->read_op = pcap_read_linux;
  24. handle->stats_op = pcap_stats_linux;
  25. + if (handle->opt.proto < 0)
  26. + handle->opt.proto = (int) htons(ETH_P_ALL);
  27. +
  28. /*
  29. * The "any" device is a special device which causes us not
  30. * to bind to a particular device and thus to look at all
  31. @@ -3335,8 +3338,8 @@ activate_new(pcap_t *handle)
  32. * try a SOCK_RAW socket for the raw interface.
  33. */
  34. sock_fd = is_any_device ?
  35. - socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)) :
  36. - socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  37. + socket(PF_PACKET, SOCK_DGRAM, handle->opt.proto) :
  38. + socket(PF_PACKET, SOCK_RAW, handle->opt.proto);
  39. if (sock_fd == -1) {
  40. if (errno == EINVAL || errno == EAFNOSUPPORT) {
  41. @@ -3454,7 +3457,7 @@ activate_new(pcap_t *handle)
  42. return PCAP_ERROR;
  43. }
  44. sock_fd = socket(PF_PACKET, SOCK_DGRAM,
  45. - htons(ETH_P_ALL));
  46. + handle->opt.proto);
  47. if (sock_fd == -1) {
  48. pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
  49. "socket: %s", pcap_strerror(errno));
  50. @@ -3518,7 +3521,7 @@ activate_new(pcap_t *handle)
  51. }
  52. if ((err = iface_bind(sock_fd, handlep->ifindex,
  53. - handle->errbuf)) != 1) {
  54. + handle->errbuf, handle->opt.proto)) != 1) {
  55. close(sock_fd);
  56. if (err < 0)
  57. return err;
  58. @@ -5271,7 +5274,7 @@ iface_get_id(int fd, const char *device,
  59. * or a PCAP_ERROR_ value on a hard error.
  60. */
  61. static int
  62. -iface_bind(int fd, int ifindex, char *ebuf)
  63. +iface_bind(int fd, int ifindex, char *ebuf, unsigned short proto)
  64. {
  65. struct sockaddr_ll sll;
  66. int err;
  67. @@ -5280,7 +5283,7 @@ iface_bind(int fd, int ifindex, char *eb
  68. memset(&sll, 0, sizeof(sll));
  69. sll.sll_family = AF_PACKET;
  70. sll.sll_ifindex = ifindex;
  71. - sll.sll_protocol = htons(ETH_P_ALL);
  72. + sll.sll_protocol = proto;
  73. if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) == -1) {
  74. if (errno == ENETDOWN) {
  75. @@ -6325,7 +6328,7 @@ activate_old(pcap_t *handle)
  76. /* Open the socket */
  77. - handle->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
  78. + handle->fd = socket(PF_INET, SOCK_PACKET, handle->opt.proto);
  79. if (handle->fd == -1) {
  80. pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
  81. "socket: %s", pcap_strerror(errno));
  82. --- a/pcap.c
  83. +++ b/pcap.c
  84. @@ -578,6 +578,7 @@ pcap_create_common(char *ebuf, size_t si
  85. p->opt.promisc = 0;
  86. p->opt.rfmon = 0;
  87. p->opt.immediate = 0;
  88. + p->opt.proto = -1;
  89. p->opt.tstamp_type = -1; /* default to not setting time stamp type */
  90. p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
  91. @@ -771,6 +772,15 @@ pcap_get_tstamp_precision(pcap_t *p)
  92. }
  93. int
  94. +pcap_set_protocol(pcap_t *p, unsigned short proto)
  95. +{
  96. + if (pcap_check_activated(p))
  97. + return PCAP_ERROR_ACTIVATED;
  98. + p->opt.proto = proto;
  99. + return 0;
  100. +}
  101. +
  102. +int
  103. pcap_activate(pcap_t *p)
  104. {
  105. int status;
  106. --- a/pcap/pcap.h
  107. +++ b/pcap/pcap.h
  108. @@ -68,6 +68,7 @@ extern "C" {
  109. #define PCAP_VERSION_MINOR 4
  110. #define PCAP_ERRBUF_SIZE 256
  111. +#define HAS_PROTO_EXTENSION
  112. /*
  113. * Compatibility for systems that have a bpf.h that
  114. @@ -287,6 +288,7 @@ PCAP_API int pcap_set_timeout(pcap_t *,
  115. PCAP_API int pcap_set_tstamp_type(pcap_t *, int);
  116. PCAP_API int pcap_set_immediate_mode(pcap_t *, int);
  117. PCAP_API int pcap_set_buffer_size(pcap_t *, int);
  118. +PCAP_API int pcap_set_protocol(pcap_t *, unsigned short);
  119. PCAP_API int pcap_set_tstamp_precision(pcap_t *, int);
  120. PCAP_API int pcap_get_tstamp_precision(pcap_t *);
  121. PCAP_API int pcap_activate(pcap_t *);
  122. --- a/pcap-int.h
  123. +++ b/pcap-int.h
  124. @@ -111,6 +111,7 @@ struct pcap_opt {
  125. char *device;
  126. int timeout; /* timeout for buffering */
  127. u_int buffer_size;
  128. + int proto; /* protocol for packet socket (linux) */
  129. int promisc;
  130. int rfmon; /* monitor mode */
  131. int immediate; /* immediate mode - deliver packets as soon as they arrive */