Win32 API 日本語リファレンス
ホーム › NetworkManagement.Rras › RtmGetLessSpecificDestination

RtmGetLessSpecificDestination

関数
指定宛先より粗いプレフィックスの宛先を取得する。
DLLrtm.dll呼出規約winapi対応OSwindowsserver2000

シグネチャ

// rtm.dll
#include <windows.h>

DWORD RtmGetLessSpecificDestination(
    INT_PTR RtmRegHandle,
    INT_PTR DestHandle,
    DWORD ProtocolId,
    DWORD TargetViews,
    RTM_DEST_INFO* DestInfo
);

パラメーター

名前型方向説明
RtmRegHandleINT_PTRinクライアントのハンドル。以前の RtmRegisterEntity の呼び出しで取得したものです。
DestHandleINT_PTRin宛先のハンドル。
ProtocolIdDWORDin

プロトコル識別子を指定します。ProtocolID は検索条件には含まれません。ルーティングテーブルマネージャーは、この識別子を使用して、どのルート情報を返すかを決定します。たとえば、クライアントが RIP プロトコル識別子を指定した場合、その宛先への最適なルートが RIP 以外のルートであっても、最適な RIP ルートが返されます。

どのプロトコルが所有しているかに関係なくルートを返すには、RTM_BEST_PROTOCOL を指定します。呼び出し元のプロトコルにとって最適なルートを返すには、RTM_THIS_PROTOCOL を指定します。

TargetViewsDWORDin情報を返すビューを指定します。クライアントが RTM_VIEW_MASK_ANY を指定した場合、すべてのビューから宛先情報が返されますが、ビュー固有の情報は返されません。
DestInfoRTM_DEST_INFO*inout

入力時、DestInfo は RTM_DEST_INFO 構造体へのポインターです。

出力時、DestInfo には要求された宛先情報が格納されます。

戻り値の型: DWORD

公式ドキュメント

RtmGetLessSpecificDestination 関数は、指定された宛先プレフィックスに対して、次に一致度の高い (最長の) プレフィックスを持つ宛先をルーティングテーブルから検索します。要求された宛先情報が返されます。

戻り値

関数が成功した場合、戻り値は NO_ERROR です。

関数が失敗した場合、戻り値は次のいずれかのエラーコードです。

値 意味
ERROR_INVALID_PARAMETER
パラメーターに正しくない情報が含まれています。
ERROR_NOT_FOUND
次に一致度の高い宛先が見つかりません。

解説(Remarks)

DestInfo パラメーターは、可変サイズの RTM_DEST_INFO 構造体です。クライアントが TargetViews で複数のビューを指定した場合、DestInfo のサイズはビューごとに増加します。この関数を呼び出す前に、 RTM_SIZE_OF_DEST_INFO マクロを使用して、DestInfo 構造体に割り当てるメモリ量を判断してください。 RTM_SIZE_OF_DEST_INFO のパラメーターには、TargetViews に指定した値を使用します。

RtmGetLessSpecificDestination 関数は、 RtmGetMostSpecificDestination の呼び出しの後に使用し、宛先に対する次に一致度の高い一致を返します。この呼び出しは、 RtmGetLessSpecificDestination の以前の呼び出しの後に使用して、さらに 1 つ一致度の低い一致を返すこともできます。クライアントはこの関数を使用して、宛先のプレフィックスツリーを "上へたどる" ことができます。

この呼び出しは、 RtmGetDestInfo や RtmGetChangedDests など、 RTM_DEST_INFO 構造体を返す関数の呼び出しの後にも使用されます。

RtmGetLessSpecificDestination 関数は、既定のルートが存在する場合、そこに到達するまで一致を返し続けます。既定のルートが見つかった後は、 RtmGetLessSpecificDestination は ERROR_NOT_FOUND を返します。

RtmGetLessSpecificDestination 関数と RtmGetMostSpecificDestination 関数の一般的な用途の 1 つは、一致するすべての宛先を取得することです。

この関数を使用したサンプルコードについては、 プレフィックスツリーを使用したルートの検索を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// rtm.dll
#include <windows.h>

