Created
May 31, 2019 22:48
-
-
Save aduitsis/e250baf7bd90d6695eeada20ecd2483f to your computer and use it in GitHub Desktop.
Get list of interfaces in FreeBSD, detect which ones are loopbacks
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
/* 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