ホーム › 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 | リンクのアドレス種別(PFADDRESSTYPE、IPv4/IPv6など)。 |
| LinkIPAddress | BYTE* | inout | リンクのIPアドレスを格納したバイト配列へのポインタ。 |
戻り値の型: 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)。const std = @import("std");
extern "iphlpapi" fn PfBindInterfaceToIndex(
pInterface: ?*anyopaque, // void* in/out
dwIndex: u32, // DWORD
pfatLinkType: i32, // PFADDRESSTYPE
LinkIPAddress: [*c]u8 // BYTE* in/out
) callconv(std.os.windows.WINAPI) u32;proc PfBindInterfaceToIndex(
pInterface: pointer, # void* in/out
dwIndex: uint32, # DWORD
pfatLinkType: int32, # PFADDRESSTYPE
LinkIPAddress: ptr uint8 # BYTE* in/out
): uint32 {.importc: "PfBindInterfaceToIndex", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint PfBindInterfaceToIndex(
void* pInterface, // void* in/out
uint dwIndex, // DWORD
int pfatLinkType, // PFADDRESSTYPE
ubyte* LinkIPAddress // BYTE* in/out
);ccall((:PfBindInterfaceToIndex, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32, Int32, Ptr{UInt8}),
pInterface, dwIndex, pfatLinkType, LinkIPAddress)
# pInterface : void* in/out -> Ptr{Cvoid}
# dwIndex : DWORD -> UInt32
# pfatLinkType : PFADDRESSTYPE -> Int32
# LinkIPAddress : BYTE* in/out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PfBindInterfaceToIndex(
void* pInterface,
uint32_t dwIndex,
int32_t pfatLinkType,
uint8_t* LinkIPAddress);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress)
-- pInterface : void* in/out
-- dwIndex : DWORD
-- pfatLinkType : PFADDRESSTYPE
-- LinkIPAddress : BYTE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const PfBindInterfaceToIndex = lib.func('__stdcall', 'PfBindInterfaceToIndex', 'uint32_t', ['void *', 'uint32_t', 'int32_t', 'uint8_t *']);
// PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress)
// pInterface : void* in/out -> 'void *'
// dwIndex : DWORD -> 'uint32_t'
// pfatLinkType : PFADDRESSTYPE -> 'int32_t'
// LinkIPAddress : BYTE* in/out -> 'uint8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
PfBindInterfaceToIndex: { parameters: ["pointer", "u32", "i32", "pointer"], result: "u32" },
});
// lib.symbols.PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress)
// pInterface : void* in/out -> "pointer"
// dwIndex : DWORD -> "u32"
// pfatLinkType : PFADDRESSTYPE -> "i32"
// LinkIPAddress : BYTE* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PfBindInterfaceToIndex(
void* pInterface,
uint32_t dwIndex,
int32_t pfatLinkType,
uint8_t* LinkIPAddress);
C, "IPHLPAPI.dll");
// $ffi->PfBindInterfaceToIndex(pInterface, dwIndex, pfatLinkType, LinkIPAddress);
// pInterface : void* in/out
// dwIndex : DWORD
// pfatLinkType : PFADDRESSTYPE
// LinkIPAddress : BYTE* 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 Iphlpapi extends StdCallLibrary {
Iphlpapi INSTANCE = Native.load("iphlpapi", Iphlpapi.class);
int PfBindInterfaceToIndex(
Pointer pInterface, // void* in/out
int dwIndex, // DWORD
int pfatLinkType, // PFADDRESSTYPE
byte[] LinkIPAddress // BYTE* in/out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun PfBindInterfaceToIndex = PfBindInterfaceToIndex(
pInterface : Void*, # void* in/out
dwIndex : UInt32, # DWORD
pfatLinkType : Int32, # PFADDRESSTYPE
LinkIPAddress : UInt8* # BYTE* 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 PfBindInterfaceToIndexNative = Uint32 Function(Pointer<Void>, Uint32, Int32, Pointer<Uint8>);
typedef PfBindInterfaceToIndexDart = int Function(Pointer<Void>, int, int, Pointer<Uint8>);
final PfBindInterfaceToIndex = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<PfBindInterfaceToIndexNative, PfBindInterfaceToIndexDart>('PfBindInterfaceToIndex');
// pInterface : void* in/out -> Pointer<Void>
// dwIndex : DWORD -> Uint32
// pfatLinkType : PFADDRESSTYPE -> Int32
// LinkIPAddress : BYTE* in/out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PfBindInterfaceToIndex(
pInterface: Pointer; // void* in/out
dwIndex: DWORD; // DWORD
pfatLinkType: Integer; // PFADDRESSTYPE
LinkIPAddress: Pointer // BYTE* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'PfBindInterfaceToIndex';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PfBindInterfaceToIndex"
c_PfBindInterfaceToIndex :: Ptr () -> Word32 -> Int32 -> Ptr Word8 -> IO Word32
-- pInterface : void* in/out -> Ptr ()
-- dwIndex : DWORD -> Word32
-- pfatLinkType : PFADDRESSTYPE -> Int32
-- LinkIPAddress : BYTE* in/out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pfbindinterfacetoindex =
foreign "PfBindInterfaceToIndex"
((ptr void) @-> uint32_t @-> int32_t @-> (ptr uint8_t) @-> returning uint32_t)
(* pInterface : void* in/out -> (ptr void) *)
(* dwIndex : DWORD -> uint32_t *)
(* pfatLinkType : PFADDRESSTYPE -> int32_t *)
(* LinkIPAddress : BYTE* in/out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("PfBindInterfaceToIndex" pf-bind-interface-to-index :convention :stdcall) :uint32
(p-interface :pointer) ; void* in/out
(dw-index :uint32) ; DWORD
(pfat-link-type :int32) ; PFADDRESSTYPE
(link-ipaddress :pointer)) ; BYTE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PfBindInterfaceToIndex = Win32::API::More->new('IPHLPAPI',
'DWORD PfBindInterfaceToIndex(LPVOID pInterface, DWORD dwIndex, int pfatLinkType, LPVOID LinkIPAddress)');
# my $ret = $PfBindInterfaceToIndex->Call($pInterface, $dwIndex, $pfatLinkType, $LinkIPAddress);
# pInterface : void* in/out -> LPVOID
# dwIndex : DWORD -> DWORD
# pfatLinkType : PFADDRESSTYPE -> int
# LinkIPAddress : BYTE* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型