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

42
libc/nt/iphlpapi.h Normal file
View file

@ -0,0 +1,42 @@
#ifndef COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
#define COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
#include "libc/nt/struct/ipadapteraddresses.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* ░░░░
cosmopolitan § new technology » ip helper API
*/
uint32_t GetAdaptersAddresses(
uint32_t Family,
uint32_t Flags,
void * Reserved,
NtIpAdapterAddresses *AdapterAddresses,
uint32_t *SizePointer);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_ */

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_AddIPAddress,AddIPAddress,0
.text.windows
AddIPAddress:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_AddIPAddress(%rip),%rax
jmp __sysv2nt6
.endfn AddIPAddress,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_AllocateAndGetTcpExTableFromStack,AllocateAndGetTcpExTableFromStack,0
.text.windows
AllocateAndGetTcpExTableFromStack:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_AllocateAndGetTcpExTableFromStack(%rip),%rax
jmp __sysv2nt6
.endfn AllocateAndGetTcpExTableFromStack,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_AllocateAndGetUdpExTableFromStack,AllocateAndGetUdpExTableFromStack,0
.text.windows
AllocateAndGetUdpExTableFromStack:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_AllocateAndGetUdpExTableFromStack(%rip),%rax
jmp __sysv2nt6
.endfn AllocateAndGetUdpExTableFromStack,globl
.previous

View file

@ -0,0 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CancelIPChangeNotify,CancelIPChangeNotify,0
.text.windows
CancelIPChangeNotify:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_CancelIPChangeNotify(%rip)
leave
ret
.endfn CancelIPChangeNotify,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CaptureInterfaceHardwareCrossTimestamp,CaptureInterfaceHardwareCrossTimestamp,0
.text.windows
CaptureInterfaceHardwareCrossTimestamp:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_CaptureInterfaceHardwareCrossTimestamp(%rip),%rax
jmp __sysv2nt
.endfn CaptureInterfaceHardwareCrossTimestamp,globl
.previous

View file

@ -0,0 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CreateIpForwardEntry,CreateIpForwardEntry,0
.text.windows
CreateIpForwardEntry:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_CreateIpForwardEntry(%rip)
leave
ret
.endfn CreateIpForwardEntry,globl
.previous

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CreateIpNetEntry,CreateIpNetEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CreatePersistentTcpPortReservation,CreatePersistentTcpPortReservation,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CreatePersistentUdpPortReservation,CreatePersistentUdpPortReservation,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_CreateProxyArpEntry,CreateProxyArpEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DeleteIPAddress,DeleteIPAddress,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DeleteIpForwardEntry,DeleteIpForwardEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DeleteIpNetEntry,DeleteIpNetEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DeletePersistentTcpPortReservation,DeletePersistentTcpPortReservation,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DeletePersistentUdpPortReservation,DeletePersistentUdpPortReservation,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DeleteProxyArpEntry,DeleteProxyArpEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_DisableMediaSense,DisableMediaSense,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_EnableRouter,EnableRouter,0

View file

@ -0,0 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_FlushIpNetTable,FlushIpNetTable,0
.text.windows
FlushIpNetTable:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_FlushIpNetTable(%rip)
leave
ret
.endfn FlushIpNetTable,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetAdapterIndex,GetAdapterIndex,0
.text.windows
GetAdapterIndex:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetAdapterIndex(%rip),%rax
jmp __sysv2nt
.endfn GetAdapterIndex,globl
.previous

View file

