---
name: "libusb20_be_device_foreach"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/libusb20_be_device_foreach"
---

# libusb20\_be\_device\_foreach(3)

iterate connected USB devices

## NAME

**libusb20\_be\_device\_foreach** – iterate connected USB devices

## SYNOPSIS

library “libusb”

**#include \<libusb20.h\>**

*struct* *libusb20\_device* *\**\

**libusb20\_be\_device\_foreach**(*struct libusb20\_backend \*pbe*, *struct libusb20\_device \*pdev*);

## DESCRIPTION

The **libusb20\_be\_device\_foreach** function iterates connected USB devices, one device at a time. A backend pointer for *pbe* may be obtained by calling [libusb20\_be\_alloc\_default(3)](/libusb20_be_alloc_default/3.md). The starting value of *pdev* is NULL. Calling **libusb20\_be\_device\_foreach** again with *pdev* set to the return value of the previous call yields the next device. To begin interacting with a USB device, pass the pointer in a call to [libusb20\_dev\_open(3)](/libusb20_dev_open/3.md).

## RETURN VALUES

**libusb20\_be\_device\_foreach** returns NULL for end of list. Otherwise this is a pointer to the next device.

## EXAMPLES

```
    #include <libusb20.h>
    struct libusb20_backend *be = libusb20_be_alloc_default(NULL);
    struct libusb20_device *device = NULL;
    while ( (device = libusb20_be_device_foreach(be, device)) != NULL ) {
        if (libusb20_dev_open(device, 0) == LIBUSB20_SUCCESS) {
            /* do something */
            libusb20_dev_close(device);
        }
    }
    libusb20_be_free(be);
```

## SEE ALSO

[libusb20(3)](/libusb20/3.md), [libusb20\_be\_alloc\_default(3)](/libusb20_be_alloc_default/3.md), [libusb20\_be\_free(3)](/libusb20_be_free/3.md), [libusb20\_dev\_open(3)](/libusb20_dev_open/3.md)
