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

RTM_NEXTHOP_INFO

構造体
サイズx64: 56 バイト / x86: 40 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
NextHopAddressRTM_NET_ADDRESS20+0+0ネクストホップのネットワークアドレス(RTM_NET_ADDRESS)。
NextHopOwnerINT_PTR8/4+24+20このネクストホップを所有するエンティティのハンドル。
InterfaceIndexDWORD4+32+24ネクストホップへ到達するための送出インターフェイスインデックス。
StateWORD2+36+28ネクストホップの状態を表すWORD値。
FlagsWORD2+38+30ネクストホップの属性を示すWORDフラグ。
EntitySpecificInfovoid*8/4+40+32プロトコル固有の情報へのポインタ。NULL可。
RemoteNextHopINT_PTR8/4+48+36リモートネクストホップを識別するハンドル。

各言語での定義

#include <windows.h>

// RTM_NET_ADDRESS  (x64 20 / x86 20 バイト)
typedef struct RTM_NET_ADDRESS {
    WORD AddressFamily;
    WORD NumBits;
    BYTE AddrBits[16];
} RTM_NET_ADDRESS;

// RTM_NEXTHOP_INFO  (x64 56 / x86 40 バイト)
typedef struct RTM_NEXTHOP_INFO {
    RTM_NET_ADDRESS NextHopAddress;
    INT_PTR NextHopOwner;
    DWORD InterfaceIndex;
    WORD State;
    WORD Flags;
    void* EntitySpecificInfo;
    INT_PTR RemoteNextHop;
} RTM_NEXTHOP_INFO;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct RTM_NET_ADDRESS
{
    public ushort AddressFamily;
    public ushort NumBits;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] AddrBits;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct RTM_NEXTHOP_INFO
{
    public RTM_NET_ADDRESS NextHopAddress;
    public IntPtr NextHopOwner;
    public uint InterfaceIndex;
    public ushort State;
    public ushort Flags;
    public IntPtr EntitySpecificInfo;
    public IntPtr RemoteNextHop;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure RTM_NET_ADDRESS
    Public AddressFamily As UShort
    Public NumBits As UShort
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public AddrBits() As Byte
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure RTM_NEXTHOP_INFO
    Public NextHopAddress As RTM_NET_ADDRESS
    Public NextHopOwner As IntPtr
    Public InterfaceIndex As UInteger
    Public State As UShort
    Public Flags As UShort
    Public EntitySpecificInfo As IntPtr
    Public RemoteNextHop As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class RTM_NET_ADDRESS(ctypes.Structure):
    _fields_ = [
        ("AddressFamily", ctypes.c_ushort),
        ("NumBits", ctypes.c_ushort),
        ("AddrBits", ctypes.c_ubyte * 16),
    ]

class RTM_NEXTHOP_INFO(ctypes.Structure):
    _fields_ = [
        ("NextHopAddress", RTM_NET_ADDRESS),
        ("NextHopOwner", ctypes.c_ssize_t),
        ("InterfaceIndex", wintypes.DWORD),
        ("State", ctypes.c_ushort),
        ("Flags", ctypes.c_ushort),
        ("EntitySpecificInfo", ctypes.c_void_p),
        ("RemoteNextHop", ctypes.c_ssize_t),
    ]
#[repr(C)]
pub struct RTM_NET_ADDRESS {
    pub AddressFamily: u16,
    pub NumBits: u16,
    pub AddrBits: [u8; 16],
}

#[repr(C)]
pub struct RTM_NEXTHOP_INFO {
    pub NextHopAddress: RTM_NET_ADDRESS,
    pub NextHopOwner: isize,
    pub InterfaceIndex: u32,
    pub State: u16,
    pub Flags: u16,
    pub EntitySpecificInfo: *mut core::ffi::c_void,
    pub RemoteNextHop: isize,
}
import "golang.org/x/sys/windows"

type RTM_NET_ADDRESS struct {
	AddressFamily uint16
	NumBits uint16
	AddrBits [16]byte
}

type RTM_NEXTHOP_INFO struct {
	NextHopAddress RTM_NET_ADDRESS
	NextHopOwner uintptr
	InterfaceIndex uint32
	State uint16
	Flags uint16
	EntitySpecificInfo uintptr
	RemoteNextHop uintptr
}
type
  RTM_NET_ADDRESS = record
    AddressFamily: Word;
    NumBits: Word;
    AddrBits: array[0..15] of Byte;
  end;

  RTM_NEXTHOP_INFO = record
    NextHopAddress: RTM_NET_ADDRESS;
    NextHopOwner: NativeInt;
    InterfaceIndex: DWORD;
    State: Word;
    Flags: Word;
    EntitySpecificInfo: Pointer;
    RemoteNextHop: NativeInt;
  end;
const RTM_NET_ADDRESS = extern struct {
    AddressFamily: u16,
    NumBits: u16,
    AddrBits: [16]u8,
};

const RTM_NEXTHOP_INFO = extern struct {
    NextHopAddress: RTM_NET_ADDRESS,
    NextHopOwner: isize,
    InterfaceIndex: u32,
    State: u16,
    Flags: u16,
    EntitySpecificInfo: ?*anyopaque,
    RemoteNextHop: isize,
};
type
  RTM_NET_ADDRESS {.bycopy.} = object
    AddressFamily: uint16
    NumBits: uint16
    AddrBits: array[16, uint8]

  RTM_NEXTHOP_INFO {.bycopy.} = object
    NextHopAddress: RTM_NET_ADDRESS
    NextHopOwner: int
    InterfaceIndex: uint32
    State: uint16
    Flags: uint16
    EntitySpecificInfo: pointer
    RemoteNextHop: int
struct RTM_NET_ADDRESS
{
    ushort AddressFamily;
    ushort NumBits;
    ubyte[16] AddrBits;
}

struct RTM_NEXTHOP_INFO
{
    RTM_NET_ADDRESS NextHopAddress;
    ptrdiff_t NextHopOwner;
    uint InterfaceIndex;
    ushort State;
    ushort Flags;
    void* EntitySpecificInfo;
    ptrdiff_t RemoteNextHop;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; RTM_NEXTHOP_INFO サイズ: 40 バイト(x86)
dim st, 10    ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; NextHopAddress : RTM_NET_ADDRESS (+0, 20byte)  varptr(st)+0 を基点に操作(20byte:入れ子/配列)
; NextHopOwner : INT_PTR (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; InterfaceIndex : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; State : WORD (+28, 2byte)  wpoke st,28,値  /  値 = wpeek(st,28)
; Flags : WORD (+30, 2byte)  wpoke st,30,値  /  値 = wpeek(st,30)
; EntitySpecificInfo : void* (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; RemoteNextHop : INT_PTR (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; RTM_NEXTHOP_INFO サイズ: 56 バイト(x64)
dim st, 14    ; 4byte整数×14(構造体サイズ 56 / 4 切り上げ)
; NextHopAddress : RTM_NET_ADDRESS (+0, 20byte)  varptr(st)+0 を基点に操作(20byte:入れ子/配列)
; NextHopOwner : INT_PTR (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; InterfaceIndex : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; State : WORD (+36, 2byte)  wpoke st,36,値  /  値 = wpeek(st,36)
; Flags : WORD (+38, 2byte)  wpoke st,38,値  /  値 = wpeek(st,38)
; EntitySpecificInfo : void* (+40, 8byte)  qpoke st,40,値 / qpeek(st,40)  ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; RemoteNextHop : INT_PTR (+48, 8byte)  qpoke st,48,値 / qpeek(st,48)  ※IronHSPのみ。3.7/3.8は lpoke st,48,下位 : lpoke st,52,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global RTM_NET_ADDRESS
    #field short AddressFamily
    #field short NumBits
    #field byte AddrBits 16
#endstruct

#defstruct global RTM_NEXTHOP_INFO
    #field RTM_NET_ADDRESS NextHopAddress
    #field intptr NextHopOwner
    #field int InterfaceIndex
    #field short State
    #field short Flags
    #field intptr EntitySpecificInfo
    #field intptr RemoteNextHop
#endstruct

stdim st, RTM_NEXTHOP_INFO        ; NSTRUCT 変数を確保
st->NextHopOwner = 100
mes "NextHopOwner=" + st->NextHopOwner