ホーム › NetworkManagement.IpHelper › PfBindInterfaceToIPAddress
PfBindInterfaceToIPAddress
関数パケットフィルタインターフェイスをIPアドレスにバインドする。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
DWORD PfBindInterfaceToIPAddress(
void* pInterface,
PFADDRESSTYPE pfatType,
BYTE* IPAddress
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pInterface | void* | inout | バインドする対象インターフェースのハンドル。 |
| pfatType | PFADDRESSTYPE | in | IPアドレスの種別(PFADDRESSTYPE、IPv4/IPv6など)。 |
| IPAddress | BYTE* | inout | バインド先のIPアドレスを格納したバイト配列へのポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
DWORD PfBindInterfaceToIPAddress(
void* pInterface,
PFADDRESSTYPE pfatType,
BYTE* IPAddress
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint PfBindInterfaceToIPAddress(
IntPtr pInterface, // void* in/out
int pfatType, // PFADDRESSTYPE
IntPtr IPAddress // BYTE* in/out
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function PfBindInterfaceToIPAddress(
pInterface As IntPtr, ' void* in/out
pfatType As Integer, ' PFADDRESSTYPE
IPAddress As IntPtr ' BYTE* in/out
) As UInteger
End Function' pInterface : void* in/out
' pfatType : PFADDRESSTYPE
' IPAddress : BYTE* in/out
Declare PtrSafe Function PfBindInterfaceToIPAddress Lib "iphlpapi" ( _
ByVal pInterface As LongPtr, _
ByVal pfatType As Long, _
ByVal IPAddress As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PfBindInterfaceToIPAddress = ctypes.windll.iphlpapi.PfBindInterfaceToIPAddress
PfBindInterfaceToIPAddress.restype = wintypes.DWORD
PfBindInterfaceToIPAddress.argtypes = [
ctypes.POINTER(None), # pInterface : void* in/out
ctypes.c_int, # pfatType : PFADDRESSTYPE
ctypes.POINTER(ctypes.c_ubyte), # IPAddress : BYTE* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
PfBindInterfaceToIPAddress = Fiddle::Function.new(
lib['PfBindInterfaceToIPAddress'],
[
Fiddle::TYPE_VOIDP, # pInterface : void* in/out
Fiddle::TYPE_INT, # pfatType : PFADDRESSTYPE
Fiddle::TYPE_VOIDP, # IPAddress : BYTE* in/out
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn PfBindInterfaceToIPAddress(
pInterface: *mut (), // void* in/out
pfatType: i32, // PFADDRESSTYPE
IPAddress: *mut u8 // BYTE* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint PfBindInterfaceToIPAddress(IntPtr pInterface, int pfatType, IntPtr IPAddress);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_PfBindInterfaceToIPAddress' -Namespace Win32 -PassThru
# $api::PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress)#uselib "IPHLPAPI.dll"
#func global PfBindInterfaceToIPAddress "PfBindInterfaceToIPAddress" sptr, sptr, sptr
; PfBindInterfaceToIPAddress pInterface, pfatType, varptr(IPAddress) ; 戻り値は stat
; pInterface : void* in/out -> "sptr"
; pfatType : PFADDRESSTYPE -> "sptr"
; IPAddress : BYTE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIPAddress "PfBindInterfaceToIPAddress" sptr, int, var ; res = PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress) ; pInterface : void* in/out -> "sptr" ; pfatType : PFADDRESSTYPE -> "int" ; IPAddress : BYTE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIPAddress "PfBindInterfaceToIPAddress" sptr, int, sptr ; res = PfBindInterfaceToIPAddress(pInterface, pfatType, varptr(IPAddress)) ; pInterface : void* in/out -> "sptr" ; pfatType : PFADDRESSTYPE -> "int" ; IPAddress : BYTE* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD PfBindInterfaceToIPAddress(void* pInterface, PFADDRESSTYPE pfatType, BYTE* IPAddress) #uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIPAddress "PfBindInterfaceToIPAddress" intptr, int, var ; res = PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress) ; pInterface : void* in/out -> "intptr" ; pfatType : PFADDRESSTYPE -> "int" ; IPAddress : BYTE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PfBindInterfaceToIPAddress(void* pInterface, PFADDRESSTYPE pfatType, BYTE* IPAddress) #uselib "IPHLPAPI.dll" #cfunc global PfBindInterfaceToIPAddress "PfBindInterfaceToIPAddress" intptr, int, intptr ; res = PfBindInterfaceToIPAddress(pInterface, pfatType, varptr(IPAddress)) ; pInterface : void* in/out -> "intptr" ; pfatType : PFADDRESSTYPE -> "int" ; IPAddress : BYTE* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procPfBindInterfaceToIPAddress = iphlpapi.NewProc("PfBindInterfaceToIPAddress")
)
// pInterface (void* in/out), pfatType (PFADDRESSTYPE), IPAddress (BYTE* in/out)
r1, _, err := procPfBindInterfaceToIPAddress.Call(
uintptr(pInterface),
uintptr(pfatType),
uintptr(IPAddress),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PfBindInterfaceToIPAddress(
pInterface: Pointer; // void* in/out
pfatType: Integer; // PFADDRESSTYPE
IPAddress: Pointer // BYTE* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'PfBindInterfaceToIPAddress';result := DllCall("IPHLPAPI\PfBindInterfaceToIPAddress"
, "Ptr", pInterface ; void* in/out
, "Int", pfatType ; PFADDRESSTYPE
, "Ptr", IPAddress ; BYTE* in/out
, "UInt") ; return: DWORD●PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress) = DLL("IPHLPAPI.dll", "dword PfBindInterfaceToIPAddress(void*, int, void*)")
# 呼び出し: PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress)
# pInterface : void* in/out -> "void*"
# pfatType : PFADDRESSTYPE -> "int"
# IPAddress : BYTE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn PfBindInterfaceToIPAddress(
pInterface: ?*anyopaque, // void* in/out
pfatType: i32, // PFADDRESSTYPE
IPAddress: [*c]u8 // BYTE* in/out
) callconv(std.os.windows.WINAPI) u32;proc PfBindInterfaceToIPAddress(
pInterface: pointer, # void* in/out
pfatType: int32, # PFADDRESSTYPE
IPAddress: ptr uint8 # BYTE* in/out
): uint32 {.importc: "PfBindInterfaceToIPAddress", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint PfBindInterfaceToIPAddress(
void* pInterface, // void* in/out
int pfatType, // PFADDRESSTYPE
ubyte* IPAddress // BYTE* in/out
);ccall((:PfBindInterfaceToIPAddress, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Int32, Ptr{UInt8}),
pInterface, pfatType, IPAddress)
# pInterface : void* in/out -> Ptr{Cvoid}
# pfatType : PFADDRESSTYPE -> Int32
# IPAddress : BYTE* in/out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PfBindInterfaceToIPAddress(
void* pInterface,
int32_t pfatType,
uint8_t* IPAddress);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress)
-- pInterface : void* in/out
-- pfatType : PFADDRESSTYPE
-- IPAddress : BYTE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const PfBindInterfaceToIPAddress = lib.func('__stdcall', 'PfBindInterfaceToIPAddress', 'uint32_t', ['void *', 'int32_t', 'uint8_t *']);
// PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress)
// pInterface : void* in/out -> 'void *'
// pfatType : PFADDRESSTYPE -> 'int32_t'
// IPAddress : BYTE* in/out -> 'uint8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
PfBindInterfaceToIPAddress: { parameters: ["pointer", "i32", "pointer"], result: "u32" },
});
// lib.symbols.PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress)
// pInterface : void* in/out -> "pointer"
// pfatType : PFADDRESSTYPE -> "i32"
// IPAddress : BYTE* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PfBindInterfaceToIPAddress(
void* pInterface,
int32_t pfatType,
uint8_t* IPAddress);
C, "IPHLPAPI.dll");
// $ffi->PfBindInterfaceToIPAddress(pInterface, pfatType, IPAddress);
// pInterface : void* in/out
// pfatType : PFADDRESSTYPE
// IPAddress : 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 PfBindInterfaceToIPAddress(
Pointer pInterface, // void* in/out
int pfatType, // PFADDRESSTYPE
byte[] IPAddress // BYTE* in/out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun PfBindInterfaceToIPAddress = PfBindInterfaceToIPAddress(
pInterface : Void*, # void* in/out
pfatType : Int32, # PFADDRESSTYPE
IPAddress : 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 PfBindInterfaceToIPAddressNative = Uint32 Function(Pointer<Void>, Int32, Pointer<Uint8>);
typedef PfBindInterfaceToIPAddressDart = int Function(Pointer<Void>, int, Pointer<Uint8>);
final PfBindInterfaceToIPAddress = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<PfBindInterfaceToIPAddressNative, PfBindInterfaceToIPAddressDart>('PfBindInterfaceToIPAddress');
// pInterface : void* in/out -> Pointer<Void>
// pfatType : PFADDRESSTYPE -> Int32
// IPAddress : BYTE* in/out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PfBindInterfaceToIPAddress(
pInterface: Pointer; // void* in/out
pfatType: Integer; // PFADDRESSTYPE
IPAddress: Pointer // BYTE* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'PfBindInterfaceToIPAddress';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PfBindInterfaceToIPAddress"
c_PfBindInterfaceToIPAddress :: Ptr () -> Int32 -> Ptr Word8 -> IO Word32
-- pInterface : void* in/out -> Ptr ()
-- pfatType : PFADDRESSTYPE -> Int32
-- IPAddress : BYTE* in/out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pfbindinterfacetoipaddress =
foreign "PfBindInterfaceToIPAddress"
((ptr void) @-> int32_t @-> (ptr uint8_t) @-> returning uint32_t)
(* pInterface : void* in/out -> (ptr void) *)
(* pfatType : PFADDRESSTYPE -> int32_t *)
(* IPAddress : 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 ("PfBindInterfaceToIPAddress" pf-bind-interface-to-ipaddress :convention :stdcall) :uint32
(p-interface :pointer) ; void* in/out
(pfat-type :int32) ; PFADDRESSTYPE
(ipaddress :pointer)) ; BYTE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PfBindInterfaceToIPAddress = Win32::API::More->new('IPHLPAPI',
'DWORD PfBindInterfaceToIPAddress(LPVOID pInterface, int pfatType, LPVOID IPAddress)');
# my $ret = $PfBindInterfaceToIPAddress->Call($pInterface, $pfatType, $IPAddress);
# pInterface : void* in/out -> LPVOID
# pfatType : PFADDRESSTYPE -> int
# IPAddress : BYTE* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型