@ -0,0 +1,14 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetAdapterOrderMap,GetAdapterOrderMap,0
.text.windows
GetAdapterOrderMap:
push %rbp
mov %rsp,%rbp
.profilable
sub $32,%rsp
call *__imp_GetAdapterOrderMap(%rip)
leave
ret
.endfn GetAdapterOrderMap,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetAdaptersAddresses,GetAdaptersAddresses,67
.text.windows
GetAdaptersAddresses:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetAdaptersAddresses(%rip),%rax
jmp __sysv2nt6
.endfn GetAdaptersAddresses,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetAdaptersInfo,GetAdaptersInfo,0
.text.windows
GetAdaptersInfo:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetAdaptersInfo(%rip),%rax
jmp __sysv2nt
.endfn GetAdaptersInfo,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetBestInterface,GetBestInterface,0
.text.windows
GetBestInterface:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetBestInterface(%rip),%rax
jmp __sysv2nt
.endfn GetBestInterface,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetBestInterfaceEx,GetBestInterfaceEx,0
.text.windows
GetBestInterfaceEx:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetBestInterfaceEx(%rip),%rax
jmp __sysv2nt
.endfn GetBestInterfaceEx,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetBestRoute,GetBestRoute,0
.text.windows
GetBestRoute:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetBestRoute(%rip),%rax
jmp __sysv2nt
.endfn GetBestRoute,globl
.previous

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetExtendedTcpTable,GetExtendedTcpTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetExtendedUdpTable,GetExtendedUdpTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetFriendlyIfIndex,GetFriendlyIfIndex,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIcmpStatistics,GetIcmpStatistics,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIcmpStatisticsEx,GetIcmpStatisticsEx,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIfEntry,GetIfEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIfTable,GetIfTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetInterfaceActiveTimestampCapabilities,GetInterfaceActiveTimestampCapabilities,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetInterfaceInfo,GetInterfaceInfo,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetInterfaceSupportedTimestampCapabilities,GetInterfaceSupportedTimestampCapabilities,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIpAddrTable,GetIpAddrTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIpErrorString,GetIpErrorString,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIpForwardTable,GetIpForwardTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIpNetTable,GetIpNetTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIpStatistics,GetIpStatistics,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetIpStatisticsEx,GetIpStatisticsEx,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetNetworkParams,GetNetworkParams,0

View file

@ -0,0 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetNumberOfInterfaces,GetNumberOfInterfaces,0
.text.windows
GetNumberOfInterfaces:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_GetNumberOfInterfaces(%rip)
leave
ret
.endfn GetNumberOfInterfaces,globl
.previous

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetOwnerModuleFromTcp6Entry,GetOwnerModuleFromTcp6Entry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetOwnerModuleFromTcpEntry,GetOwnerModuleFromTcpEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetOwnerModuleFromUdp6Entry,GetOwnerModuleFromUdp6Entry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetOwnerModuleFromUdpEntry,GetOwnerModuleFromUdpEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetPerAdapterInfo,GetPerAdapterInfo,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetPerTcp6ConnectionEStats,GetPerTcp6ConnectionEStats,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetPerTcpConnectionEStats,GetPerTcpConnectionEStats,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetRTTAndHopCount,GetRTTAndHopCount,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcp6Table,GetTcp6Table,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcp6Table2,GetTcp6Table2,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcpStatistics,GetTcpStatistics,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcpStatisticsEx,GetTcpStatisticsEx,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcpStatisticsEx2,GetTcpStatisticsEx2,0

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcpTable,GetTcpTable,0
.text.windows
GetTcpTable:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetTcpTable(%rip),%rax
jmp __sysv2nt
.endfn GetTcpTable,globl
.previous

View file

@ -0,0 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetTcpTable2,GetTcpTable2,0
.text.windows
GetTcpTable2:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetTcpTable2(%rip),%rax
jmp __sysv2nt
.endfn GetTcpTable2,globl
.previous

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetUdp6Table,GetUdp6Table,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetUdpStatistics,GetUdpStatistics,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetUdpStatisticsEx,GetUdpStatisticsEx,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetUdpStatisticsEx2,GetUdpStatisticsEx2,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetUdpTable,GetUdpTable,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_GetUniDirectionalAdapterInfo,GetUniDirectionalAdapterInfo,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_IpReleaseAddress,IpReleaseAddress,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_IpRenewAddress,IpRenewAddress,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_LookupPersistentTcpPortReservation,LookupPersistentTcpPortReservation,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_LookupPersistentUdpPortReservation,LookupPersistentUdpPortReservation,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_NhpAllocateAndGetInterfaceInfoFromStack,NhpAllocateAndGetInterfaceInfoFromStack,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_NotifyAddrChange,NotifyAddrChange,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_NotifyRouteChange,NotifyRouteChange,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_ParseNetworkString,ParseNetworkString,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_RegisterInterfaceTimestampConfigChange,RegisterInterfaceTimestampConfigChange,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_ResolveNeighbor,ResolveNeighbor,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_RestoreMediaSense,RestoreMediaSense,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SendARP,SendARP,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetIfEntry,SetIfEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetIpForwardEntry,SetIpForwardEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetIpNetEntry,SetIpNetEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetIpStatistics,SetIpStatistics,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetIpStatisticsEx,SetIpStatisticsEx,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetIpTTL,SetIpTTL,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetPerTcp6ConnectionEStats,SetPerTcp6ConnectionEStats,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetPerTcpConnectionEStats,SetPerTcpConnectionEStats,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_SetTcpEntry,SetTcpEntry,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_UnenableRouter,UnenableRouter,0

View file

@ -0,0 +1,2 @@
.include "o/libc/nt/codegen.inc"
.imp iphlpapi,__imp_UnregisterInterfaceTimestampConfigChange,UnregisterInterfaceTimestampConfigChange,0

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp kernel32,__imp_WideCharToMultiByte,WideCharToMultiByte,0
.imp kernel32,__imp_WideCharToMultiByte,WideCharToMultiByte,1553
.text.windows
WideCharToMultiByte:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_WideCharToMultiByte(%rip),%rax
jmp __sysv2nt8
.endfn WideCharToMultiByte,globl
.previous

View file

