From d044171b72337ec530a9b9ab1334a08e9c91fbaf Mon Sep 17 00:00:00 2001 From: Huw Davies <huw@codeweavers.com> Date: Fri, 9 Jul 2021 09:09:26 +0100 Subject: [PATCH] iphlpapi: Implement GetIfEntry() on top of nsi. Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> --- dlls/iphlpapi/ifenum.c | 41 ----------------------------------- dlls/iphlpapi/ifenum.h | 7 ------ dlls/iphlpapi/iphlpapi_main.c | 33 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 65 deletions(-) diff --git a/dlls/iphlpapi/ifenum.c b/dlls/iphlpapi/ifenum.c index 3b4ac775db7..8108c7ff8c2 100644 --- a/dlls/iphlpapi/ifenum.c +++ b/dlls/iphlpapi/ifenum.c @@ -745,47 +745,6 @@ DWORD getInterfaceStatusByName(const char *name, INTERNAL_IF_OPER_STATUS *status return ret; } -DWORD getInterfaceEntryByName(const char *name, PMIB_IFROW entry) -{ - BYTE addr[MAX_INTERFACE_PHYSADDR]; - DWORD ret, len = sizeof(addr), type; - - if (!name) - return ERROR_INVALID_PARAMETER; - if (!entry) - return ERROR_INVALID_PARAMETER; - - if (getInterfacePhysicalByName(name, &len, addr, &type) == NO_ERROR) { - WCHAR *assigner; - const char *walker; - - memset(entry, 0, sizeof(MIB_IFROW)); - for (assigner = entry->wszName, walker = name; *walker; - walker++, assigner++) - *assigner = *walker; - *assigner = 0; - getInterfaceIndexByName(name, &entry->dwIndex); - entry->dwPhysAddrLen = len; - memcpy(entry->bPhysAddr, addr, len); - memset(entry->bPhysAddr + len, 0, sizeof(entry->bPhysAddr) - len); - entry->dwType = type; - /* FIXME: how to calculate real speed? */ - getInterfaceMtuByName(name, &entry->dwMtu); - /* lie, there's no "administratively down" here */ - entry->dwAdminStatus = MIB_IF_ADMIN_STATUS_UP; - getInterfaceStatusByName(name, &entry->dwOperStatus); - /* punt on dwLastChange? */ - entry->dwDescrLen = min(strlen(name), MAX_INTERFACE_DESCRIPTION - 1); - memcpy(entry->bDescr, name, entry->dwDescrLen); - entry->bDescr[entry->dwDescrLen] = '\0'; - entry->dwDescrLen++; - ret = NO_ERROR; - } - else - ret = ERROR_INVALID_DATA; - return ret; -} - static DWORD getIPAddrRowByName(PMIB_IPADDRROW ipAddrRow, const char *ifName, const struct sockaddr *sa) { diff --git a/dlls/iphlpapi/ifenum.h b/dlls/iphlpapi/ifenum.h index 558dff64cb6..d0143eaaf69 100644 --- a/dlls/iphlpapi/ifenum.h +++ b/dlls/iphlpapi/ifenum.h @@ -87,13 +87,6 @@ DWORD getInterfaceIndexByName(const char *name, IF_INDEX *index) DECLSPEC_HIDDEN DWORD getInterfacePhysicalByIndex(IF_INDEX index, PDWORD len, PBYTE addr, PDWORD type) DECLSPEC_HIDDEN; -/* Fills in the MIB_IFROW by name. Doesn't fill in interface statistics, - * see ipstats.h for that. - * Returns ERROR_INVALID_PARAMETER if name is NULL, ERROR_INVALID_DATA - * if name isn't valid, and NO_ERROR otherwise. - */ -DWORD getInterfaceEntryByName(const char *name, PMIB_IFROW entry) DECLSPEC_HIDDEN; - DWORD getNumIPAddresses(void) DECLSPEC_HIDDEN; /* Gets the configured IP addresses for the system, and sets *ppIpAddrTable to diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index e5b6e72bde1..375766f1e9c 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -1821,26 +1821,25 @@ static void if_row_fill( MIB_IFROW *row, struct nsi_ndis_ifinfo_rw *rw, struct n * Success: NO_ERROR * Failure: error code from winerror.h */ -DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow) +DWORD WINAPI GetIfEntry( MIB_IFROW *row ) { - DWORD ret; - char nameBuf[MAX_ADAPTER_NAME]; - char *name; + struct nsi_ndis_ifinfo_rw rw; + struct nsi_ndis_ifinfo_dynamic dyn; + struct nsi_ndis_ifinfo_static stat; + NET_LUID luid; + DWORD err; - TRACE("pIfRow %p\n", pIfRow); - if (!pIfRow) - return ERROR_INVALID_PARAMETER; + TRACE( "row %p\n", row ); + if (!row) return ERROR_INVALID_PARAMETER; - name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf); - if (name) { - ret = getInterfaceEntryByName(name, pIfRow); - if (ret == NO_ERROR) - ret = getInterfaceStatsByName(name, pIfRow); - } - else - ret = ERROR_INVALID_DATA; - TRACE("returning %d\n", ret); - return ret; + err = ConvertInterfaceIndexToLuid( row->dwIndex, &luid ); + if (err) return err; + + err = NsiGetAllParameters( 1, &NPI_MS_NDIS_MODULEID, NSI_NDIS_IFINFO_TABLE, + &luid, sizeof(luid), &rw, sizeof(rw), + &dyn, sizeof(dyn), &stat, sizeof(stat) ); + if (!err) if_row_fill( row, &rw, &dyn, &stat ); + return err; } static int ifrow_cmp( const void *a, const void *b ) -- 2.24.1