ホーム › NetworkManagement.IpHelper › PfBindInterfaceToIndex
PfBindInterfaceToIndex
関数パケットフィルタインターフェイスをインターフェイスインデックスにバインドする。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
DWORD PfBindInterfaceToIndex(
void* pInterface,
DWORD dwIndex,
PFADDRESSTYPE pfatLinkType,
BYTE* LinkIPAddress
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pInterface | void* | inout |
| dwIndex | DWORD | in |
| pfatLinkType | PFADDRESSTYPE | in |
| LinkIPAddress | BYTE* | inout |
戻り値の型: DWORD
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
DWORD PfBindInterfaceToIndex(
void* pInterface,
DWORD dwIndex,
PFADDRESSTYPE pfatLinkType,
BYTE* LinkIPAddress
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint PfBindInterfaceToIndex(
IntPtr pInterface, // void* in/out
uint dwIndex, // DWORD
int pfatLinkType, // PFADDRESSTYPE
IntPtr LinkIPAddress // BYTE* in/out
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function PfBindInterfaceToIndex(
pInterface As IntPtr, ' void* in/out
dwIndex As UInteger, ' DWORD
pfatLinkType As Integer, ' PFADDRESSTYPE
LinkIPAddress As IntPtr ' BYTE* in/out
) As UInteger
End Function' pInterface : void* in/out
' dwIndex : DWORD
' pfatLinkType : PFADDRESSTYPE
' LinkIPAddress : BYTE* in/out
Declare PtrSafe Function PfBindInterfaceToIndex Lib "iphlpapi" ( _
ByVal pInterface As LongPtr, _
ByVal dwIndex As Long, _
ByVal pfatLinkType As Long, _
ByVal LinkIPAddress As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PfBindInterfaceToIndex = ctypes.windll.iphlpapi.PfBindInterfaceToIndex
PfBindInterfaceToIndex.restype = wintypes.DWORD
PfBindInterfaceToIndex.argtypes = [
ctypes.POINTER(None), # pInterface : void* in/out
wintypes.DWORD, # dwIndex : DWORD
ctypes.c_int, # pfatLinkType : PFADDRESSTYPE
ctypes.POINTER(ctypes.c_ubyte), # LinkIPAddress : BYTE* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
PfBindInterfaceToIndex = Fiddle::Function.new(
lib['PfBindInterfaceToIndex'],
[
Fiddle::TYPE_VOIDP, # pInterface : void* in/out
-Fiddle::TYPE_INT, # dwIndex : DWORD
Fiddle::TYPE_INT, # pfatLinkType : PFADDRESSTYPE
Fiddle::TYPE_VOIDP, # LinkIPAddress : BYTE* in/out
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn PfBindInterfaceToIndex(
pInterface: *mut (), // void* in/out
dwIndex: u32, // DWORD
pfatLinkType: i32, // PFADDRESSTYPE
LinkIPAddress: *mut u8 // BYTE* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint PfBindInterfaceToIndex(IntPtr pInterface, uint dwIndex, int pfatLinkType, IntPtr LinkIPAddress);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_PfBindInterfaceToIndex' -Namespace Win32 -PassThru
# $api::PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress)#uselib "IPHLPAPI.dll"
#func global PfBindInterfaceToIndex "PfBindInterfaceToIndex" sptr, sptr, sptr, sptr
; PfBindInterfaceToIndex pInterface, dwIndex, pfatLinkType, varptr(LinkIPAddress) ; 戻り値は stat
; pInterface : void* in/out -> "sptr"
; dwIndex : DWORD -> "sptr"
; pfatLinkType : PFADDRESSTYPE -> "sptr"
; LinkIPAddress : BYTE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIndex "PfBindInterfaceToIndex" sptr, int, int, var ; res = PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress) ; pInterface : void* in/out -> "sptr" ; dwIndex : DWORD -> "int" ; pfatLinkType : PFADDRESSTYPE -> "int" ; LinkIPAddress : BYTE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIndex "PfBindInterfaceToIndex" sptr, int, int, sptr ; res = PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, varptr(LinkIPAddress)) ; pInterface : void* in/out -> "sptr" ; dwIndex : DWORD -> "int" ; pfatLinkType : PFADDRESSTYPE -> "int" ; LinkIPAddress : BYTE* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD PfBindInterfaceToIndex(void* pInterface, DWORD dwIndex, PFADDRESSTYPE pfatLinkType, BYTE* LinkIPAddress) #uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIndex "PfBindInterfaceToIndex" intptr, int, int, var ; res = PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress) ; pInterface : void* in/out -> "intptr" ; dwIndex : DWORD -> "int" ; pfatLinkType : PFADDRESSTYPE -> "int" ; LinkIPAddress : BYTE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PfBindInterfaceToIndex(void* pInterface, DWORD dwIndex, PFADDRESSTYPE pfatLinkType, BYTE* LinkIPAddress) #uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIndex "PfBindInterfaceToIndex" intptr, int, int, intptr ; res = PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, varptr(LinkIPAddress)) ; pInterface : void* in/out -> "intptr" ; dwIndex : DWORD -> "int" ; pfatLinkType : PFADDRESSTYPE -> "int" ; LinkIPAddress : BYTE* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procPfBindInterfaceToIndex = iphlpapi.NewProc("PfBindInterfaceToIndex")
)
// pInterface (void* in/out), dwIndex (DWORD), pfatLinkType (PFADDRESSTYPE), LinkIPAddress (BYTE* in/out)
r1, _, err := procPfBindInterfaceToIndex.Call(
uintptr(pInterface),
uintptr(dwIndex),
uintptr(pfatLinkType),
uintptr(LinkIPAddress),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PfBindInterfaceToIndex(
pInterface: Pointer; // void* in/out
dwIndex: DWORD; // DWORD
pfatLinkType: Integer; // PFADDRESSTYPE
LinkIPAddress: Pointer // BYTE* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'PfBindInterfaceToIndex';result := DllCall("IPHLPAPI\PfBindInterfaceToIndex"
, "Ptr", pInterface ; void* in/out
, "UInt", dwIndex ; DWORD
, "Int", pfatLinkType ; PFADDRESSTYPE
, "Ptr", LinkIPAddress ; BYTE* in/out
, "UInt") ; return: DWORD●PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress) = DLL("IPHLPAPI.dll", "dword PfBindInterfaceToIndex(void*, dword, int, void*)")
# 呼び出し: PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress)
# pInterface : void* in/out -> "void*"
# dwIndex : DWORD -> "dword"
# pfatLinkType : PFADDRESSTYPE -> "int"
# LinkIPAddress : BYTE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。