Skip to content

Instantly share code, notes, and snippets.

@ilansmith
Created December 29, 2022 14:20
Show Gist options
  • Select an option

  • Save ilansmith/a41d2106df4b2a1efff56b7870a41458 to your computer and use it in GitHub Desktop.

Select an option

Save ilansmith/a41d2106df4b2a1efff56b7870a41458 to your computer and use it in GitHub Desktop.
List network devices
#include <net/if.h>
#include <stdio.h>
int main(void)
{
struct if_nameindex *if_nidxs, *intf;
if (!(if_nidxs = if_nameindex()))
goto exit;
for (intf = if_nidxs; intf->if_index || intf->if_name; intf++)
printf("%s\n", intf->if_name);
if_freenameindex(if_nidxs);
exit:
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment