GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — libusb/examples/listdevs.c at master · Raghuvardhan-Reddy78/libusb

Expand file tree

/

listdevs.c

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
137 lines (119 loc) · 3.76 KB
/

listdevs.c

Copy path

File metadata and controls

137 lines (119 loc) · 3.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:4 -*- */
/*
* libusb example program to list devices on the bus
* Copyright © 2007 Daniel Drake <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <string.h>
#include "libusb.h"
static void print_devs(libusb_device **devs, int verbose)
{
libusb_device *dev;
int i = 0, j = 0;
uint8_t path[8];
char string_buffer[LIBUSB_DEVICE_STRING_BYTES_MAX];
while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
fprintf(stderr, "failed to get device descriptor");
return;
}
printf("%04x:%04x (bus %d, device %d)",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev), libusb_get_device_address(dev));
r = libusb_get_port_numbers(dev, path, sizeof(path));
if (r > 0) {
printf(" path: %d", path[0]);
for (j = 1; j < r; j++)
printf(".%d", path[j]);
}
if (verbose) {
r = libusb_get_device_string(dev, LIBUSB_DEVICE_STRING_MANUFACTURER,
string_buffer, sizeof(string_buffer));
if (r >= 0) {
printf("\n manufacturer = %s", string_buffer);
}
r = libusb_get_device_string(dev, LIBUSB_DEVICE_STRING_PRODUCT,
string_buffer, sizeof(string_buffer));
if (r >= 0) {
printf("\n product = %s", string_buffer);
}
r = libusb_get_device_string(dev, LIBUSB_DEVICE_STRING_SERIAL_NUMBER,
string_buffer, sizeof(string_buffer));
if (r >= 0) {
printf("\n serial_number = %s", string_buffer);
}
r = libusb_get_config_string(dev, /*config_value=*/0,
string_buffer, sizeof(string_buffer));
if (r >= 0) {
printf("\n configuration = %s", string_buffer);
}
struct libusb_config_descriptor *config;
if (libusb_get_active_config_descriptor(dev, &config) == 0) {
int ifc;
for (ifc = 0; ifc < config->bNumInterfaces; ifc++) {
const struct libusb_interface_descriptor *altsetting =
&config->interface[ifc].altsetting[0];
r = libusb_get_interface_string(dev, /*config_value=*/0,
altsetting->bInterfaceNumber, altsetting->bAlternateSetting,
string_buffer, sizeof(string_buffer));
if (r >= 0) {
printf("\n interface %u = %s",
altsetting->bInterfaceNumber, string_buffer);
}
}
libusb_free_config_descriptor(config);
}
}
printf("\n");
}
}
static int usage(void) {
printf("usage: listdevs [--verbose]\n");
return 1;
}
int main(int argc, const char *argv[])
{
int verbose = 0;
libusb_device **devs;
int r;
ssize_t cnt;
--argc; ++argv; /* consume argument */
while (argc) {
if ((0 == strcmp("-v", argv[0])) || (0 == strcmp("--verbose", argv[0]))) {
++verbose;
--argc; ++argv; /* consume argument */
} else {
return usage();
}
}
r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
if (r < 0)
return r;
cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0){
libusb_exit(NULL);
return (int) cnt;
}
print_devs(devs, verbose);
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
return 0;
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.