switchbrew / libnx

Library for Switch Homebrew

Home Page:https://switchbrew.github.io/libnx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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]:

short ifr_flags[2]; /* flags (low 16 bits) */

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.

commented

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!

The fix seems simple enough, logical, and it doesn’t seem like the fix could break things anymore as they already are.

But there’s no way I can test this atm at least until issue #250 is solved.