summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libldetect-private.h3
-rw-r--r--lspcidrake.c13
-rw-r--r--usb.c9
3 files changed, 18 insertions, 7 deletions
diff --git a/libldetect-private.h b/libldetect-private.h
index 9addd46..7f6d82b 100644
--- a/libldetect-private.h
+++ b/libldetect-private.h
@@ -3,3 +3,6 @@ extern void pciusb_initialize(struct pciusb_entry *e);
#define MAX_DEVICES 100
#define BUF_SIZE 512
+
+
+extern char *proc_usb_path;
diff --git a/lspcidrake.c b/lspcidrake.c
index fccecb3..ace91e4 100644
--- a/lspcidrake.c
+++ b/lspcidrake.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "libldetect.h"
+#include "libldetect-private.h"
static int verboze = 0;
@@ -14,7 +15,8 @@ static void printit(struct pciusb_entries entries, const char *(find_class)(unsi
else printf("unknown (%04x/%04x/%04x/%04x)", e->vendor, e->device, e->subvendor, e->subdevice);
if (e->class_) {
const char *class_ = find_class(e->class_);
- if (strcmp(class_, "NOT_DEFINED") != 0) printf(" [%s]", class_);
+ if (strcmp(class_, "NOT_DEFINED") != 0)
+ printf(" [%s]", class_);
}
if (verboze && e->text) {
printf(" (vendor:%04x device:%04x", e->vendor, e->device);
@@ -25,7 +27,6 @@ static void printit(struct pciusb_entries entries, const char *(find_class)(unsi
printf("\n");
}
pciusb_free(&entries);
-
}
@@ -35,7 +36,11 @@ int main(int argc, char **argv) {
while (ptr && *ptr) {
if (!strcmp(*ptr, "-h") || !strcmp(*ptr, "--help")) {
- printf("usage: lspcidrake [-v] [-f]\n");
+ printf("usage: lspcidrake [-v|-f|-u]\n"
+ "-f : full probe\n"
+ "-u : usb devices source [/proc/usb/devices by default\n"
+ "-v : verbose mode [print ids and sub-ids], implies full probe\n"
+ );
return 0;
}
if (!strcmp(*ptr, "-v")) {
@@ -44,6 +49,8 @@ int main(int argc, char **argv) {
}
if (!strcmp(*ptr, "-f"))
full_probe = 1;
+ if (!strcmp(*ptr, "-u"))
+ proc_usb_path = *++ptr;
ptr++;
}
diff --git a/usb.c b/usb.c
index 5982d44..cbeea25 100644
--- a/usb.c
+++ b/usb.c
@@ -5,17 +5,18 @@
#include "libldetect-private.h"
#include "common.h"
+char *proc_usb_path = "/proc/bus/usb/devices";
+
extern struct pciusb_entries usb_probe(void) {
FILE *f;
char buf[BUF_SIZE];
int line;
- const char *file = "/proc/bus/usb/devices";
struct pciusb_entry t[MAX_DEVICES];
struct pciusb_entries r;
struct pciusb_entry *e = NULL;
- if (!(f = fopen(file, "r")))
+ if (!(f = fopen(proc_usb_path, "r")))
exit(1);
for(r.nb = line = 0; fgets(buf, sizeof(buf) - 1, f) && r.nb < psizeof(t); line++) {
@@ -24,7 +25,7 @@ extern struct pciusb_entries usb_probe(void) {
pciusb_initialize(e);
if (sscanf(buf, "P: Vendor=%hx ProdID=%hx", &e->vendor, &e->device) != 2) {
- fprintf(stderr, "%s %d: unknown ``P'' line\n", file, line);
+ fprintf(stderr, "%s %d: unknown ``P'' line\n", proc_usb_path, line);
pciusb_initialize(e);
}
} else if (e && buf[0] == 'I' && e->class_ == 0) {
@@ -32,7 +33,7 @@ extern struct pciusb_entries usb_probe(void) {
if (sscanf(buf, "I: If#=%*2d Alt=%*2d #EPs=%*2d Cls=%02x(%*5c) Sub=%02x Prot=%02x", &class_, &sub, &prot) == 3) {
e->class_ = (class_ * 0x100 + sub) * 0x100 + prot;
} else {
- fprintf(stderr, "%s %d: unknown ``I'' line\n", file, line);
+ fprintf(stderr, "%s %d: unknown ``I'' line\n", proc_usb_path, line);
}
} else if (e && buf[0] == 'S') {
int offset;