mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 17:58:30 +00:00
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:
parent
4d8f884e76
commit
fd0eefce17
105 changed files with 1531 additions and 4 deletions
|
@ -53,6 +53,45 @@ struct sockaddr_un_bsd {
|
|||
char sun_path[108];
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------------
|
||||
* ioctl SIOCGIFCONF & others:
|
||||
*
|
||||
* BSD has a different structure. All the ioctl will adjust to use
|
||||
* the ifreq with the ifreq_bsd
|
||||
*/
|
||||
struct ifreq_bsd {
|
||||
union {
|
||||
char ifrn_name[IFNAMSIZ];
|
||||
} ifr_ifrn;
|
||||
|
||||
union {
|
||||
/* Right now we only list the structures used by the few ioctl that are
|
||||
* supported by Cosmopolitan. Add your own definition here if you need
|
||||
* a particular ioctl that requires polyfill for BSD
|
||||
*/
|
||||
struct sockaddr_bsd ifru_addr;
|
||||
struct sockaddr_bsd ifru_netmask;
|
||||
struct sockaddr_bsd ifru_dstaddr;
|
||||
struct sockaddr_bsd ifru_broadaddr;
|
||||
short ifru_flags;
|
||||
char ifru_pad[16]; /* used as padding */
|
||||
} ifr_ifru;
|
||||
};
|
||||
|
||||
#pragma pack(4)
|
||||
struct ifconf_bsd {
|
||||
uint32_t ifc_len; /* size of buffer */
|
||||
union {
|
||||
char *ifcu_buf;
|
||||
struct ifreq_bsd *ifcu_req;
|
||||
} ifc_ifcu;
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
struct SockFd {
|
||||
int family;
|
||||
int type;
|
||||
|
|
|
@ -85,6 +85,59 @@ struct msghdr { /* Linux+NT ABI */
|
|||
uint32_t msg_flags; /* MSG_XXX */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Structure used in SIOCGIFCONF request.
|
||||
* Used to retrieve interface configuration
|
||||
* for machine (useful for programs which
|
||||
* must know all networks accessible).
|
||||
*/
|
||||
struct ifconf {
|
||||
uint64_t ifc_len; /* size of buffer */
|
||||
union {
|
||||
char *ifcu_buf;
|
||||
struct ifreq *ifcu_req;
|
||||
} ifc_ifcu;
|
||||
};
|
||||
|
||||
|
||||
/* Shortcuts to the ifconf buffer or ifreq array */
|
||||
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
|
||||
#define ifc_req ifc_ifcu.ifcu_req /* array of structures */
|
||||
|
||||
#define IFHWADDRLEN 6
|
||||
#define IF_NAMESIZE 16
|
||||
#define IFNAMSIZ IF_NAMESIZE
|
||||
struct ifreq {
|
||||
union {
|
||||
char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */
|
||||
} ifr_ifrn;
|
||||
|
||||
union {
|
||||
struct sockaddr ifru_addr; /* SIOCGIFADDR */
|
||||
struct sockaddr ifru_dstaddr; /* SIOCGIFDSTADDR */
|
||||
struct sockaddr ifru_netmask; /* SIOCGIFNETMASK */
|
||||
struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
|
||||
short ifru_flags; /* SIOCGIFFLAGS */
|
||||
char ifru_pad[24]; /* ifru_map is the largest, just pad */
|
||||
} ifr_ifru;
|
||||
};
|
||||
|
||||
#define ifr_name ifr_ifrn.ifrn_name /* interface name */
|
||||
#define ifr_addr ifr_ifru.ifru_addr /* address */
|
||||
#define ifr_netmask ifr_ifru.ifru_netmask /* netmask */
|
||||
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
|
||||
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* destination address */
|
||||
#define ifr_flags ifr_ifru.ifru_flags /* flags */
|
||||
|
||||
#define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0)
|
||||
#define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0)
|
||||
#define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0)
|
||||
|
||||
#define IFF_UP (1<<0)
|
||||
|
||||
|
||||
|
||||
const char *inet_ntop(int, const void *, char *, uint32_t);
|
||||
int inet_aton(const char *, struct in_addr *);
|
||||
int inet_pton(int, const char *, void *);
|
||||
|
|
|
@ -33,6 +33,7 @@ LIBC_SOCK_A_DIRECTDEPS = \
|
|||
LIBC_NT_MSWSOCK \
|
||||
LIBC_NT_NTDLL \
|
||||
LIBC_NT_WS2_32 \
|
||||
LIBC_NT_IPHLPAPI \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
// {{{ sys_socketpair_nt
|
||||
textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) {
|
||||
int64_t hpipe, h1, h2;
|
||||
int reader, writer, oflags;
|
||||
|
@ -89,4 +88,3 @@ textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) {
|
|||
sv[1] = writer;
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue