title: How to get the USB VID, PID and serial number of a device in Ubuntu using C++ from /dev/xxx path
body: <p>When USB cameras are plugged into Linux a device appears in the /dev folder.  For example, the first camera will appear as video0.  In the system we’re building, with multiple cameras, we get video0, video1 and video2.  </p>
  
  <p>My requirement is to to programmatically read a USB camera’s VendorID (VID), ProductID (PID) and serial number using C++.</p>
  
  <p>Currently, we use UDEV rules to map a specific device to something like /dev/camera_one; but we'd like to programmatically read the serial number and check that the device has not been changed.  </p>
  
  <p>We can enumerate all USB devices using the libudev, so we know we can get the information from libudev ( <a href="https://github.com/gavv/snippets/blob/master/udev/udev_monitor_usb.c" rel="nofollow noreferrer">https://github.com/gavv/snippets/blob/master/udev/udev_monitor_usb.c</a> )</p>
  
  <p>But how can we use libudev to extract the required VID, PID and serial number given the /dev/videoN path.</p>