running the following code prints out the ifa_flags value for each interface. Running ifconfig
immediately after will show different FLAGS values for each interface. Why is this? How can I get ifconfig's FLAGS value without parsing a shell command's output?
void printFlags(){
struct ifaddrs *addrs, *nextAddr;
getifaddrs(&addrs);
nextAddr = addrs;
while(nextAddr){
fprintf(stdout, "%s\' FLAGS: %u\n", nextAddr->ifa_name, nextAddr->ifa_flags);
nextAddr = nextAddr->ifa_next;
}
}
The reason they are different is because ifconfig decides to print the flags in hex format. Despite the Kernel passing this value around as an int or a short etc... Whatever... Simple way to see it: fprint("Flags: %x", flags);