I've hit an incredibly odd edge case that I don't quite get the cause of regardi...
Buckwheat :haskell: 🦀 :freebsd: :openbsd: :netbsd: @buckwheat@neondystopia.world
I've hit an incredibly odd edge case that I don't quite get the cause of regarding C compilers (yes, this is for testing solutions for an xmobar plugin). NetBSD is a black sheep in the BSD family in that its default compiler choice is GCC, meanwhile the others use Clang, so I of course tend to default to using Clang as my C compiler. I wrote this C function here, which is... pretty basic:
here is where I get really, really baffled... this compiles under both Clang and GCC, however it only works properly when compiled with GCC. Clang causes the condition of ioctl not working whatsoever. I definitely need to look a little closer at the verbose output, or maybe instead I just need to talk to someone who understands NetBSD better than me to figure out the problem? just, kind of curious to see such a weird compiler edge case.
int
check_state(const char* if_name)
{
struct ifreq* ifr;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
{
printf("Could not create socket\n");
return -1;
}
memset(ifr, 0, sizeof(&ifr));
strncpy(ifr->ifr_name, if_name, IFNAMSIZ);
if (ioctl(sock, SIOCGIFFLAGS, ifr) == -1)
{
printf("Could not get interface flags for %s\n", ifr->ifr_name);
return -1;
}
close(sock);
if (ifr->ifr_flags & IFF_RUNNING)
return 0;
else
return -1;
}here is where I get really, really baffled... this compiles under both Clang and GCC, however it only works properly when compiled with GCC. Clang causes the condition of ioctl not working whatsoever. I definitely need to look a little closer at the verbose output, or maybe instead I just need to talk to someone who understands NetBSD better than me to figure out the problem? just, kind of curious to see such a weird compiler edge case.