DWORD RtmGetLessSpecificDestination(
    INT_PTR RtmRegHandle,
    INT_PTR DestHandle,
    DWORD ProtocolId,
    DWORD TargetViews,
    RTM_DEST_INFO* DestInfo
);
[DllImport("rtm.dll", ExactSpelling = true)]
static extern uint RtmGetLessSpecificDestination(
    IntPtr RtmRegHandle,   // INT_PTR
    IntPtr DestHandle,   // INT_PTR
    uint ProtocolId,   // DWORD
    uint TargetViews,   // DWORD
    IntPtr DestInfo   // RTM_DEST_INFO* in/out
);
<DllImport("rtm.dll", ExactSpelling:=True)>
Public Shared Function RtmGetLessSpecificDestination(
    RtmRegHandle As IntPtr,   ' INT_PTR
    DestHandle As IntPtr,   ' INT_PTR
    ProtocolId As UInteger,   ' DWORD
    TargetViews As UInteger,   ' DWORD
    DestInfo As IntPtr   ' RTM_DEST_INFO* in/out
) As UInteger
End Function
' RtmRegHandle : INT_PTR
' DestHandle : INT_PTR
' ProtocolId : DWORD
' TargetViews : DWORD
' DestInfo : RTM_DEST_INFO* in/out
Declare PtrSafe Function RtmGetLessSpecificDestination Lib "rtm" ( _
    ByVal RtmRegHandle As LongPtr, _
    ByVal DestHandle As LongPtr, _
    ByVal ProtocolId As Long, _
    ByVal TargetViews As Long, _
    ByVal DestInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtmGetLessSpecificDestination = ctypes.windll.rtm.RtmGetLessSpecificDestination
RtmGetLessSpecificDestination.restype = wintypes.DWORD
RtmGetLessSpecificDestination.argtypes = [
    ctypes.c_ssize_t,  # RtmRegHandle : INT_PTR
    ctypes.c_ssize_t,  # DestHandle : INT_PTR
    wintypes.DWORD,  # ProtocolId : DWORD
    wintypes.DWORD,  # TargetViews : DWORD
    ctypes.c_void_p,  # DestInfo : RTM_DEST_INFO* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('rtm.dll')
RtmGetLessSpecificDestination = Fiddle::Function.new(
  lib['RtmGetLessSpecificDestination'],
  [
    Fiddle::TYPE_INTPTR_T,  # RtmRegHandle : INT_PTR
    Fiddle::TYPE_INTPTR_T,  # DestHandle : INT_PTR
    -Fiddle::TYPE_INT,  # ProtocolId : DWORD
    -Fiddle::TYPE_INT,  # TargetViews : DWORD
    Fiddle::TYPE_VOIDP,  # DestInfo : RTM_DEST_INFO* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "rtm")]
extern "system" {
    fn RtmGetLessSpecificDestination(
        RtmRegHandle: isize,  // INT_PTR
        DestHandle: isize,  // INT_PTR
        ProtocolId: u32,  // DWORD
        TargetViews: u32,  // DWORD
        DestInfo: *mut RTM_DEST_INFO  // RTM_DEST_INFO* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("rtm.dll")]
public static extern uint RtmGetLessSpecificDestination(IntPtr RtmRegHandle, IntPtr DestHandle, uint ProtocolId, uint TargetViews, IntPtr DestInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'rtm_RtmGetLessSpecificDestination' -Namespace Win32 -PassThru
# $api::RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
#uselib "rtm.dll"
#func global RtmGetLessSpecificDestination "RtmGetLessSpecificDestination" sptr, sptr, sptr, sptr, sptr
; RtmGetLessSpecificDestination RtmRegHandle, DestHandle, ProtocolId, TargetViews, varptr(DestInfo)   ; 戻り値は stat
; RtmRegHandle : INT_PTR -> "sptr"
; DestHandle : INT_PTR -> "sptr"
; ProtocolId : DWORD -> "sptr"
; TargetViews : DWORD -> "sptr"
; DestInfo : RTM_DEST_INFO* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "rtm.dll"
#cfunc global RtmGetLessSpecificDestination "RtmGetLessSpecificDestination" sptr, sptr, int, int, var
; res = RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
; RtmRegHandle : INT_PTR -> "sptr"
; DestHandle : INT_PTR -> "sptr"
; ProtocolId : DWORD -> "int"
; TargetViews : DWORD -> "int"
; DestInfo : RTM_DEST_INFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD RtmGetLessSpecificDestination(INT_PTR RtmRegHandle, INT_PTR DestHandle, DWORD ProtocolId, DWORD TargetViews, RTM_DEST_INFO* DestInfo)
#uselib "rtm.dll"
#cfunc global RtmGetLessSpecificDestination "RtmGetLessSpecificDestination" intptr, intptr, int, int, var
; res = RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
; RtmRegHandle : INT_PTR -> "intptr"
; DestHandle : INT_PTR -> "intptr"
; ProtocolId : DWORD -> "int"
; TargetViews : DWORD -> "int"
; DestInfo : RTM_DEST_INFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	rtm = windows.NewLazySystemDLL("rtm.dll")
	procRtmGetLessSpecificDestination = rtm.NewProc("RtmGetLessSpecificDestination")
)

// RtmRegHandle (INT_PTR), DestHandle (INT_PTR), ProtocolId (DWORD), TargetViews (DWORD), DestInfo (RTM_DEST_INFO* in/out)
r1, _, err := procRtmGetLessSpecificDestination.Call(
	uintptr(RtmRegHandle),
	uintptr(DestHandle),
	uintptr(ProtocolId),
	uintptr(TargetViews),
	uintptr(DestInfo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RtmGetLessSpecificDestination(
  RtmRegHandle: NativeInt;   // INT_PTR
  DestHandle: NativeInt;   // INT_PTR
  ProtocolId: DWORD;   // DWORD
  TargetViews: DWORD;   // DWORD
  DestInfo: Pointer   // RTM_DEST_INFO* in/out
): DWORD; stdcall;
  external 'rtm.dll' name 'RtmGetLessSpecificDestination';
result := DllCall("rtm\RtmGetLessSpecificDestination"
    , "Ptr", RtmRegHandle   ; INT_PTR
    , "Ptr", DestHandle   ; INT_PTR
    , "UInt", ProtocolId   ; DWORD
    , "UInt", TargetViews   ; DWORD
    , "Ptr", DestInfo   ; RTM_DEST_INFO* in/out
    , "UInt")   ; return: DWORD
●RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo) = DLL("rtm.dll", "dword RtmGetLessSpecificDestination(int, int, dword, dword, void*)")
# 呼び出し: RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
# RtmRegHandle : INT_PTR -> "int"
# DestHandle : INT_PTR -> "int"
# ProtocolId : DWORD -> "dword"
# TargetViews : DWORD -> "dword"
# DestInfo : RTM_DEST_INFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "rtm" fn RtmGetLessSpecificDestination(
    RtmRegHandle: isize, // INT_PTR
    DestHandle: isize, // INT_PTR
    ProtocolId: u32, // DWORD
    TargetViews: u32, // DWORD
    DestInfo: [*c]RTM_DEST_INFO // RTM_DEST_INFO* in/out
) callconv(std.os.windows.WINAPI) u32;
proc RtmGetLessSpecificDestination(
    RtmRegHandle: int,  # INT_PTR
    DestHandle: int,  # INT_PTR
    ProtocolId: uint32,  # DWORD
    TargetViews: uint32,  # DWORD
    DestInfo: ptr RTM_DEST_INFO  # RTM_DEST_INFO* in/out
): uint32 {.importc: "RtmGetLessSpecificDestination", stdcall, dynlib: "rtm.dll".}
pragma(lib, "rtm");
extern(Windows)
uint RtmGetLessSpecificDestination(
    ptrdiff_t RtmRegHandle,   // INT_PTR
    ptrdiff_t DestHandle,   // INT_PTR
    uint ProtocolId,   // DWORD
    uint TargetViews,   // DWORD
    RTM_DEST_INFO* DestInfo   // RTM_DEST_INFO* in/out
);
ccall((:RtmGetLessSpecificDestination, "rtm.dll"), stdcall, UInt32,
      (Int, Int, UInt32, UInt32, Ptr{RTM_DEST_INFO}),
      RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
# RtmRegHandle : INT_PTR -> Int
# DestHandle : INT_PTR -> Int
# ProtocolId : DWORD -> UInt32
# TargetViews : DWORD -> UInt32
# DestInfo : RTM_DEST_INFO* in/out -> Ptr{RTM_DEST_INFO}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t RtmGetLessSpecificDestination(
    intptr_t RtmRegHandle,
    intptr_t DestHandle,
    uint32_t ProtocolId,
    uint32_t TargetViews,
    void* DestInfo);
]]
local rtm = ffi.load("rtm")
-- rtm.RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
-- RtmRegHandle : INT_PTR
-- DestHandle : INT_PTR
-- ProtocolId : DWORD
-- TargetViews : DWORD
-- DestInfo : RTM_DEST_INFO* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('rtm.dll');
const RtmGetLessSpecificDestination = lib.func('__stdcall', 'RtmGetLessSpecificDestination', 'uint32_t', ['intptr_t', 'intptr_t', 'uint32_t', 'uint32_t', 'void *']);
// RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
// RtmRegHandle : INT_PTR -> 'intptr_t'
// DestHandle : INT_PTR -> 'intptr_t'
// ProtocolId : DWORD -> 'uint32_t'
// TargetViews : DWORD -> 'uint32_t'
// DestInfo : RTM_DEST_INFO* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("rtm.dll", {
  RtmGetLessSpecificDestination: { parameters: ["isize", "isize", "u32", "u32", "pointer"], result: "u32" },
});
// lib.symbols.RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo)
// RtmRegHandle : INT_PTR -> "isize"
// DestHandle : INT_PTR -> "isize"
// ProtocolId : DWORD -> "u32"
// TargetViews : DWORD -> "u32"
// DestInfo : RTM_DEST_INFO* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t RtmGetLessSpecificDestination(
    intptr_t RtmRegHandle,
    intptr_t DestHandle,
    uint32_t ProtocolId,
    uint32_t TargetViews,
    void* DestInfo);
C, "rtm.dll");
// $ffi->RtmGetLessSpecificDestination(RtmRegHandle, DestHandle, ProtocolId, TargetViews, DestInfo);
// RtmRegHandle : INT_PTR
// DestHandle : INT_PTR
// ProtocolId : DWORD
// TargetViews : DWORD
// DestInfo : RTM_DEST_INFO* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Rtm extends StdCallLibrary {
    Rtm INSTANCE = Native.load("rtm", Rtm.class);
    int RtmGetLessSpecificDestination(
        long RtmRegHandle,   // INT_PTR
        long DestHandle,   // INT_PTR
        int ProtocolId,   // DWORD
        int TargetViews,   // DWORD
        Pointer DestInfo   // RTM_DEST_INFO* in/out
    );
}
@[Link("rtm")]
lib Librtm
  fun RtmGetLessSpecificDestination = RtmGetLessSpecificDestination(
    RtmRegHandle : LibC::SSizeT,   # INT_PTR
    DestHandle : LibC::SSizeT,   # INT_PTR
    ProtocolId : UInt32,   # DWORD
    TargetViews : UInt32,   # DWORD
    DestInfo : RTM_DEST_INFO*   # RTM_DEST_INFO* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RtmGetLessSpecificDestinationNative = Uint32 Function(IntPtr, IntPtr, Uint32, Uint32, Pointer<Void>);
typedef RtmGetLessSpecificDestinationDart = int Function(int, int, int, int, Pointer<Void>);
final RtmGetLessSpecificDestination = DynamicLibrary.open('rtm.dll')
    .lookupFunction<RtmGetLessSpecificDestinationNative, RtmGetLessSpecificDestinationDart>('RtmGetLessSpecificDestination');
// RtmRegHandle : INT_PTR -> IntPtr
// DestHandle : INT_PTR -> IntPtr
// ProtocolId : DWORD -> Uint32
// TargetViews : DWORD -> Uint32
// DestInfo : RTM_DEST_INFO* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RtmGetLessSpecificDestination(
  RtmRegHandle: NativeInt;   // INT_PTR
  DestHandle: NativeInt;   // INT_PTR
  ProtocolId: DWORD;   // DWORD
  TargetViews: DWORD;   // DWORD
  DestInfo: Pointer   // RTM_DEST_INFO* in/out
): DWORD; stdcall;
  external 'rtm.dll' name 'RtmGetLessSpecificDestination';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RtmGetLessSpecificDestination"
  c_RtmGetLessSpecificDestination :: CIntPtr -> CIntPtr -> Word32 -> Word32 -> Ptr () -> IO Word32
-- RtmRegHandle : INT_PTR -> CIntPtr
-- DestHandle : INT_PTR -> CIntPtr
-- ProtocolId : DWORD -> Word32
-- TargetViews : DWORD -> Word32
-- DestInfo : RTM_DEST_INFO* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rtmgetlessspecificdestination =
  foreign "RtmGetLessSpecificDestination"
    (intptr_t @-> intptr_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* RtmRegHandle : INT_PTR -> intptr_t *)
(* DestHandle : INT_PTR -> intptr_t *)
(* ProtocolId : DWORD -> uint32_t *)
(* TargetViews : DWORD -> uint32_t *)
(* DestInfo : RTM_DEST_INFO* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library rtm (t "rtm.dll"))
(cffi:use-foreign-library rtm)

(cffi:defcfun ("RtmGetLessSpecificDestination" rtm-get-less-specific-destination :convention :stdcall) :uint32
  (rtm-reg-handle :int64)   ; INT_PTR
  (dest-handle :int64)   ; INT_PTR
  (protocol-id :uint32)   ; DWORD
  (target-views :uint32)   ; DWORD
  (dest-info :pointer))   ; RTM_DEST_INFO* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RtmGetLessSpecificDestination = Win32::API::More->new('rtm',
    'DWORD RtmGetLessSpecificDestination(LPARAM RtmRegHandle, LPARAM DestHandle, DWORD ProtocolId, DWORD TargetViews, LPVOID DestInfo)');
# my $ret = $RtmGetLessSpecificDestination->Call($RtmRegHandle, $DestHandle, $ProtocolId, $TargetViews, $DestInfo);
# RtmRegHandle : INT_PTR -> LPARAM
# DestHandle : INT_PTR -> LPARAM
# ProtocolId : DWORD -> DWORD
# TargetViews : DWORD -> DWORD
# DestInfo : RTM_DEST_INFO* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型