Problem with getting networking to work, using ifr_flags
rsn8887 opened this issue · comments
I am not sure if this is really an issue, or if I am just missing something.
The app I am working on currently (OpenTTD port) does this in the networking code:
if (r.ifr_flags & IFF_BROADCAST) continue;
Which according to every page I found about inet and net.h and whatever should be valid.
However, libnx declares ifr_flags as short int[2]:
libnx/nx/external/bsd/include/net/if.h
Line 376 in aee9ba4
but defines IFF_BROADCAST as 0x02. So the check for the flag gives a compile error because I am trying to do a binary and operation on two different types (short int[2] and int).
I have two questions, the second one being the only pressing one atm:
a) Why is ifr_flags declared as short int[2], not short int, like it is done in every linux on the planet?
See e.g. http://man7.org/linux/man-pages/man7/netdevice.7.html
b) How do I fix the code to continue
when the IFF_BROADCAST flag is set? Is it ok to cast like this if ((*((int *)(r.ifr_flags))) & IFF_BROADCAST) continue
? This looks extremely ugly and I suspect it won't do what I want.
I simply don't understand which bit in the array of two shorts I should check for.
Switch's networking stack is based on FreeBSD, not Linux.
By the looks of it ifr_flags[0] should be ifr_flags and ifr_flags[1] should be ifr_flagshigh.
https://github.com/freebsd/freebsd/blob/master/sys/net/if.h#L415-L416
Feel free to test and submit a PR.
Awesome I will test this, thanks!