[2/2] wbemprox: Add a partial implementation of Win32_IP4RouteTable.
Hans Leidekker
hans at codeweavers.com
Wed Feb 1 07:18:50 CST 2017
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
dlls/wbemprox/builtin.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
dlls/wbemprox/tests/query.c | 63 +++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+)
diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c
index 0976306..73d93a0 100644
--- a/dlls/wbemprox/builtin.c
+++ b/dlls/wbemprox/builtin.c
@@ -26,6 +26,9 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
@@ -81,6 +84,8 @@ static const WCHAR class_diskdriveW[] =
{'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
static const WCHAR class_diskpartitionW[] =
{'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
+static const WCHAR class_ip4routetableW[] =
+ {'W','i','n','3','2','_','I','P','4','R','o','u','t','e','T','a','b','l','e',0};
static const WCHAR class_logicaldiskW[] =
{'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
static const WCHAR class_logicaldisk2W[] =
@@ -184,6 +189,8 @@ static const WCHAR prop_defaultvalueW[] =
{'D','e','f','a','u','l','t','V','a','l','u','e',0};
static const WCHAR prop_descriptionW[] =
{'D','e','s','c','r','i','p','t','i','o','n',0};
+static const WCHAR prop_destinationW[] =
+ {'D','e','s','t','i','n','a','t','i','o','n',0};
static const WCHAR prop_deviceidW[] =
{'D','e','v','i','c','e','I','d',0};
static const WCHAR prop_dhcpenabledW[] =
@@ -272,6 +279,8 @@ static const WCHAR prop_netconnectionstatusW[] =
{'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
static const WCHAR prop_networkW[] =
{'N','e','t','w','o','r','k',0};
+static const WCHAR prop_nexthopW[] =
+ {'N','e','x','t','H','o','p',0};
static const WCHAR prop_numcoresW[] =
{'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
static const WCHAR prop_numlogicalprocessorsW[] =
@@ -471,6 +480,12 @@ static const struct column col_diskpartition[] =
{ prop_startingoffsetW, CIM_UINT64 },
{ prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
};
+static const struct column col_ip4routetable[] =
+{
+ { prop_destinationW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
+ { prop_interfaceindexW, CIM_SINT32|COL_FLAG_KEY },
+ { prop_nexthopW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
+};
static const struct column col_logicaldisk[] =
{
{ prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
@@ -855,6 +870,12 @@ struct record_diskpartition
UINT64 startingoffset;
const WCHAR *type;
};
+struct record_ip4routetable
+{
+ const WCHAR *destination;
+ INT32 interfaceindex;
+ const WCHAR *nexthop;
+};
struct record_logicaldisk
{
const WCHAR *device_id;
@@ -2025,6 +2046,59 @@ static enum fill_status fill_diskpartition( struct table *table, const struct ex
return status;
}
+static WCHAR *get_ip4_string( DWORD addr )
+{
+ static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
+ WCHAR *ret;
+
+ if (!(ret = heap_alloc( sizeof("ddd.ddd.ddd.ddd") * sizeof(WCHAR) ))) return NULL;
+ sprintfW( ret, fmtW, (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff );
+ return ret;
+}
+
+static enum fill_status fill_ip4routetable( struct table *table, const struct expr *cond )
+{
+ struct record_ip4routetable *rec;
+ UINT i, row = 0, offset = 0, size = 0;
+ MIB_IPFORWARDTABLE *forwards;
+ enum fill_status status = FILL_STATUS_UNFILTERED;
+
+ if (GetIpForwardTable( NULL, &size, TRUE ) != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
+ if (!(forwards = heap_alloc( size ))) return FILL_STATUS_FAILED;
+ if (GetIpForwardTable( forwards, &size, TRUE ))
+ {
+ heap_free( forwards );
+ return FILL_STATUS_FAILED;
+ }
+ if (!resize_table( table, forwards->dwNumEntries, sizeof(*rec) ))
+ {
+ heap_free( forwards );
+ return FILL_STATUS_FAILED;
+ }
+
+ for (i = 0; i < forwards->dwNumEntries; i++)
+ {
+ rec = (struct record_ip4routetable *)(table->data + offset);
+
+ rec->destination = get_ip4_string( ntohl(forwards->table[i].dwForwardDest) );
+ rec->interfaceindex = forwards->table[i].dwForwardIfIndex;
+ rec->nexthop = get_ip4_string( ntohl(forwards->table[i].dwForwardNextHop) );
+
+ if (!match_row( table, row, cond, &status ))
+ {
+ free_row_values( table, row );
+ continue;
+ }
+ offset += sizeof(*rec);
+ row++;
+ }
+ TRACE("created %u rows\n", row);
+ table->num_rows = row;
+
+ heap_free( forwards );
+ return status;
+}
+
static WCHAR *get_volumename( const WCHAR *root )
{
WCHAR buf[MAX_PATH + 1] = {0};
@@ -3171,6 +3245,7 @@ static struct table builtin_classes[] =
{ class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
{ class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
{ class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
+ { class_ip4routetableW, SIZEOF(col_ip4routetable), col_ip4routetable, 0, 0, NULL, fill_ip4routetable },
{ class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
{ class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
{ class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c
index 1aeb7e5..8ff9803 100644
--- a/dlls/wbemprox/tests/query.c
+++ b/dlls/wbemprox/tests/query.c
@@ -1301,6 +1301,68 @@ static void test_PhysicalMemory( IWbemServices *services )
SysFreeString( wql );
}
+static void test_IP4RouteTable( IWbemServices *services )
+{
+ static const WCHAR destinationW[] = {'D','e','s','t','i','n','a','t','i','o','n',0};
+ static const WCHAR interfaceindexW[] = {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
+ static const WCHAR nexthopW[] = {'N','e','x','t','H','o','p',0};
+ static const WCHAR queryW[] =
+ {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
+ 'I','P','4','R','o','u','t','e','T','a','b','l','e',0};
+ BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
+ IEnumWbemClassObject *result;
+ IWbemClassObject *obj;
+ VARIANT val;
+ CIMTYPE type;
+ HRESULT hr;
+ DWORD count;
+
+ hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
+ if (hr != S_OK)
+ {
+ win_skip( "Win32_IP4RouteTable not available\n" );
+ return;
+ }
+
+ for (;;)
+ {
+ hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
+ if (hr != S_OK) break;
+
+ type = 0xdeadbeef;
+ VariantInit( &val );
+ hr = IWbemClassObject_Get( obj, destinationW, 0, &val, &type, NULL );
+ ok( hr == S_OK, "failed to get destination %08x\n", hr );
+ ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
+ ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
+ trace( "destination %s\n", wine_dbgstr_w(V_BSTR( &val )) );
+ VariantClear( &val );
+
+ type = 0xdeadbeef;
+ VariantInit( &val );
+ hr = IWbemClassObject_Get( obj, interfaceindexW, 0, &val, &type, NULL );
+ ok( hr == S_OK, "failed to get interface index %08x\n", hr );
+ ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
+ ok( type == CIM_SINT32, "unexpected type 0x%x\n", type );
+ trace( "interfaceindex %d\n", V_I4( &val ) );
+ VariantClear( &val );
+
+ type = 0xdeadbeef;
+ VariantInit( &val );
+ hr = IWbemClassObject_Get( obj, nexthopW, 0, &val, &type, NULL );
+ ok( hr == S_OK, "failed to get nexthop %08x\n", hr );
+ ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
+ ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
+ trace( "nexthop %s\n", wine_dbgstr_w(V_BSTR( &val )) );
+ VariantClear( &val );
+
+ IWbemClassObject_Release( obj );
+ }
+
+ SysFreeString( query );
+ SysFreeString( wql );
+}
+
START_TEST(query)
{
static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
@@ -1341,6 +1403,7 @@ START_TEST(query)
test_OperatingSystem( services );
test_ComputerSystemProduct( services );
test_PhysicalMemory( services );
+ test_IP4RouteTable( services );
SysFreeString( path );
IWbemServices_Release( services );
--
2.1.4
More information about the wine-patches
mailing list