As I have been working on trying to reduce files copied from musl, specifically those that use syscall by using the macro approach I described earlier, I have come across 3 files that use syscall but also use socket() call differently than musl.
And I think we have a problem in 2 of those.
< int s = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
---
> int s = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);
because AF_UNIX domain is not supported in OSv (read the commit).
Now 2 other files - if_indextoname.c, if_nametoindex.c - have socket() call that uses AF_UNIX which most likely (we do not have unit tests for these) fails:
socket(AF_UNIX, SOCK_DGRAM, 0))
So I think we should change AF_UNIX to AF_INET in those as well, right?
Also it seems these 2 files were copied from older musl and new musl adds protocol option SOCK_CLOEXEC and there is no reason we should have it different - see this diff between OSv and musl:
DIFF: [/network/if_indextoname.c]
6c6
< #include "syscall.h"
---
> #include "unistd.h"
13c13
< if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
---
> if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return 0;
16c16
< __syscall(SYS_close, fd);
---
> close(fd);
Finally, I think we can solve the socket call changes (AF_UNIX->AF_INET) with --include libc/network/socket_mod.h option where this header looks like so:
#include <sys/socket.h>
#undef socket
#define socket(domain,type,protocol) socket(AF_INET,type,protocol)
We should also enhance existing tests/tst-ifaddrs.cc to test if_indextoname and if_nametoindex.
Waldek