Add ioctl(SIOCGIFxxx) support (#197)

- SIOCGIFCONFIG: reads and enumerate all the network interfaces
- SIOCGIFADDR: reads network address for a given interface
- SIOCGIFFLAGS: reads network flags for a given interface
- SIOCGIFNETMASK: reads network netmask for a given interface
- SIOCGIFBRDADDR: reads network broadcast address for a given interface
- SIOCGIFDSTADDR: reads peer destination address for a given
  interface (not supported for Windows)

This change defines Linux ABI structs for the above interfaces and adds
polyfills to ensure they behave consistently on XNU and Windows.
This commit is contained in:
fabriziobertocci 2021-06-24 13:53:27 -04:00 committed by GitHub
parent 4d8f884e76
commit fd0eefce17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 1531 additions and 4 deletions

View file

@ -19,12 +19,19 @@
#include "libc/calls/internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/winsock.h"
#include "libc/nt/iphlpapi.h"
#include "libc/sock/internal.h"
#include "libc/sock/yoink.inc"
#include "libc/sysv/consts/fio.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/sock.h"
/* ioctl(SIOCGIFCONFIG) for Windows need to access the following functions through
* weak reference. This ensure those symbols are not stripped during final link
*/
STATIC_YOINK("GetAdaptersAddresses");
STATIC_YOINK("tprecode16to8");
textwindows int sys_socket_nt(int family, int type, int protocol) {
int64_t h;
struct SockFd *sockfd;
@ -42,6 +49,7 @@ textwindows int sys_socket_nt(int family, int type, int protocol) {
return __winsockerr();
}
}
sockfd = calloc(1, sizeof(struct SockFd));
sockfd->family = family;
sockfd->type = truetype;