Last active
March 23, 2020 06:37
-
-
Save j1ah0ng/e1a29d0fff3513764b8d6dce0d454b03 to your computer and use it in GitHub Desktop.
quick little program that takes a network interface at argv[1] and gets the Linux interface id
This file contains 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 <errno.h> | |
#include <net/if.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#ifndef NULL | |
#define NULL 0 | |
#endif | |
int main(int argc, char *argv[]) { | |
char *name = (argc < 2) ? "eth0" : argv[1]; | |
unsigned int idx = if_nametoindex(name); | |
if (idx == 0) { | |
printf("Oh no THAT WAS NOT A VALID INTERFACE the world shall end and thus errno was set to %d!\n", errno); | |
} | |
else | |
printf("CONGRATULATIONS you win the lottery for the index of %s was %d.\n", name, idx); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment