`if_nameindex()` always fails with EACCES on my Android 15 device under Termux. On failure, `if_nameindex()` returns null and sets errno. The original implementation in Wine didn't check for this, which meant that `entry->if_index` would be dereferencing null and failing with an access violation error. As all calls to `if_list_lock()` are guarded with a mutex lock, the lock would never be released, causing deadlocks. To reproduce this on my PC, I used the \`LD_PRELOAD\` trick with this dummy dynamic library: ```c #define _GNU_SOURCE #include <net/if.h> #include <errno.h> #include <stdlib.h> struct if_nameindex *if_nameindex(void) { errno = EACCES; return NULL; } ``` ```console $ LD_PRELOAD=/home/user/wine/libborked_if_nameindex.so WINEDEBUG=+nsi,+iphlpapi,+seh ./wine ipconfig 0054:trace:nsi:DriverEntry (00007FFFFF219CF0, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\nsiproxy") 0054:trace:iphlpapi:GetIfTable2 table 00007FFFFEC0FA00 0054:trace:iphlpapi:GetIfTable2Ex level 0, table 00007FFFFEC0FA00 0054:trace:nsi:NsiAllocateAndGetTable 1 00006FFFFDD254F0 0 00007FFFFEC0F940 8 00007FFFFEC0F948 1092 00007FFFFEC0F950 216 00007FFFFEC0F958 600 00007FFFFEC0F93C 0 0054:trace:nsi:NsiEnumerateObjectsAllParameters 1 0 00006FFFFDD254F0 0 00007FFFFF27F150 8 00007FFFFF27F360 1092 00007FFFFF290470 216 00007FFFFF293A80 600 00007FFFFEC0F83C 0058:trace:nsi:nsi_ioctl ioctl 121000 insize 56 outsize 122628 0058:trace:nsi:ifinfo_enumerate_all 0x7fffff2bafa4 8 0x7fffff2bb1a4 1092 0x7fffff2cc2a4 216 0x7fffff2cf8a4 600 0x7ffffef0f948 0058:trace:seh:handle_syscall_fault code=c0000005 flags=0 addr=0x7fdb07114783 ip=7fdb07114783 tid=0058 0058:trace:seh:handle_syscall_fault info[0]=0000000000000000 0058:trace:seh:handle_syscall_fault info[1]=0000000000000000 0058:trace:seh:handle_syscall_fault rax=0000000000000000 rbx=00007fffff2bb1a4 rcx=0000000000000000 rdx=0000000000000001 0058:trace:seh:handle_syscall_fault rsi=0000000000000000 rdi=00007fdb0711cf80 rbp=00007fffff2cc2a4 rsp=00007ffffed0e8f0 0058:trace:seh:handle_syscall_fault r8=0000000000000000 r9=0000000000000000 r10=00007fdb0768a898 r11=00007fdb076a0250 0058:trace:seh:handle_syscall_fault r12=00007ffffef0f948 r13=00007fffff2bafa4 r14=0000000000000008 r15=0000000000000038 0058:trace:seh:handle_syscall_fault returning to user mode ip=00006ffffde12515 ret=c0000005 0054:trace:nsi:NsiFreeTable 00007FFFFF27F150 00007FFFFF27F360 00007FFFFF290470 00007FFFFF293A80 00a4:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\winebth": c00000e5 003c:fixme:service:scmdatabase_autostart_services Auto-start service L"winebth" failed to start: 1359 00e4:trace:iphlpapi:GetAdaptersAddresses (0, 00000080, 0000000000000000, 00007FFFFE32E280, 00007FFFFE2FFA8C) 00e4:trace:nsi:NsiAllocateAndGetTable 1 00006FFFFDD254F0 0 00007FFFFE2FF9B0 8 00007FFFFE2FF9B8 1092 00007FFFFE2FF9C0 216 00007FFFFE2FF9C8 600 00007FFFFE2FF9AC 0 00e4:trace:nsi:NsiEnumerateObjectsAllParameters 1 0 00006FFFFDD254F0 0 00007FFFFE32F290 8 00007FFFFE8F7DC0 1092 00007FFFFE908ED0 216 00007FFFFE90C4E0 600 00007FFFFE2FF87C 0058:trace:nsi:nsi_ioctl ioctl 121000 insize 56 outsize 122628 0058:trace:nsi:ifinfo_enumerate_all 0x7fffff27f224 8 0x7fffff27f424 1092 0x7fffff290524 216 0x7fffff293b24 600 0x7ffffef0f948 <-- stuck in pthread_mutex_lock( &if_list_lock ); ``` The changes to `adapters_addresses_alloc` and `ipv4_neighbour_enumerate_all` deal with the edge case of no network adapters being present/detectable by Wine. On systems where `if_nameindex()` always fails, `add_entry()` in ndis.c would never be called. On the topic of correctness, MSDN says that `GetAdaptersAddresses` may return `ERROR_NO_DATA` if "No addresses were found for the requested parameters", which sounds right to me, but I wasn't able to come up with an invocation that would give me that return to put in the tests. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10628