Created
December 29, 2022 14:20
-
-
Save ilansmith/a41d2106df4b2a1efff56b7870a41458 to your computer and use it in GitHub Desktop.
List network devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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