[Midnightbsd-cvs] src [10312] trunk/usr.sbin/usbdump/usbdump.c: update usbdump

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jun 3 14:58:35 EDT 2018


Revision: 10312
          http://svnweb.midnightbsd.org/src/?rev=10312
Author:   laffer1
Date:     2018-06-03 14:58:35 -0400 (Sun, 03 Jun 2018)
Log Message:
-----------
update usbdump

Modified Paths:
--------------
    trunk/usr.sbin/usbdump/Makefile
    trunk/usr.sbin/usbdump/usbdump.8
    trunk/usr.sbin/usbdump/usbdump.c

Property Changed:
----------------
    trunk/usr.sbin/usbdump/usbdump.8

Modified: trunk/usr.sbin/usbdump/Makefile
===================================================================
--- trunk/usr.sbin/usbdump/Makefile	2018-06-03 18:58:05 UTC (rev 10311)
+++ trunk/usr.sbin/usbdump/Makefile	2018-06-03 18:58:35 UTC (rev 10312)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/usbdump/Makefile 220316 2011-04-04 03:43:13Z thompsa $
 
 PROG=	usbdump
 SRCS=	usbdump.c

Modified: trunk/usr.sbin/usbdump/usbdump.8
===================================================================
--- trunk/usr.sbin/usbdump/usbdump.8	2018-06-03 18:58:05 UTC (rev 10311)
+++ trunk/usr.sbin/usbdump/usbdump.8	2018-06-03 18:58:35 UTC (rev 10312)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 2010 Weongyo Jeong.
 .\" All rights reserved.
@@ -23,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/usbdump/usbdump.8 234655 2012-04-24 14:06:07Z hselasky $
 .\"
 .Dd April 24, 2012
 .Dt USBDUMP 8


Property changes on: trunk/usr.sbin/usbdump/usbdump.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/usbdump/usbdump.c
===================================================================
--- trunk/usr.sbin/usbdump/usbdump.c	2018-06-03 18:58:05 UTC (rev 10311)
+++ trunk/usr.sbin/usbdump/usbdump.c	2018-06-03 18:58:35 UTC (rev 10312)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 Weongyo Jeong <weongyo at freebsd.org>
  * All rights reserved.
@@ -26,7 +27,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGES.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/usbdump/usbdump.c 267045 2014-06-04 10:33:30Z hselasky $
  */
 
 #include <sys/param.h>
@@ -472,7 +473,6 @@
 	 */
 	up->up_totlen = le32toh(up->up_totlen);
 	up->up_busunit = le32toh(up->up_busunit);
-	up->up_address = le32toh(up->up_address);
 	up->up_flags = le32toh(up->up_flags);
 	up->up_status = le32toh(up->up_status);
 	up->up_error = le32toh(up->up_error);
@@ -795,6 +795,8 @@
 	int o;
 	int filt_unit;
 	int filt_ep;
+	int s;
+	int ifindex;
 	const char *optstring;
 	char *pp;
 
@@ -887,9 +889,20 @@
 	/* clear ifr structure */
 	memset(&ifr, 0, sizeof(ifr));
 
+	/* Try to create usbusN interface if it is not available. */
+	s = socket(AF_LOCAL, SOCK_DGRAM, 0);
+	if (s < 0)
+		errx(EXIT_FAILURE, "Could not open a socket");
+	ifindex = if_nametoindex(i_arg);
+	if (ifindex == 0) {
+		(void)strlcpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name));
+		if (ioctl(s, SIOCIFCREATE2, &ifr) < 0)
+			errx(EXIT_FAILURE, "Invalid bus interface: %s", i_arg);
+	}
+
 	for ( ; v >= USBPF_HDR_LEN; v >>= 1) {
 		(void)ioctl(fd, BIOCSBLEN, (caddr_t)&v);
-		(void)strncpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name));
+		(void)strlcpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name));
 		if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0)
 			break;
 	}
@@ -930,6 +943,17 @@
 	printf("%d packets received by filter\n", us.bs_recv);
 	printf("%d packets dropped by kernel\n", us.bs_drop);
 
+	/*
+	 * Destroy the usbusN interface only if it was created by
+	 * usbdump(8).  Ignore when it was already destroyed.
+	 */
+	if (ifindex == 0 && if_nametoindex(i_arg) > 0) {
+		(void)strlcpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name));
+		if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
+			warn("SIOCIFDESTROY ioctl failed");
+	}
+	close(s);
+
 	if (p->fd > 0)
 		close(p->fd);
 	if (p->rfd > 0)



More information about the Midnightbsd-cvs mailing list