大网数据广告活动
网络与域名解析

Enumerate All Destinations

· 52CE 我爱测

The following sample code shows how to enumerate all destinations in the routing table.

The following sample code shows how to enumerate all destinations in the routing table.

#include <windows.h>


#define ALLOC_RTM_DEST_INFO(NumViews, NumInfos) (PRTM_DEST_INFO) _alloca(RTM_SIZE_OF_DEST_INFO(NumViews) * NumInfos)

void main()
{
    // Macro to allocate a RTM_DEST_INFO on the stack

    // Code to enumerate destinations in the table
    MaxHandles = RegnProfile.MaxHandlesInEnum;
    DestInfos = ALLOC_RTM_DEST_INFO(NumViews, MaxHandles);
    DestInfoSize = RTM_SIZE_OF_DEST_INFO(NumViews);

    // Enumerate all destinations in the subtree (0 / 0)
    // (basically the whole tree; you can
    // also achieve this by using RTM_ENUM_START)
    RTM_IPV4_MAKE_NET_ADDRESS(&NetAddress,0x00000000,0);

    Status = RtmCreateDestEnum(RtmRegHandle, RTM_VIEW_MASK_UCAST | RTM_VIEW_MASK_MCAST, RTM_ENUM_RANGE, &NetAddress, RTM_BEST_PROTOCOL, &EnumHandle1);
    if (Status == NO_ERROR)
    {
        do {
            NumInfos = MaxHandles;
            Status = RtmGetEnumDests(RtmRegHandle, EnumHandle1, &NumInfos, DestInfos);
            for (i = 0; i < NumInfos; i++)
            {
                DestInfo = (PRTM_DEST_INFO) ((PUCHAR)DestInfos+(i*DestInfoSize));

                // Process the current destination information
                ASSERT(DestInfo->ViewInfo[0].ViewId == RTM_VIEW_ID_UCAST);
                BestUnicastRoute = DestInfo->ViewInfo[0].Route;

                // Advertise the best unicast route for the destination
                ...

                // You can enumerate all routes for a destination by
                // creating a route enumeration using
                // RtmCreateRouteEnum ( .. DestInfo->DestHandle .. );
            }
            RtmReleaseDests(RtmRegHandle, NumInfos, DestInfos);

        } while (Status == NO_ERROR)

        // Close the enumeration and release its resources
        RtmDeleteEnumHandle(RtmRegHandle, EnumHandle1);
    }
}

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。