svn commit: r215267 - user/weongyo/usb/usb.sbin/usbdump

Weongyo Jeong weongyo at FreeBSD.org
Sat Nov 13 22:18:12 UTC 2010


Author: weongyo
Date: Sat Nov 13 22:18:12 2010
New Revision: 215267
URL: http://svn.freebsd.org/changeset/base/215267

Log:
  usbdump(8) now handles endians correctly.

Modified:
  user/weongyo/usb/usb.sbin/usbdump/usbdump.c

Modified: user/weongyo/usb/usb.sbin/usbdump/usbdump.c
==============================================================================
--- user/weongyo/usb/usb.sbin/usbdump/usbdump.c	Sat Nov 13 22:10:26 2010	(r215266)
+++ user/weongyo/usb/usb.sbin/usbdump/usbdump.c	Sat Nov 13 22:18:12 2010	(r215267)
@@ -256,6 +256,15 @@ print_apacket(const struct usbpf_xhdr *h
 	const char *ptr = payload;
 	char buf[64];
 
+	/* A packet from the kernel is based on little endian byte order. */
+	up->up_busunit = le32toh(up->up_busunit);
+	up->up_flags = le32toh(up->up_flags);
+	up->up_status = le32toh(up->up_status);
+	up->up_length = le32toh(up->up_length);
+	up->up_frames = le32toh(up->up_frames);
+	up->up_error = le32toh(up->up_error);
+	up->up_interval = le32toh(up->up_interval);
+
 	tv.tv_sec = hdr->uh_tstamp.ut_sec;
 	tv.tv_usec = hdr->uh_tstamp.ut_frac;
 	tm = localtime(&tv.tv_sec);
@@ -275,7 +284,7 @@ print_apacket(const struct usbpf_xhdr *h
 
 	if (verbose >= 1) {
 		for (x = 0; x < up->up_frames; x++) {
-			framelen = *((const u_int32_t *)ptr);
+			framelen = le32toh(*((const u_int32_t *)ptr));
 			ptr += sizeof(u_int32_t);
 			printf(" frame[%u] len %d\n", x, framelen);
 			assert(framelen < (1024 * 4));
@@ -308,7 +317,7 @@ print_packets(const char *data, const in
 			print_apacket(hdr, up, ptr);
 		pkt_captured++;
 		for (x = 0; x < up->up_frames; x++) {
-			framelen = *((const u_int32_t *)ptr);
+			framelen = le32toh(*((const u_int32_t *)ptr));
 			ptr += sizeof(u_int32_t) + framelen;
 		}
 	}


More information about the svn-src-user mailing list