NotifyTeredoPortChange
関数シグネチャ
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR NotifyTeredoPortChange(
PTEREDO_PORT_CHANGE_CALLBACK Callback,
void* CallerContext,
BOOLEAN InitialNotification,
HANDLE* NotificationHandle
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Callback | PTEREDO_PORT_CHANGE_CALLBACK | in | Teredo クライアントのポート変更が発生したときに呼び出す関数へのポインターです。この関数は、Teredo ポート変更通知を受信したときに呼び出されます。 |
| CallerContext | void* | in | Teredo ポート変更通知を受信したときに、Callback パラメーターで指定したコールバック関数に渡されるユーザーコンテキストです。 |
| InitialNotification | BOOLEAN | in | 変更通知の登録が完了した直後にコールバックを呼び出すかどうかを示す値です。この初期通知は、Teredo クライアントポートに変更が発生したことを示すものではありません。このパラメーターの目的は、コールバックが登録されたことを確認することにあります。 |
| NotificationHandle | HANDLE* | inout | 後で変更通知を解除するために使用できるハンドルを返すために用いるポインターです。成功した場合、このパラメーターに通知ハンドルが返されます。エラーが発生した場合は NULL が返されます。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ローカルコンピューター上で Teredo サービスポート用に Teredo クライアントが使用する UDP ポート番号の変更について通知を受け取るよう登録します。
戻り値
関数が成功した場合、戻り値は NO_ERROR です。
関数が失敗した場合、戻り値は次のいずれかのエラーコードになります。
| Return code | Description |
|---|---|
| 無効なハンドルが検出される内部エラーが発生しました。 | |
| 無効なパラメーターが関数に渡されました。このエラーは、Callback パラメーターが NULL ポインターの場合に返されます。 | |
| メモリが不足していました。 | |
|
返されたエラーのメッセージ文字列を取得するには、 FormatMessage を使用してください。 |
解説(Remarks)
NotifyTeredoPortChange 関数は Windows Vista 以降で定義されています。
GetTeredoPort 関数を使用すると、Teredo サービスポート用に Teredo クライアントが使用する初期 UDP ポート番号を取得できます。
Teredo ポートは動的であり、ローカルコンピューター上で Teredo クライアントが再起動されるたびに変更される可能性があります。アプリケーションは、NotifyTeredoPortChange 関数を呼び出すことで、Teredo サービスポートが変更されたときに通知を受け取るよう登録できます。
Callback パラメーターで指定したコールバック関数の呼び出しは直列化されます。コールバック関数は VOID 型の関数として定義する必要があります。コールバック関数に渡されるパラメーターには、次のものが含まれます。
| Parameter | Description |
|---|---|
| IN PVOID CallerContext | 通知の登録時に NotifyTeredoPortChange 関数に渡された CallerContext パラメーターです。 |
| IN USHORT Port | Teredo クライアントが現在使用している UDP ポート番号です。コールバック関数の NotificationType パラメーターに渡される MIB_NOTIFICATION_TYPE 値が MibInitialNotification に設定されている場合、このパラメーターは zero になります。これは、通知の登録時に NotifyTeredoPortChange に渡された InitialNotification パラメーターが TRUE に設定されていた場合にのみ発生します。 |
| IN MIB_NOTIFICATION_TYPE NotificationType | 通知の種類です。このメンバーには、Netioapi.h ヘッダーファイルで定義されている MIB_NOTIFICATION_TYPE 列挙型の値のいずれかを指定できます。 |
Callback パラメーターで指定したコールバック関数は、NotifyTeredoPortChange 関数を呼び出すアプリケーションと同じプロセス内に実装する必要があります。コールバック関数が別の DLL 内にある場合は、変更通知の登録のために NotifyTeredoPortChange 関数を呼び出す前に、その DLL を読み込んでおく必要があります。
NotifyTeredoPortChange 関数を呼び出して変更通知を登録すると、アプリケーションが変更通知の登録を解除するか、アプリケーションが終了するまで、これらの通知は送信され続けます。アプリケーションが終了した場合、システムは変更通知の登録を自動的に解除します。それでも、アプリケーションが終了する前に変更通知の登録を明示的に解除することをお勧めします。
変更通知の登録は、システムのシャットダウンや再起動をまたいで保持されることはありません。
変更通知の登録を解除するには、NotifyTeredoPortChange によって返された NotificationHandle パラメーターを渡して CancelMibChangeNotify2 関数を呼び出します。
アプリケーションは、同じ NotificationHandle パラメーターの通知コールバック関数を現在実行しているスレッドのコンテキストから CancelMibChangeNotify2 関数を呼び出すことはできません。これを行うと、そのコールバックを実行しているスレッドがデッドロックに陥ります。したがって、CancelMibChangeNotify2 関数を通知コールバックルーチンの一部として直接呼び出してはなりません。より一般的な状況として、CancelMibChangeNotify2 関数を実行するスレッドは、通知コールバック操作を実行するスレッドが待機するリソースを所有してはなりません。同様のデッドロックが発生するためです。CancelMibChangeNotify2 関数は、通知コールバックを受け取るスレッドが依存していない別のスレッドから呼び出す必要があります。
Teredo クライアントは、RFC 4380 で定義されているマルチキャスト IPv4 アドレス 224.0.0.253 に送信されるマルチキャストトラフィックをリッスンするために、静的 UDP ポート 3544 も使用します。詳細については、http://www.ietf.org/rfc/rfc4380.txt を参照してください。
NotifyTeredoPortChange 関数は、主にファイアウォールアプリケーションが、受信および送信の Teredo トラフィックを許可する適切な例外を構成するために使用されます。
NotifyStableUnicastIpAddressTable 関数は、主に Teredo クライアントを使用するアプリケーションによって使用されます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR NotifyTeredoPortChange(
PTEREDO_PORT_CHANGE_CALLBACK Callback,
void* CallerContext,
BOOLEAN InitialNotification,
HANDLE* NotificationHandle
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint NotifyTeredoPortChange(
IntPtr Callback, // PTEREDO_PORT_CHANGE_CALLBACK
IntPtr CallerContext, // void*
[MarshalAs(UnmanagedType.U1)] bool InitialNotification, // BOOLEAN
IntPtr NotificationHandle // HANDLE* in/out
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function NotifyTeredoPortChange(
Callback As IntPtr, ' PTEREDO_PORT_CHANGE_CALLBACK
CallerContext As IntPtr, ' void*
<MarshalAs(UnmanagedType.U1)> InitialNotification As Boolean, ' BOOLEAN
NotificationHandle As IntPtr ' HANDLE* in/out
) As UInteger
End Function' Callback : PTEREDO_PORT_CHANGE_CALLBACK
' CallerContext : void*
' InitialNotification : BOOLEAN
' NotificationHandle : HANDLE* in/out
Declare PtrSafe Function NotifyTeredoPortChange Lib "iphlpapi" ( _
ByVal Callback As LongPtr, _
ByVal CallerContext As LongPtr, _
ByVal InitialNotification As Byte, _
ByVal NotificationHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NotifyTeredoPortChange = ctypes.windll.iphlpapi.NotifyTeredoPortChange
NotifyTeredoPortChange.restype = wintypes.DWORD
NotifyTeredoPortChange.argtypes = [
ctypes.c_void_p, # Callback : PTEREDO_PORT_CHANGE_CALLBACK
ctypes.POINTER(None), # CallerContext : void*
wintypes.BOOLEAN, # InitialNotification : BOOLEAN
ctypes.c_void_p, # NotificationHandle : HANDLE* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
NotifyTeredoPortChange = Fiddle::Function.new(
lib['NotifyTeredoPortChange'],
[
Fiddle::TYPE_VOIDP, # Callback : PTEREDO_PORT_CHANGE_CALLBACK
Fiddle::TYPE_VOIDP, # CallerContext : void*
Fiddle::TYPE_CHAR, # InitialNotification : BOOLEAN
Fiddle::TYPE_VOIDP, # NotificationHandle : HANDLE* in/out
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn NotifyTeredoPortChange(
Callback: *const core::ffi::c_void, // PTEREDO_PORT_CHANGE_CALLBACK
CallerContext: *mut (), // void*
InitialNotification: u8, // BOOLEAN
NotificationHandle: *mut *mut core::ffi::c_void // HANDLE* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint NotifyTeredoPortChange(IntPtr Callback, IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, IntPtr NotificationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_NotifyTeredoPortChange' -Namespace Win32 -PassThru
# $api::NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)#uselib "IPHLPAPI.dll"
#func global NotifyTeredoPortChange "NotifyTeredoPortChange" sptr, sptr, sptr, sptr
; NotifyTeredoPortChange Callback, CallerContext, InitialNotification, NotificationHandle ; 戻り値は stat
; Callback : PTEREDO_PORT_CHANGE_CALLBACK -> "sptr"
; CallerContext : void* -> "sptr"
; InitialNotification : BOOLEAN -> "sptr"
; NotificationHandle : HANDLE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "IPHLPAPI.dll"
#cfunc global NotifyTeredoPortChange "NotifyTeredoPortChange" sptr, sptr, int, sptr
; res = NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)
; Callback : PTEREDO_PORT_CHANGE_CALLBACK -> "sptr"
; CallerContext : void* -> "sptr"
; InitialNotification : BOOLEAN -> "int"
; NotificationHandle : HANDLE* in/out -> "sptr"; WIN32_ERROR NotifyTeredoPortChange(PTEREDO_PORT_CHANGE_CALLBACK Callback, void* CallerContext, BOOLEAN InitialNotification, HANDLE* NotificationHandle)
#uselib "IPHLPAPI.dll"
#cfunc global NotifyTeredoPortChange "NotifyTeredoPortChange" intptr, intptr, int, intptr
; res = NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)
; Callback : PTEREDO_PORT_CHANGE_CALLBACK -> "intptr"
; CallerContext : void* -> "intptr"
; InitialNotification : BOOLEAN -> "int"
; NotificationHandle : HANDLE* in/out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procNotifyTeredoPortChange = iphlpapi.NewProc("NotifyTeredoPortChange")
)
// Callback (PTEREDO_PORT_CHANGE_CALLBACK), CallerContext (void*), InitialNotification (BOOLEAN), NotificationHandle (HANDLE* in/out)
r1, _, err := procNotifyTeredoPortChange.Call(
uintptr(Callback),
uintptr(CallerContext),
uintptr(InitialNotification),
uintptr(NotificationHandle),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction NotifyTeredoPortChange(
Callback: Pointer; // PTEREDO_PORT_CHANGE_CALLBACK
CallerContext: Pointer; // void*
InitialNotification: ByteBool; // BOOLEAN
NotificationHandle: Pointer // HANDLE* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'NotifyTeredoPortChange';result := DllCall("IPHLPAPI\NotifyTeredoPortChange"
, "Ptr", Callback ; PTEREDO_PORT_CHANGE_CALLBACK
, "Ptr", CallerContext ; void*
, "Char", InitialNotification ; BOOLEAN
, "Ptr", NotificationHandle ; HANDLE* in/out
, "UInt") ; return: WIN32_ERROR●NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle) = DLL("IPHLPAPI.dll", "dword NotifyTeredoPortChange(void*, void*, byte, void*)")
# 呼び出し: NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)
# Callback : PTEREDO_PORT_CHANGE_CALLBACK -> "void*"
# CallerContext : void* -> "void*"
# InitialNotification : BOOLEAN -> "byte"
# NotificationHandle : HANDLE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn NotifyTeredoPortChange(
Callback: ?*anyopaque, // PTEREDO_PORT_CHANGE_CALLBACK
CallerContext: ?*anyopaque, // void*
InitialNotification: u8, // BOOLEAN
NotificationHandle: ?*anyopaque // HANDLE* in/out
) callconv(std.os.windows.WINAPI) u32;proc NotifyTeredoPortChange(
Callback: pointer, # PTEREDO_PORT_CHANGE_CALLBACK
CallerContext: pointer, # void*
InitialNotification: uint8, # BOOLEAN
NotificationHandle: pointer # HANDLE* in/out
): uint32 {.importc: "NotifyTeredoPortChange", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint NotifyTeredoPortChange(
void* Callback, // PTEREDO_PORT_CHANGE_CALLBACK
void* CallerContext, // void*
ubyte InitialNotification, // BOOLEAN
void* NotificationHandle // HANDLE* in/out
);ccall((:NotifyTeredoPortChange, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt8, Ptr{Cvoid}),
Callback, CallerContext, InitialNotification, NotificationHandle)
# Callback : PTEREDO_PORT_CHANGE_CALLBACK -> Ptr{Cvoid}
# CallerContext : void* -> Ptr{Cvoid}
# InitialNotification : BOOLEAN -> UInt8
# NotificationHandle : HANDLE* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NotifyTeredoPortChange(
void* Callback,
void* CallerContext,
uint8_t InitialNotification,
void* NotificationHandle);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)
-- Callback : PTEREDO_PORT_CHANGE_CALLBACK
-- CallerContext : void*
-- InitialNotification : BOOLEAN
-- NotificationHandle : HANDLE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const NotifyTeredoPortChange = lib.func('__stdcall', 'NotifyTeredoPortChange', 'uint32_t', ['void *', 'void *', 'uint8_t', 'void *']);
// NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)
// Callback : PTEREDO_PORT_CHANGE_CALLBACK -> 'void *'
// CallerContext : void* -> 'void *'
// InitialNotification : BOOLEAN -> 'uint8_t'
// NotificationHandle : HANDLE* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("IPHLPAPI.dll", {
NotifyTeredoPortChange: { parameters: ["pointer", "pointer", "u8", "pointer"], result: "u32" },
});
// lib.symbols.NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle)
// Callback : PTEREDO_PORT_CHANGE_CALLBACK -> "pointer"
// CallerContext : void* -> "pointer"
// InitialNotification : BOOLEAN -> "u8"
// NotificationHandle : HANDLE* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NotifyTeredoPortChange(
void* Callback,
void* CallerContext,
uint8_t InitialNotification,
void* NotificationHandle);
C, "IPHLPAPI.dll");
// $ffi->NotifyTeredoPortChange(Callback, CallerContext, InitialNotification, NotificationHandle);
// Callback : PTEREDO_PORT_CHANGE_CALLBACK
// CallerContext : void*
// InitialNotification : BOOLEAN
// NotificationHandle : HANDLE* 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 NotifyTeredoPortChange(
Callback Callback, // PTEREDO_PORT_CHANGE_CALLBACK
Pointer CallerContext, // void*
byte InitialNotification, // BOOLEAN
Pointer NotificationHandle // HANDLE* in/out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun NotifyTeredoPortChange = NotifyTeredoPortChange(
Callback : Void*, # PTEREDO_PORT_CHANGE_CALLBACK
CallerContext : Void*, # void*
InitialNotification : UInt8, # BOOLEAN
NotificationHandle : Void* # HANDLE* 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 NotifyTeredoPortChangeNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint8, Pointer<Void>);
typedef NotifyTeredoPortChangeDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final NotifyTeredoPortChange = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<NotifyTeredoPortChangeNative, NotifyTeredoPortChangeDart>('NotifyTeredoPortChange');
// Callback : PTEREDO_PORT_CHANGE_CALLBACK -> Pointer<Void>
// CallerContext : void* -> Pointer<Void>
// InitialNotification : BOOLEAN -> Uint8
// NotificationHandle : HANDLE* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NotifyTeredoPortChange(
Callback: Pointer; // PTEREDO_PORT_CHANGE_CALLBACK
CallerContext: Pointer; // void*
InitialNotification: ByteBool; // BOOLEAN
NotificationHandle: Pointer // HANDLE* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'NotifyTeredoPortChange';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NotifyTeredoPortChange"
c_NotifyTeredoPortChange :: Ptr () -> Ptr () -> Word8 -> Ptr () -> IO Word32
-- Callback : PTEREDO_PORT_CHANGE_CALLBACK -> Ptr ()
-- CallerContext : void* -> Ptr ()
-- InitialNotification : BOOLEAN -> Word8
-- NotificationHandle : HANDLE* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let notifyteredoportchange =
foreign "NotifyTeredoPortChange"
((ptr void) @-> (ptr void) @-> uint8_t @-> (ptr void) @-> returning uint32_t)
(* Callback : PTEREDO_PORT_CHANGE_CALLBACK -> (ptr void) *)
(* CallerContext : void* -> (ptr void) *)
(* InitialNotification : BOOLEAN -> uint8_t *)
(* NotificationHandle : HANDLE* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("NotifyTeredoPortChange" notify-teredo-port-change :convention :stdcall) :uint32
(callback :pointer) ; PTEREDO_PORT_CHANGE_CALLBACK
(caller-context :pointer) ; void*
(initial-notification :uint8) ; BOOLEAN
(notification-handle :pointer)) ; HANDLE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NotifyTeredoPortChange = Win32::API::More->new('IPHLPAPI',
'DWORD NotifyTeredoPortChange(LPVOID Callback, LPVOID CallerContext, BYTE InitialNotification, HANDLE NotificationHandle)');
# my $ret = $NotifyTeredoPortChange->Call($Callback, $CallerContext, $InitialNotification, $NotificationHandle);
# Callback : PTEREDO_PORT_CHANGE_CALLBACK -> LPVOID
# CallerContext : void* -> LPVOID
# InitialNotification : BOOLEAN -> BYTE
# NotificationHandle : HANDLE* in/out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
- f CancelMibChangeNotify2 — MIB変更通知の登録をキャンセルする。
- f GetTeredoPort — Teredoが使用するUDPポート番号を取得する。
- f NotifyStableUnicastIpAddressTable — 安定したユニキャストIPアドレステーブルを取得し通知登録する。