Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-10-2011, 10:33 AM   #1
tank junior
Registered: Apr 2010
Posts: 42

Rep: Reputation: 0
libpci and get subsystem vendor/device

Using libpci, how do you get subsystem vendor and subsystem device? Here is the default example:
#include <stdio.h>
#include "lib/pci.h"
int main(void)
  struct pci_access *pacc;
  struct pci_dev *dev;
  unsigned int c;
  char namebuf[1024], *name;

  pacc = pci_alloc();		/* Get the pci_access structure */
  /* Set all options you want -- here we stick with the defaults */
  pci_init(pacc);		/* Initialize the PCI library */
  pci_scan_bus(pacc);		/* We want to get the list of devices */
  for (dev=pacc->devices; dev; dev=dev->next)	/* Iterate over all devices */
      pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);	/* Fill in header info we need */
      c = pci_read_byte(dev, PCI_INTERRUPT_PIN);				/* Read config register directly */
      printf("%04x:%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d (pin %d) base0=%lx",
	     dev->domain, dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
	     dev->device_class, dev->irq, c, (long) dev->base_addr[0]);

      /* Look up and print the full name of the device */
      name = pci_lookup_name(pacc, namebuf, sizeof(namebuf), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
      printf(" (%s)\n", name);
  pci_cleanup(pacc);		/* Close everything */
  return 0;
Is it possible to get only ethernet devices instead of all of them?


Old 05-01-2011, 12:21 PM   #2
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
vendor and device ids are right there in the pci_dev struct, and the device_class is used to determine the type:

Just use the code you already have there to walk the device tree and pull out the network devices.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
libpci.a penl Linux - Newbie 1 12-27-2010 05:52 PM
How to apply a vendor ID for USB device on fedora linux alchen1999 Programming 1 01-06-2009 12:43 PM
How to apply a vendor ID for USB device on fedora linux alchen1999 Linux - General 1 01-06-2009 12:41 PM
how do i manually load a device with known vendor and product IDs to devices? pyenos Linux - Hardware 0 03-01-2005 11:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration