2016-12-10 09:56:22 +00:00
|
|
|
This API extension is used by ead (Emergency Access Daemon)
|
|
|
|
|
2010-03-08 14:21:32 +00:00
|
|
|
--- a/pcap-linux.c
|
|
|
|
+++ b/pcap-linux.c
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -425,7 +425,7 @@ static int iface_get_id(int fd, const ch
|
2010-03-08 14:21:32 +00:00
|
|
|
static int iface_get_mtu(int fd, const char *device, char *ebuf);
|
|
|
|
static int iface_get_arptype(int fd, const char *device, char *ebuf);
|
|
|
|
#ifdef HAVE_PF_PACKET_SOCKETS
|
|
|
|
-static int iface_bind(int fd, int ifindex, char *ebuf);
|
|
|
|
+static int iface_bind(int fd, int ifindex, char *ebuf, unsigned short proto);
|
2011-05-24 09:51:08 +00:00
|
|
|
#ifdef IW_MODE_MONITOR
|
2010-03-08 14:21:32 +00:00
|
|
|
static int has_wext(int sock_fd, const char *device, char *ebuf);
|
2011-05-24 09:51:08 +00:00
|
|
|
#endif /* IW_MODE_MONITOR */
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -1059,7 +1059,7 @@ pcap_can_set_rfmon_linux(pcap_t *handle)
|
2010-03-08 14:21:32 +00:00
|
|
|
* (We assume that if we have Wireless Extensions support
|
|
|
|
* we also have PF_PACKET support.)
|
|
|
|
*/
|
|
|
|
- sock_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
|
|
|
+ sock_fd = socket(PF_PACKET, SOCK_RAW, p->opt.proto);
|
|
|
|
if (sock_fd == -1) {
|
2016-12-10 09:56:22 +00:00
|
|
|
(void)pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
2010-03-08 14:21:32 +00:00
|
|
|
"socket: %s", pcap_strerror(errno));
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -1456,6 +1456,9 @@ pcap_activate_linux(pcap_t *handle)
|
2010-03-08 14:21:32 +00:00
|
|
|
handle->read_op = pcap_read_linux;
|
|
|
|
handle->stats_op = pcap_stats_linux;
|
|
|
|
|
|
|
|
+ if (handle->opt.proto < 0)
|
|
|
|
+ handle->opt.proto = (int) htons(ETH_P_ALL);
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* The "any" device is a special device which causes us not
|
|
|
|
* to bind to a particular device and thus to look at all
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -3335,8 +3338,8 @@ activate_new(pcap_t *handle)
|
2010-03-08 14:21:32 +00:00
|
|
|
* try a SOCK_RAW socket for the raw interface.
|
|
|
|
*/
|
|
|
|
sock_fd = is_any_device ?
|
|
|
|
- socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)) :
|
|
|
|
- socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
|
|
|
+ socket(PF_PACKET, SOCK_DGRAM, handle->opt.proto) :
|
|
|
|
+ socket(PF_PACKET, SOCK_RAW, handle->opt.proto);
|
|
|
|
|
|
|
|
if (sock_fd == -1) {
|
2013-04-01 21:07:34 +00:00
|
|
|
if (errno == EINVAL || errno == EAFNOSUPPORT) {
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -3454,7 +3457,7 @@ activate_new(pcap_t *handle)
|
2010-03-08 14:21:32 +00:00
|
|
|
return PCAP_ERROR;
|
|
|
|
}
|
|
|
|
sock_fd = socket(PF_PACKET, SOCK_DGRAM,
|
|
|
|
- htons(ETH_P_ALL));
|
|
|
|
+ handle->opt.proto);
|
|
|
|
if (sock_fd == -1) {
|
2016-12-10 09:56:22 +00:00
|
|
|
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
2010-03-08 14:21:32 +00:00
|
|
|
"socket: %s", pcap_strerror(errno));
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -3518,7 +3521,7 @@ activate_new(pcap_t *handle)
|
2010-03-08 14:21:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 09:54:34 +00:00
|
|
|
if ((err = iface_bind(sock_fd, handlep->ifindex,
|
2010-03-08 14:21:32 +00:00
|
|
|
- handle->errbuf)) != 1) {
|
|
|
|
+ handle->errbuf, handle->opt.proto)) != 1) {
|
|
|
|
close(sock_fd);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -5271,7 +5274,7 @@ iface_get_id(int fd, const char *device,
|
2010-03-08 14:21:32 +00:00
|
|
|
* or a PCAP_ERROR_ value on a hard error.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
-iface_bind(int fd, int ifindex, char *ebuf)
|
|
|
|
+iface_bind(int fd, int ifindex, char *ebuf, unsigned short proto)
|
|
|
|
{
|
|
|
|
struct sockaddr_ll sll;
|
|
|
|
int err;
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -5280,7 +5283,7 @@ iface_bind(int fd, int ifindex, char *eb
|
2010-03-08 14:21:32 +00:00
|
|
|
memset(&sll, 0, sizeof(sll));
|
|
|
|
sll.sll_family = AF_PACKET;
|
|
|
|
sll.sll_ifindex = ifindex;
|
|
|
|
- sll.sll_protocol = htons(ETH_P_ALL);
|
|
|
|
+ sll.sll_protocol = proto;
|
|
|
|
|
|
|
|
if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) == -1) {
|
|
|
|
if (errno == ENETDOWN) {
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -6325,7 +6328,7 @@ activate_old(pcap_t *handle)
|
2010-03-08 14:21:32 +00:00
|
|
|
|
|
|
|
/* Open the socket */
|
|
|
|
|
|
|
|
- handle->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
|
|
|
|
+ handle->fd = socket(PF_INET, SOCK_PACKET, handle->opt.proto);
|
|
|
|
if (handle->fd == -1) {
|
2016-12-10 09:56:22 +00:00
|
|
|
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
2010-03-08 14:21:32 +00:00
|
|
|
"socket: %s", pcap_strerror(errno));
|
|
|
|
--- a/pcap.c
|
|
|
|
+++ b/pcap.c
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -578,6 +578,7 @@ pcap_create_common(char *ebuf, size_t si
|
2010-03-08 14:21:32 +00:00
|
|
|
p->opt.promisc = 0;
|
2014-02-05 09:54:34 +00:00
|
|
|
p->opt.rfmon = 0;
|
|
|
|
p->opt.immediate = 0;
|
2010-03-08 14:21:32 +00:00
|
|
|
+ p->opt.proto = -1;
|
2013-04-01 21:07:34 +00:00
|
|
|
p->opt.tstamp_type = -1; /* default to not setting time stamp type */
|
2014-02-05 09:54:34 +00:00
|
|
|
p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
|
2015-09-03 13:14:56 +00:00
|
|
|
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -771,6 +772,15 @@ pcap_get_tstamp_precision(pcap_t *p)
|
2010-03-08 14:21:32 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 21:07:34 +00:00
|
|
|
int
|
2010-03-08 14:21:32 +00:00
|
|
|
+pcap_set_protocol(pcap_t *p, unsigned short proto)
|
|
|
|
+{
|
|
|
|
+ if (pcap_check_activated(p))
|
|
|
|
+ return PCAP_ERROR_ACTIVATED;
|
|
|
|
+ p->opt.proto = proto;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
2013-04-01 21:07:34 +00:00
|
|
|
+int
|
2010-03-08 14:21:32 +00:00
|
|
|
pcap_activate(pcap_t *p)
|
|
|
|
{
|
2013-04-01 21:07:34 +00:00
|
|
|
int status;
|
2010-03-08 14:21:32 +00:00
|
|
|
--- a/pcap/pcap.h
|
|
|
|
+++ b/pcap/pcap.h
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -68,6 +68,7 @@ extern "C" {
|
2010-03-08 14:21:32 +00:00
|
|
|
#define PCAP_VERSION_MINOR 4
|
|
|
|
|
|
|
|
#define PCAP_ERRBUF_SIZE 256
|
|
|
|
+#define HAS_PROTO_EXTENSION
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compatibility for systems that have a bpf.h that
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -287,6 +288,7 @@ PCAP_API int pcap_set_timeout(pcap_t *,
|
|
|
|
PCAP_API int pcap_set_tstamp_type(pcap_t *, int);
|
|
|
|
PCAP_API int pcap_set_immediate_mode(pcap_t *, int);
|
|
|
|
PCAP_API int pcap_set_buffer_size(pcap_t *, int);
|
|
|
|
+PCAP_API int pcap_set_protocol(pcap_t *, unsigned short);
|
|
|
|
PCAP_API int pcap_set_tstamp_precision(pcap_t *, int);
|
|
|
|
PCAP_API int pcap_get_tstamp_precision(pcap_t *);
|
|
|
|
PCAP_API int pcap_activate(pcap_t *);
|
2014-02-05 09:54:34 +00:00
|
|
|
--- a/pcap-int.h
|
|
|
|
+++ b/pcap-int.h
|
2016-12-10 09:56:22 +00:00
|
|
|
@@ -111,6 +111,7 @@ struct pcap_opt {
|
|
|
|
char *device;
|
2014-02-05 09:54:34 +00:00
|
|
|
int timeout; /* timeout for buffering */
|
2016-12-10 09:56:22 +00:00
|
|
|
u_int buffer_size;
|
|
|
|
+ int proto; /* protocol for packet socket (linux) */
|
2014-02-05 09:54:34 +00:00
|
|
|
int promisc;
|
|
|
|
int rfmon; /* monitor mode */
|
|
|
|
int immediate; /* immediate mode - deliver packets as soon as they arrive */
|