@ -7093,7 +7093,7 @@ imp 'WerpNotifyLoadStringResource' WerpNotifyLoadStringResource KernelBase
imp 'WerpNotifyLoadStringResourceWorker' WerpNotifyLoadStringResourceWorker kernel32 1540
imp 'WerpNotifyUseStringResource' WerpNotifyUseStringResource KernelBase 1809
imp 'WerpNotifyUseStringResourceWorker' WerpNotifyUseStringResourceWorker kernel32 1541
imp 'WideCharToMultiByte' WideCharToMultiByte kernel32 0 # KernelBase
imp 'WideCharToMultiByte' WideCharToMultiByte kernel32 1553 8
imp 'WidenPath' WidenPath gdi32 1941
imp 'Win32DeleteFile' Win32DeleteFile shell32 164
imp 'WinExec' WinExec kernel32 1543
@ -7797,3 +7797,92 @@ imp 'ReleaseSRWLockExclusive' ReleaseSRWLockExclusive kernel32 0 1 # Kern
imp 'ReleaseSRWLockShared' ReleaseSRWLockShared kernel32 0 1 # KernelBase
imp 'TryAcquireSRWLockExclusive' TryAcquireSRWLockExclusive kernel32 0 1 # KernelBase
imp 'TryAcquireSRWLockShared' TryAcquireSRWLockShared kernel32 0 1 # KernelBase
imp 'AddIPAddress' AddIPAddress iphlpapi 0 5
imp 'AllocateAndGetTcpExTableFromStack' AllocateAndGetTcpExTableFromStack iphlpapi 0 5
imp 'AllocateAndGetUdpExTableFromStack' AllocateAndGetUdpExTableFromStack iphlpapi 0 5
imp 'CancelIPChangeNotify' CancelIPChangeNotify iphlpapi 0 1
imp 'CaptureInterfaceHardwareCrossTimestamp' CaptureInterfaceHardwareCrossTimestamp iphlpapi 0 2
imp 'CreateIpForwardEntry' CreateIpForwardEntry iphlpapi 0 1
imp 'CreateIpNetEntry' CreateIpNetEntry iphlpapi 0
imp 'CreatePersistentTcpPortReservation' CreatePersistentTcpPortReservation iphlpapi 0
imp 'CreatePersistentUdpPortReservation' CreatePersistentUdpPortReservation iphlpapi 0
imp 'CreateProxyArpEntry' CreateProxyArpEntry iphlpapi 0
imp 'DeleteIPAddress' DeleteIPAddress iphlpapi 0
imp 'DeleteIpForwardEntry' DeleteIpForwardEntry iphlpapi 0
imp 'DeleteIpNetEntry' DeleteIpNetEntry iphlpapi 0
imp 'DeletePersistentTcpPortReservation' DeletePersistentTcpPortReservation iphlpapi 0
imp 'DeletePersistentUdpPortReservation' DeletePersistentUdpPortReservation iphlpapi 0
imp 'DeleteProxyArpEntry' DeleteProxyArpEntry iphlpapi 0
imp 'DisableMediaSense' DisableMediaSense iphlpapi 0
imp 'EnableRouter' EnableRouter iphlpapi 0
imp 'FlushIpNetTable' FlushIpNetTable iphlpapi 0 1
imp 'GetAdapterIndex' GetAdapterIndex iphlpapi 0 2
imp 'GetAdapterOrderMap' GetAdapterOrderMap iphlpapi 0 0
imp 'GetAdaptersAddresses' GetAdaptersAddresses iphlpapi 67 5
imp 'GetAdaptersInfo' GetAdaptersInfo iphlpapi 0 2
imp 'GetBestInterface' GetBestInterface iphlpapi 0 2
imp 'GetBestInterfaceEx' GetBestInterfaceEx iphlpapi 0 2
imp 'GetBestRoute' GetBestRoute iphlpapi 0 3
imp 'GetExtendedTcpTable' GetExtendedTcpTable iphlpapi 0
imp 'GetExtendedUdpTable' GetExtendedUdpTable iphlpapi 0
imp 'GetFriendlyIfIndex' GetFriendlyIfIndex iphlpapi 0
imp 'GetIcmpStatistics' GetIcmpStatistics iphlpapi 0
imp 'GetIcmpStatisticsEx' GetIcmpStatisticsEx iphlpapi 0
imp 'GetIfEntry' GetIfEntry iphlpapi 0
imp 'GetIfTable' GetIfTable iphlpapi 0
imp 'GetInterfaceActiveTimestampCapabilities' GetInterfaceActiveTimestampCapabilities iphlpapi 0
imp 'GetInterfaceInfo' GetInterfaceInfo iphlpapi 0
imp 'GetInterfaceSupportedTimestampCapabilities' GetInterfaceSupportedTimestampCapabilities iphlpapi 0
imp 'GetIpAddrTable' GetIpAddrTable iphlpapi 0
imp 'GetIpErrorString' GetIpErrorString iphlpapi 0
imp 'GetIpForwardTable' GetIpForwardTable iphlpapi 0
imp 'GetIpNetTable' GetIpNetTable iphlpapi 0
imp 'GetIpStatistics' GetIpStatistics iphlpapi 0
imp 'GetIpStatisticsEx' GetIpStatisticsEx iphlpapi 0
imp 'GetNetworkParams' GetNetworkParams iphlpapi 0
imp 'GetNumberOfInterfaces' GetNumberOfInterfaces iphlpapi 0 1
imp 'GetOwnerModuleFromTcp6Entry' GetOwnerModuleFromTcp6Entry iphlpapi 0
imp 'GetOwnerModuleFromTcpEntry' GetOwnerModuleFromTcpEntry iphlpapi 0
imp 'GetOwnerModuleFromUdp6Entry' GetOwnerModuleFromUdp6Entry iphlpapi 0
imp 'GetOwnerModuleFromUdpEntry' GetOwnerModuleFromUdpEntry iphlpapi 0
imp 'GetPerAdapterInfo' GetPerAdapterInfo iphlpapi 0
imp 'GetPerTcp6ConnectionEStats' GetPerTcp6ConnectionEStats iphlpapi 0
imp 'GetPerTcpConnectionEStats' GetPerTcpConnectionEStats iphlpapi 0
imp 'GetRTTAndHopCount' GetRTTAndHopCount iphlpapi 0
imp 'GetTcp6Table' GetTcp6Table iphlpapi 0
imp 'GetTcp6Table2' GetTcp6Table2 iphlpapi 0
imp 'GetTcpStatistics' GetTcpStatistics iphlpapi 0
imp 'GetTcpStatisticsEx' GetTcpStatisticsEx iphlpapi 0
imp 'GetTcpStatisticsEx2' GetTcpStatisticsEx2 iphlpapi 0
imp 'GetTcpTable' GetTcpTable iphlpapi 0 3
imp 'GetTcpTable2' GetTcpTable2 iphlpapi 0 3
imp 'GetUdp6Table' GetUdp6Table iphlpapi 0
imp 'GetUdpStatistics' GetUdpStatistics iphlpapi 0
imp 'GetUdpStatisticsEx' GetUdpStatisticsEx iphlpapi 0
imp 'GetUdpStatisticsEx2' GetUdpStatisticsEx2 iphlpapi 0
imp 'GetUdpTable' GetUdpTable iphlpapi 0
imp 'GetUniDirectionalAdapterInfo' GetUniDirectionalAdapterInfo iphlpapi 0
imp 'IpReleaseAddress' IpReleaseAddress iphlpapi 0
imp 'IpRenewAddress' IpRenewAddress iphlpapi 0
imp 'LookupPersistentTcpPortReservation' LookupPersistentTcpPortReservation iphlpapi 0
imp 'LookupPersistentUdpPortReservation' LookupPersistentUdpPortReservation iphlpapi 0
imp 'NhpAllocateAndGetInterfaceInfoFromStack' NhpAllocateAndGetInterfaceInfoFromStack iphlpapi 0
imp 'NotifyAddrChange' NotifyAddrChange iphlpapi 0
imp 'NotifyRouteChange' NotifyRouteChange iphlpapi 0
imp 'ParseNetworkString' ParseNetworkString iphlpapi 0
imp 'RegisterInterfaceTimestampConfigChange' RegisterInterfaceTimestampConfigChange iphlpapi 0
imp 'ResolveNeighbor' ResolveNeighbor iphlpapi 0
imp 'RestoreMediaSense' RestoreMediaSense iphlpapi 0
imp 'SendARP' SendARP iphlpapi 0
imp 'SetIfEntry' SetIfEntry iphlpapi 0
imp 'SetIpForwardEntry' SetIpForwardEntry iphlpapi 0
imp 'SetIpNetEntry' SetIpNetEntry iphlpapi 0
imp 'SetIpStatistics' SetIpStatistics iphlpapi 0
imp 'SetIpStatisticsEx' SetIpStatisticsEx iphlpapi 0
imp 'SetIpTTL' SetIpTTL iphlpapi 0
imp 'SetPerTcp6ConnectionEStats' SetPerTcp6ConnectionEStats iphlpapi 0
imp 'SetPerTcpConnectionEStats' SetPerTcpConnectionEStats iphlpapi 0
imp 'SetTcpEntry' SetTcpEntry iphlpapi 0
imp 'UnenableRouter' UnenableRouter iphlpapi 0
imp 'UnregisterInterfaceTimestampConfigChange' UnregisterInterfaceTimestampConfigChange iphlpapi 0

View file

@ -252,6 +252,27 @@ $(LIBC_NT_WS2_32_A).pkg: \
#───────────────────────────────────────────────────────────────────────────────
LIBC_NT_ARTIFACTS += LIBC_NT_IPHLPAPI_A
LIBC_NT_IPHLPAPI = $(LIBC_NT_IPHLPAPI_A_DEPS) $(LIBC_NT_IPHLPAPI_A)
LIBC_NT_IPHLPAPI_A = o/$(MODE)/libc/nt/iphlpapi.a
LIBC_NT_IPHLPAPI_A_SRCS := $(wildcard libc/nt/iphlpapi/*.s)
LIBC_NT_IPHLPAPI_A_OBJS = $(LIBC_NT_IPHLPAPI_A_SRCS:%.s=o/$(MODE)/%.o)
LIBC_NT_IPHLPAPI_A_CHECKS = $(LIBC_IPHLPAPI_32_A).pkg
LIBC_NT_IPHLPAPI_A_DIRECTDEPS = LIBC_NT_KERNEL32
LIBC_NT_IPHLPAPI_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_NT_IPHLPAPI_A_DIRECTDEPS),$($(x))))
$(LIBC_NT_IPHLPAPI_A): \
libc/nt/iphlpapi/ \
$(LIBC_NT_IPHLPAPI_A).pkg \
$(LIBC_NT_IPHLPAPI_A_OBJS)
$(LIBC_NT_IPHLPAPI_A).pkg: \
$(LIBC_NT_IPHLPAPI_A_OBJS) \
$(foreach x,$(LIBC_NT_IPHLPAPI_A_DIRECTDEPS),$($(x)_A).pkg)
#───────────────────────────────────────────────────────────────────────────────
LIBC_NT_ARTIFACTS += LIBC_NT_MSWSOCK_A
LIBC_NT_MSWSOCK = $(LIBC_NT_MSWSOCK_A_DEPS) $(LIBC_NT_MSWSOCK_A)
LIBC_NT_MSWSOCK_A = o/$(MODE)/libc/nt/MsWSock.a

View file

@ -0,0 +1,291 @@
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_
#define COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_
#include "libc/nt/winsock.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* Constants ----------------------------------------------------------- */
#define kNtMaxAdapterAddressLength 8
#define kNtMaxDnsSuffixStringLength 256
#define kNtMaxDhcpv6DuidLength 130
/* Values for the 'Flags' parameter of GetAdaptersAddresses */
#define kNtGaaFlagSkipUnicast 0x0001
#define kNtGaaFlagSkipAnycast 0x0002
#define kNtGaaFlagSkipMulticast 0x0004
#define kNtGaaFlagSkipDnsServer 0x0008
#define kNtGaaFlagIncludePrefix 0x0010
#define kNtGaaFlagSkipFriendlyName 0x0020
#define kNtGaaFlagIncludeWinsInfo 0x0040
#define kNtGaaFlagIncludeGateways 0x0080
#define kNtGaaFlagIncludeAllInterfaces 0x0100
#define kNtGaaFlagIncludeAllCompartments 0x0200
#define kNtGaaFlagIncludeTunnelBindingorder 0x0400
#define kNtGaaFlagSkipDnsInfo 0x0800
/* Values for the IfType parameter
* See: https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
*/
#define kNtIfTypeOther 1
#define kNtIfTypeEthernetCsmacd 6
#define kNtIfTypeIso88025Tokenring 9
#define kNtIfTypePpp 23
#define kNtIfTypeSoftwareLoopback 24
#define kNtIfTypeAtm 37
#define kNtIfTypeIeee80211 71 /* wifi */
#define kNtIfTypeTunnel 131
#define kNtIfTypeIeee1394 144 /* firewire */
/* Enums --------------------------------------------------------------- */
typedef enum {
kNtIpPrefixOriginOther,
kNtIpPrefixOriginManual,
kNtIpPrefixOriginWellKnown,
kNtIpPrefixOriginDhcp,
kNtIpPrefixOriginRouterAdvertisement,
kNtIpPrefixOriginUnchanged
} NtPrefixOrigin;
typedef enum {
kNtNlsoOther,
kNtNlsoManual,
kNtNlsoWellKnown,
kNtNlsoDhcp,
kNtNlsoLinkLayerAddress,
kNtNlsoRandom,
kNtIpSuffixOriginOther,
kNtIpSuffixOriginManual,
kNtIpSuffixOriginWellKnown,
kNtIpSuffixOriginDhcp,
kNtIpSuffixOriginLinkLayerAddress,
kNtIpSuffixOriginRandom,
kNtIpSuffixOriginUnchanged
} NtSuffixOrigin;
typedef enum {
kNtNldsInvalid,
kNtNldsTentative,
kNtNldsDuplicate,
kNtNldsDeprecated,
kNtNldsPreferred,
kNtIpDadStateInvalid,
kNtIpDadStateTentative,
kNtIpDadStateDuplicate,
kNtIpDadStateDeprecated,
kNtIpDadStatePreferred
} NtDadState;
typedef enum {
kNtIfOperStatusUp = 1,
kNtIfOperStatusDown,
kNtIfOperStatusTesting,
kNtIfOperStatusUnknown,
kNtIfOperStatusDormant,
kNtIfOperStatusNotPresent,
kNtIfOperStatusLowerLayerDown
} NtIfOperStatus;
typedef enum {
kNtNetIfConnectionDedicated = 1,
kNtNetIfConnectionPassive = 2,
kNtNetIfConnectionDemand = 3,
kNtNetIfConnectionMaximum = 4
} NtNetIfConnectionType;
typedef enum {
kNtTunnelTypeNone = 0,
kNtTunnelTypeOther = 1,
kNtTunnelTypeDirect = 2,
kNtTunnelType6to4 = 11,
kNtTunnelTypeIsatap = 13,
kNtTunnelTypeTeredo = 14,
kNtTunnelTypeIphttps = 15
} NtTunnelType;
/* Inner Types --------------------------------------------------------- */
typedef struct _NtIpAdapterUnicastAddress {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Flags;
};
};
struct _NtIpAdapterUnicastAddress * Next;
struct NtSocketAddress Address;
NtPrefixOrigin PrefixOrigin;
NtSuffixOrigin SuffixOrigin;
NtDadState DadState;
uint32_t ValidLifetime;
uint32_t PreferredLifetime;
uint32_t LeaseLifetime;
uint8_t OnLinkPrefixLength;
} NtIpAdapterUnicastAddress;
typedef struct NtIpAdapterAnycastAddress {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Flags;
};
};
struct _NtIpAdapterAnycastAddress *Next;
struct NtSocketAddress Address;
} NtIpAdapterAnycastAddress;
typedef struct NtIpAdapterMulticastAddress {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Flags;
};
};
struct _NtIpAdapterMulticastAddress *Next;
struct NtSocketAddress Address;
} NtIpAdapterMulticastAddress;
typedef struct _NtIpAdapterDnsServerAddress {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Reserved;
};
};
struct _NtIpAdapterDnsServerAddress *Next;
struct NtSocketAddress Address;
} NtIpAdapterDnsServerAddress;
typedef struct _NtIpAdapterPrefix {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Flags;
};
};
struct _NtIpAdapterPrefix *Next;
struct NtSocketAddress Address;
uint32_t PrefixLength;
} NtIpAdapterPrefix;
typedef struct _NtIpAdapterWinsServerAddress {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Reserved;
};
};
struct _NtIpAdapterWinsServerAddress *Next;
struct NtSocketAddress Address;
} NtIpAdapterWinsServerAddress;
typedef struct _NtIpAdapterGatewayAddress {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t Reserved;
};
};
struct _NtIpAdapterGatewayAddress *Next;
struct NtSocketAddress Address;
} NtIpAdapterGatewayAddress;
typedef struct _NtGUID {
uint32_t Data1;
uint16_t Data2;
uint16_t Data3;
uint8_t Data4[8];
} NtGUID;
typedef union _NtNetLUID
{
uint64_t Value;
struct
{
uint64_t Reserved:24;
uint64_t NetLuidIndex:24;
uint64_t IfType:16;
}Info;
} NtNetLUID;
typedef struct _NtIpAdapterDnsSuffix {
struct _NtIpAdapterDnsSuffix *Next;
uint16_t String[kNtMaxDnsSuffixStringLength];
} NtIpAdapterDnsSuffix;
/* Top level ----------------------------------------------------------- */
typedef struct _NtIpAdapterAddresses {
union {
uint64_t Alignment;
struct {
uint32_t Length;
uint32_t IfIndex;
};
};
struct _NtIpAdapterAddresses * Next;
char * AdapterName;
NtIpAdapterUnicastAddress * FirstUnicastAddress;
NtIpAdapterAnycastAddress * FirstAnycastAddress;
NtIpAdapterMulticastAddress * FirstMulticastAddress;
NtIpAdapterDnsServerAddress * FirstDnsServerAddress;
uint16_t * DnsSuffix;
uint16_t * Description;
uint16_t * FriendlyName;
uint8_t PhysicalAddress[kNtMaxAdapterAddressLength];
uint32_t PhysicalAddressLength;
union {
uint32_t Flags;
struct {
uint32_t DdnsEnabled : 1;
uint32_t RegisterAdapterSuffix : 1;
uint32_t Dhcpv4Enabled : 1;
uint32_t ReceiveOnly : 1;
uint32_t NoMulticast : 1;
uint32_t Ipv6OtherStatefulConfig : 1;
uint32_t NetbiosOverTcpipEnabled : 1;
uint32_t Ipv4Enabled : 1;
uint32_t Ipv6Enabled : 1;
uint32_t Ipv6ManagedAddressConfigurationSupported : 1;
};
};
uint32_t Mtu;
uint32_t IfType;
NtIfOperStatus OperStatus;
uint32_t Ipv6IfIndex;
uint32_t ZoneIndices[16];
NtIpAdapterPrefix * FirstPrefix;
uint64_t TransmitLinkSpeed;
uint64_t ReceiveLinkSpeed;
NtIpAdapterWinsServerAddress * FirstWinsServerAddress;
NtIpAdapterGatewayAddress * FirstGatewayAddress;
uint32_t Ipv4Metric;
uint32_t Ipv6Metric;
NtNetLUID Luid;
struct NtSocketAddress Dhcpv4Server;
uint32_t CompartmentId;
NtGUID NetworkGuid;
NtNetIfConnectionType ConnectionType;
NtTunnelType TunnelType;
struct NtSocketAddress Dhcpv6Server;
uint8_t Dhcpv6ClientDuid[kNtMaxDhcpv6DuidLength];
uint32_t Dhcpv6ClientDuidLength;
uint32_t Dhcpv6Iaid;
NtIpAdapterDnsSuffix * FirstDnsSuffix;
} NtIpAdapterAddresses;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_ */

View file

@ -91,6 +91,17 @@ bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y,
int32_t nReserved, int64_t hWnd,
const struct NtRect *prcRect);
int WideCharToMultiByte(unsigned int CodePage,
uint32_t dwFlags,
uint16_t * lpWideCharStr,
int cchWideChar,
char * lpMultiByteStr,
int cbMultiByte,
uint16_t * lpDefaultChar,
int * lpUsedDefaultChar
);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_WINDOWS_H_ */

View file

@ -85,6 +85,7 @@
#define kNtSioTranslateHandle 0xC800000Du
#define kNtSioUdpConnreset 0x9800000Cu
#define kNtSioUdpNetreset 0x9800000Fu
#define kNtSioGetInterfaceList 0x4008747fu /* _IOR('t', 127, ULONG) */
#define kNtNspNotifyImmediately 0
#define kNtNspNotifyHwnd 1
@ -311,6 +312,13 @@ struct NtFdSet {
int64_t fd_array[64];
};
struct NtInterfaceInfo {
uint64_t iiFlags;
struct sockaddr_in iiAddress;
struct sockaddr_in iiBroadcastAddress;
struct sockaddr_in iiNetmask;
};
/**
* Winsock2 prototypes.
*