Skip to content

Instantly share code, notes, and snippets.

@aduitsis
Created May 31, 2019 22:48
Show Gist options
  • Save aduitsis/e250baf7bd90d6695eeada20ecd2483f to your computer and use it in GitHub Desktop.
Save aduitsis/e250baf7bd90d6695eeada20ecd2483f to your computer and use it in GitHub Desktop.
Get list of interfaces in FreeBSD, detect which ones are loopbacks
/* compile with cc -o interfaces interfaces.c */
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <net/if.h>
int main() {
struct ifaddrs *ifap;
if( getifaddrs(&ifap) < 0 ) {
perror("getifaddrs returned an error:");
exit(1);
}
while( ifap != NULL ) {
printf("%s %x",ifap->ifa_name,ifap->ifa_flags);
if( ifap->ifa_flags & IFF_LOOPBACK ) printf(" LOOPBACK");
printf("\n");
ifap = ifap->ifa_next;
}
freeifaddrs(ifap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment