Skip to content

Instantly share code, notes, and snippets.

@Gumnos
Created January 5, 2022 12:33
Show Gist options
  • Save Gumnos/e27e657bf5af8e29786cc63d0e5e07e7 to your computer and use it in GitHub Desktop.
Save Gumnos/e27e657bf5af8e29786cc63d0e5e07e7 to your computer and use it in GitHub Desktop.
Given a list of network interfaces, report back which interfaces are missing
#include <stdio.h>
#include <sysexits.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
int
main(int argc, char *argv[]) {
int i;
int result;
if (argc == 1) {
fprintf(stderr, "usage: %s [ifname ...]\n", argv[0]);
fprintf(stderr, "returns 0 if all ifname exist\n"
"or prints each ifname that doesn't exist\n");
return EX_USAGE;
} else {
result = EX_OK;
for (i=1; i < argc; i++)
if (if_nametoindex(argv[i]) == 0) {
printf("%s\n", argv[i]);
result = 1;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment