Differences From Artifact [0c6d28d689]:
- File src/platform/Windows/OFSystemInfo+NetworkInterfaces.m — part of check-in [ccf154b51a] at 2023-06-11 19:58:25 on branch trunk — +[OFSystemInfo networkInterfaces]: MAC on Linux (user: js, size: 7271) [annotate] [blame] [check-ins using] [more...]
To Artifact [f40e21866b]:
- File
src/platform/Windows/OFSystemInfo+NetworkInterfaces.m
— part of check-in
[abe3ccd61e]
at
2024-01-20 15:18:15
on branch trunk
— +[OFSystemInfo networkInterfaces]: Avoid IfIndex
It turns out it is not unique, resulting in two adapters being merged
into one. Instead, use the adapter name as key. (user: js, size: 7255) [annotate] [blame] [check-ins using] [more...]
1 | /* | | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * |
︙ | ︙ | |||
34 35 36 37 38 39 40 | PIP_ADAPTER_ADDRESSES, PULONG); static void init(void) { HMODULE module; | | < < > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | PIP_ADAPTER_ADDRESSES, PULONG); static void init(void) { HMODULE module; if ((module = GetModuleHandle("iphlpapi.dll")) != NULL) GetAdaptersAddressesFuncPtr = (WINAPI ULONG (*)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG)) GetProcAddress(module, "GetAdaptersAddresses"); } static OFMutableDictionary OF_GENERIC(OFString *, OFNetworkInterface) * networkInterfacesFromGetAdaptersAddresses(void) { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; ULONG adapterAddressesSize = sizeof(IP_ADAPTER_ADDRESSES); PIP_ADAPTER_ADDRESSES adapterAddresses; if ((adapterAddresses = malloc(adapterAddressesSize)) == NULL) return nil; @try { OFStringEncoding encoding = [OFLocale encoding]; ULONG error = GetAdaptersAddressesFuncPtr(AF_UNSPEC, 0, NULL, adapterAddresses, &adapterAddressesSize); if (error == ERROR_BUFFER_OVERFLOW) { PIP_ADAPTER_ADDRESSES newAdapterAddresses = realloc(adapterAddresses, adapterAddressesSize); |
︙ | ︙ | |||
98 99 100 101 102 103 104 | OFNetworkInterfaceHardwareAddress; OFData *address = [OFData dataWithItems: iter->PhysicalAddress count: iter->PhysicalAddressLength]; [interface setObject: address forKey: key]; } | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | OFNetworkInterfaceHardwareAddress; OFData *address = [OFData dataWithItems: iter->PhysicalAddress count: iter->PhysicalAddressLength]; [interface setObject: address forKey: key]; } for (__typeof__(iter->FirstUnicastAddress) addrIter = iter->FirstUnicastAddress; addrIter != NULL; addrIter = addrIter->Next) { OFSocketAddress address; int length; OFNetworkInterfaceKey key; OFMutableData *addresses; |
︙ | ︙ | |||
191 192 193 194 195 196 197 | iter = iter->Next) { OFMutableDictionary *interface; OFString *name, *IPString; OFNumber *index; OFSocketAddress IPv4Address; OFData *addresses; | | < | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | iter = iter->Next) { OFMutableDictionary *interface; OFString *name, *IPString; OFNumber *index; OFSocketAddress IPv4Address; OFData *addresses; name = [OFString stringWithFormat: @"%u", iter->Index]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } index = [OFNumber numberWithUnsignedInt: iter->Index]; |
︙ | ︙ |