add netbsd nl(1)
[rofl0r-hardcore-utils.git] / usbreset.c
blob532ebb208c0c00831df3945c647f5d74c9c62b6c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <fcntl.h>
4 #include <errno.h>
5 #include <sys/ioctl.h>
7 #include <linux/usbdevice_fs.h>
9 int main(int argc, char **argv) {
10 int fd, err=0;
11 if (argc != 2) {
12 printf("usbreset - send a port reset to an USB device\n"
13 "this should be equivalent to physically unplugging and replugging a device\n\n"
14 "usage: usbreset /dev/bus/usb/busid/deviceid\n"
15 "e.g. usbreset /dev/bus/usb/002/001\n"
16 "(see lsusb output for bus id and device id)\n");
17 return 1;
19 if((fd = open(argv[1], O_WRONLY)) == -1) {;
20 perror("open");
21 return 1;
24 printf("resetting USB device %s\n", argv[1]);
26 if(ioctl(fd, USBDEVFS_RESET, 0) == -1) {
27 perror("ioctl");
28 err = 1;
29 } else printf("reset successful\n");
31 close(fd);
32 return err;