3 @@ -187,6 +187,7 @@ struct pcap_opt {
7 + int proto; /* protocol for packet socket (linux) */
13 @@ -273,7 +273,7 @@ static int iface_get_id(int fd, const ch
14 static int iface_get_mtu(int fd, const char *device, char *ebuf);
15 static int iface_get_arptype(int fd, const char *device, char *ebuf);
16 #ifdef HAVE_PF_PACKET_SOCKETS
17 -static int iface_bind(int fd, int ifindex, char *ebuf);
18 +static int iface_bind(int fd, int ifindex, char *ebuf, unsigned short proto);
19 static int has_wext(int sock_fd, const char *device, char *ebuf);
20 static int enter_rfmon_mode_wext(pcap_t *handle, int sock_fd,
22 @@ -362,7 +362,7 @@ pcap_can_set_rfmon_linux(pcap_t *p)
23 * (We assume that if we have Wireless Extensions support
24 * we also have PF_PACKET support.)
26 - sock_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
27 + sock_fd = socket(PF_PACKET, SOCK_RAW, handle->opt.proto);
29 (void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
30 "socket: %s", pcap_strerror(errno));
31 @@ -522,6 +522,9 @@ pcap_activate_linux(pcap_t *handle)
32 handle->read_op = pcap_read_linux;
33 handle->stats_op = pcap_stats_linux;
35 + if (handle->opt.proto < 0)
36 + handle->opt.proto = (int) htons(ETH_P_ALL);
39 * The "any" device is a special device which causes us not
40 * to bind to a particular device and thus to look at all
41 @@ -1673,8 +1676,8 @@ activate_new(pcap_t *handle)
42 * try a SOCK_RAW socket for the raw interface.
44 sock_fd = is_any_device ?
45 - socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)) :
46 - socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
47 + socket(PF_PACKET, SOCK_DGRAM, handle->opt.proto) :
48 + socket(PF_PACKET, SOCK_RAW, handle->opt.proto);
51 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
52 @@ -1763,7 +1766,7 @@ activate_new(pcap_t *handle)
55 sock_fd = socket(PF_PACKET, SOCK_DGRAM,
59 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
60 "socket: %s", pcap_strerror(errno));
61 @@ -1815,7 +1818,7 @@ activate_new(pcap_t *handle)
64 if ((err = iface_bind(sock_fd, handle->md.ifindex,
65 - handle->errbuf)) != 1) {
66 + handle->errbuf, handle->opt.proto)) != 1) {
70 @@ -2440,7 +2443,7 @@ iface_get_id(int fd, const char *device,
71 * or a PCAP_ERROR_ value on a hard error.
74 -iface_bind(int fd, int ifindex, char *ebuf)
75 +iface_bind(int fd, int ifindex, char *ebuf, unsigned short proto)
77 struct sockaddr_ll sll;
79 @@ -2449,7 +2452,7 @@ iface_bind(int fd, int ifindex, char *eb
80 memset(&sll, 0, sizeof(sll));
81 sll.sll_family = AF_PACKET;
82 sll.sll_ifindex = ifindex;
83 - sll.sll_protocol = htons(ETH_P_ALL);
84 + sll.sll_protocol = proto;
86 if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) == -1) {
87 if (errno == ENETDOWN) {
88 @@ -3119,7 +3122,7 @@ activate_old(pcap_t *handle)
92 - handle->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
93 + handle->fd = socket(PF_INET, SOCK_PACKET, handle->opt.proto);
94 if (handle->fd == -1) {
95 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
96 "socket: %s", pcap_strerror(errno));
99 @@ -152,6 +152,8 @@ pcap_create_common(const char *source, c
100 pcap_set_snaplen(p, 65535); /* max packet size */
102 p->opt.buffer_size = 0;
108 @@ -212,6 +214,15 @@ pcap_set_buffer_size(pcap_t *p, int buff
112 +pcap_set_protocol(pcap_t *p, unsigned short proto)
114 + if (pcap_check_activated(p))
115 + return PCAP_ERROR_ACTIVATED;
116 + p->opt.proto = proto;
121 pcap_activate(pcap_t *p)
126 @@ -61,6 +61,7 @@ extern "C" {
127 #define PCAP_VERSION_MINOR 4
129 #define PCAP_ERRBUF_SIZE 256
130 +#define HAS_PROTO_EXTENSION
133 * Compatibility for systems that have a bpf.h that
134 @@ -263,6 +264,7 @@ int pcap_can_set_rfmon(pcap_t *);
135 int pcap_set_rfmon(pcap_t *, int);
136 int pcap_set_timeout(pcap_t *, int);
137 int pcap_set_buffer_size(pcap_t *, int);
138 +int pcap_set_protocol(pcap_t *, unsigned short);
139 int pcap_activate(pcap_t *);
141 pcap_t *pcap_open_live(const char *, int, int, int, char *);