모든 대상 열거
다음 샘플 코드는 라우팅 테이블의 모든 대상을 열거하는 방법을 보여 줍니다.
#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);
}
}
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기