aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-usb-linux.c
diff options
context:
space:
mode:
authorguy <guy>2006-10-05 16:22:52 +0000
committerguy <guy>2006-10-05 16:22:52 +0000
commit748adf9a88325f0444bf782f78366533e38605d3 (patch)
treee3a7971c820ca444c24954612f86c9000b3e5001 /pcap-usb-linux.c
parentef32ac1186563fbaba91a150d5ab3973b02cd5bd (diff)
From Paolo Abeni - fix a couple of problems:
- the snaplen parameter is just ignored. - the raw data received from usb port is partially corrupted.
Diffstat (limited to 'pcap-usb-linux.c')
-rw-r--r--pcap-usb-linux.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c
index 95b7432..99dba90 100644
--- a/pcap-usb-linux.c
+++ b/pcap-usb-linux.c
@@ -181,7 +181,7 @@ usb_open_live(const char* bus, int snaplen, int promisc , int to_ms, char* errms
static inline int
ascii_to_int(char c)
{
- return c < 'A' ? c- '0': ((c<'a') ? c- 'A': c-'a');
+ return c < 'A' ? c- '0': ((c<'a') ? c - 'A' + 10: c-'a'+10);
}
/*
@@ -331,12 +331,13 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
string += cnt;
handle->md.packets_read++;
- /* urb tag is not present if urb length is 0 */
- pkth.len += pkth.caplen;
+ /* urb tag is not present if urb length is 0, so we can stop here
+ * text parsing */
+ pkth.len += pkth.caplen;
if (pkth.len == pkth.caplen)
return 1;
- /* check for data presence */
+ /* check for data presence; data is present if and only if urb tag is '=' */
if (sscanf(string, " %c", &urb_tag) != 1)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
@@ -347,9 +348,12 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
if (urb_tag != '=')
goto got;
- /* read all urb data; if urb length is less then our string we get only
- * a partial information */
- while ((string[0] != 0) && (string[1] != 0))
+ /* read all urb data; if urb length is greater then the usbmon internal
+ * buffer length used by the kernel to spool the URB, we get only
+ * a partial information.
+ * At least until linux 2.6.17 there is no way to set usbmon intenal buffer
+ * length and default value is 130. */
+ while ((string[0] != 0) && (string[1] != 0) && (pkth.caplen < handle->snaplen))
{
rawdata[0] = ascii_to_int(string[0]) * 16 + ascii_to_int(string[1]);
rawdata++;