]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap-can-linux.c
Move platform-dependent pcap_t data out of the pcap_t structure.
[libpcap] / pcap-can-linux.c
index f6a3925ec065cfc4084c741f1c3e9a3a93aaedf5..bee669b03eb26833618bc4d2e5a2df4e4aee26af 100644 (file)
@@ -72,6 +72,13 @@ static int can_setfilter_linux(pcap_t *, struct bpf_program *);
 static int can_setdirection_linux(pcap_t *, pcap_direction_t);
 static int can_stats_linux(pcap_t *, struct pcap_stat *);
 
+/*
+ * Private data for capturing on Linux CANbus devices.
+ */
+struct pcap_can {
+       int ifindex;            /* interface index of device we're bound to */
+};
+
 int
 can_findalldevs(pcap_if_t **devlistp, char *errbuf)
 {
@@ -124,7 +131,7 @@ can_create(const char *device, char *ebuf, int *is_ours)
        /* OK, it's probably ours. */
        *is_ours = 1;
 
-       p = pcap_create_common(device, ebuf);
+       p = pcap_create_common(device, ebuf, sizeof (struct pcap_can));
        if (p == NULL)
                return (NULL);
 
@@ -136,6 +143,7 @@ can_create(const char *device, char *ebuf, int *is_ours)
 static int
 can_activate(pcap_t* handle)
 {
+       struct pcap_can *handlep = handle->private;
        struct sockaddr_can addr;
        struct ifreq ifr;
 
@@ -172,7 +180,7 @@ can_activate(pcap_t* handle)
                pcap_cleanup_live_common(handle);
                return PCAP_ERROR;
        }
-       handle->md.ifindex = ifr.ifr_ifindex;
+       handlep->ifindex = ifr.ifr_ifindex;
 
        /* allocate butter */
        handle->buffer = malloc(handle->bufsize);
@@ -186,11 +194,11 @@ can_activate(pcap_t* handle)
 
        /* Bind to the socket */
        addr.can_family = AF_CAN;
-       addr.can_ifindex = handle->md.ifindex;
+       addr.can_ifindex = handlep->ifindex;
        if( bind( handle->fd, (struct sockaddr*)&addr, sizeof(addr) ) < 0  )
        {
                snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't attach to device %d %d:%s",
-                       handle->md.ifindex, errno, strerror(errno));
+                       handlep->ifindex, errno, strerror(errno));
                pcap_cleanup_live_common(handle);
                return PCAP_ERROR;
        }
@@ -199,7 +207,7 @@ can_activate(pcap_t* handle)
        {
                /* Monitor mode doesn't apply to CAN devices. */
                pcap_cleanup_live_common(handle);
-               return PCAP_ERROR;
+               return PCAP_ERROR_RFMON_NOTSUP;
        }
 
        handle->selectable_fd = handle->fd;