summaryrefslogtreecommitdiff
path: root/pcap-usb-linux.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@steve.local>2009-07-11 11:59:04 -0700
committerGuy Harris <gharris@steve.local>2009-07-11 11:59:04 -0700
commit3efa66617444114280a9daa625d910a897867c15 (patch)
treeb1203067ae562e47139c0ea697d085cee74ed583 /pcap-usb-linux.c
parent6f7074d4b01554ff275223c12244d5db9d2be75f (diff)
downloadlibpcap-3efa66617444114280a9daa625d910a897867c15.tar.gz
For Linux, add to the pcap_md structure a pointer to a memory-mapped
region and the size of the region; use that pointer rather than the bp or buffer member (that means we don't have to worry about pcap_cleanup_live_common() attempting to free that buffer). Use the saved size when unmapping the memory-mapped region. Use that for Linux USB memory-mapped access as well - and unmap the memory-mapped region when we close the pcap_t, because we *do* have to unmap it.
Diffstat (limited to 'pcap-usb-linux.c')
-rw-r--r--pcap-usb-linux.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c
index 3d7cb2c5..ab30159e 100644
--- a/pcap-usb-linux.c
+++ b/pcap-usb-linux.c
@@ -201,8 +201,10 @@ int usb_mmap(pcap_t* handle)
if (len < 0)
return 0;
- handle->buffer = mmap(0, len, PROT_READ, MAP_SHARED, handle->fd, 0);
- return handle->buffer != MAP_FAILED;
+ handle->md.mmapbuflen = len;
+ handle->md.mmapbuf = mmap(0, handle->md.mmapbuflen, PROT_READ,
+ MAP_SHARED, handle->fd, 0);
+ return handle->md.mmapbuf != MAP_FAILED;
}
#define CTRL_TIMEOUT (5*1000) /* milliseconds */
@@ -799,7 +801,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
nflush = fetch.nfetch;
for (i=0; i<fetch.nfetch; ++i) {
/* discard filler */
- hdr = (pcap_usb_header*) &handle->buffer[vec[i]];
+ hdr = (pcap_usb_header*) &handle->md.mmapbuf[vec[i]];
if (hdr->event_type == '@')
continue;
@@ -833,8 +835,10 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
static void
usb_cleanup_linux_mmap(pcap_t* handle)
{
- /* buffer must not be freed because it's memory mapped */
- /* XXX - does it need to be unmapped? */
- handle->buffer = NULL;
+ /* if we have a memory-mapped buffer, unmap it */
+ if (handle->md.mmapbuf != NULL) {
+ munmap(handle->md.mmapbuf, handle->md.mmapbuflen);
+ handle->md.mmapbuf = NULL;
+ }
pcap_cleanup_live_common(handle);
}