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

CreateProxyArpEntry

関数
指定インターフェイスにプロキシARPエントリを作成する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// IPHLPAPI.dll
#include <windows.h>

DWORD CreateProxyArpEntry(
    DWORD dwAddress,
    DWORD dwMask,
    DWORD dwIfIndex
);

パラメーター

名前方向説明
dwAddressDWORDinこのコンピューターがプロキシとして動作する対象の IPv4 アドレス。
dwMaskDWORDindwAddress で指定された IPv4 アドレスのサブネット マスク。
dwIfIndexDWORDindwAddress で識別される IPv4 アドレスに対してプロキシ ARP を実行するインターフェイスのインデックス。つまり、dwAddress に対する ARP 要求がこのインターフェイスで受信されると、ローカル コンピューターはこのインターフェイスの物理アドレスで応答します。このインターフェイスが PPP のように ARP をサポートしない種類のものである場合、この呼び出しは失敗します。

戻り値の型: DWORD

公式ドキュメント

CreateProxyArpEnry 関数は、指定された IPv4 アドレスに対するプロキシ ARP (Proxy Address Resolution Protocol、PARP) エントリをローカル コンピューター上に作成します。

戻り値

関数が成功した場合、NO_ERROR (ゼロ) を返します。

関数が失敗した場合、戻り値は次のいずれかのエラー コードになります。

戻りコード 説明
ERROR_ACCESS_DENIED
アクセスが拒否されました。このエラーは、Windows Vista および Windows Server 2008 において、次を含むいくつかの条件で返されます。すなわち、ユーザーがローカル コンピューター上で必要な管理者特権を持っていない場合、またはアプリケーションが組み込みの Administrator (管理者として実行) としての拡張シェルで実行されていない場合です。
ERROR_INVALID_PARAMETER
入力パラメーターが無効であり、何も実行されませんでした。このエラーは、dwAddress パラメーターが zero または無効な値である場合、あるいは他のパラメーターのいずれかが無効である場合に返されます。
ERROR_NOT_SUPPORTED
ローカル コンピューターで IPv4 トランスポートが構成されていません。
Other
返されたエラーのメッセージ文字列を取得するには、 FormatMessage を使用してください。

解説(Remarks)

ARP テーブルを取得するには、GetIpNetTable 関数を呼び出します。既存の PARP エントリを削除するには、DeleteProxyArpEntry を呼び出します。

Windows Vista 以降では、CreateProxyArpEnry 関数は Administrators グループのメンバーとしてログオンしているユーザーのみが呼び出すことができます。CreateProxyArpEnry が Administrators グループのメンバーでないユーザーによって呼び出された場合、関数呼び出しは失敗し、ERROR_ACCESS_DENIED が返されます。この関数は、Windows Vista 以降のユーザー アカウント制御 (UAC) が原因で失敗することもあります。この関数を含むアプリケーションが、組み込みの Administrator 以外の Administrators グループのメンバーとしてログオンしているユーザーによって実行された場合、マニフェスト ファイルで requestedExecutionLevel が requireAdministrator に設定されていない限り、この呼び出しは失敗します。Windows Vista 以降のアプリケーションにこのマニフェスト ファイルがない場合、この関数を成功させるには、組み込みの Administrator 以外の Administrators グループのメンバーとしてログオンしているユーザーが、組み込みの Administrator (管理者として実行) としての拡張シェルでアプリケーションを実行する必要があります。

注意 この関数は特権操作を実行します。この関数が正常に実行されるには、呼び出し元が Administrators グループまたは NetworkConfigurationOperators グループのメンバーとしてログオンしている必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// IPHLPAPI.dll
#include <windows.h>

DWORD CreateProxyArpEntry(
    DWORD dwAddress,
    DWORD dwMask,
    DWORD dwIfIndex
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint CreateProxyArpEntry(
    uint dwAddress,   // DWORD
    uint dwMask,   // DWORD
    uint dwIfIndex   // DWORD
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function CreateProxyArpEntry(
    dwAddress As UInteger,   ' DWORD
    dwMask As UInteger,   ' DWORD
    dwIfIndex As UInteger   ' DWORD
) As UInteger
End Function
' dwAddress : DWORD
' dwMask : DWORD
' dwIfIndex : DWORD
Declare PtrSafe Function CreateProxyArpEntry Lib "iphlpapi" ( _
    ByVal dwAddress As Long, _
    ByVal dwMask As Long, _
    ByVal dwIfIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateProxyArpEntry = ctypes.windll.iphlpapi.CreateProxyArpEntry
CreateProxyArpEntry.restype = wintypes.DWORD
CreateProxyArpEntry.argtypes = [
    wintypes.DWORD,  # dwAddress : DWORD
    wintypes.DWORD,  # dwMask : DWORD
    wintypes.DWORD,  # dwIfIndex : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
CreateProxyArpEntry = Fiddle::Function.new(
  lib['CreateProxyArpEntry'],
  [
    -Fiddle::TYPE_INT,  # dwAddress : DWORD
    -Fiddle::TYPE_INT,  # dwMask : DWORD
    -Fiddle::TYPE_INT,  # dwIfIndex : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn CreateProxyArpEntry(
        dwAddress: u32,  // DWORD
        dwMask: u32,  // DWORD
        dwIfIndex: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint CreateProxyArpEntry(uint dwAddress, uint dwMask, uint dwIfIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_CreateProxyArpEntry' -Namespace Win32 -PassThru
# $api::CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
#uselib "IPHLPAPI.dll"
#func global CreateProxyArpEntry "CreateProxyArpEntry" sptr, sptr, sptr
; CreateProxyArpEntry dwAddress, dwMask, dwIfIndex   ; 戻り値は stat
; dwAddress : DWORD -> "sptr"
; dwMask : DWORD -> "sptr"
; dwIfIndex : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "IPHLPAPI.dll"
#cfunc global CreateProxyArpEntry "CreateProxyArpEntry" int, int, int
; res = CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
; dwAddress : DWORD -> "int"
; dwMask : DWORD -> "int"
; dwIfIndex : DWORD -> "int"
; DWORD CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
#uselib "IPHLPAPI.dll"
#cfunc global CreateProxyArpEntry "CreateProxyArpEntry" int, int, int
; res = CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
; dwAddress : DWORD -> "int"
; dwMask : DWORD -> "int"
; dwIfIndex : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procCreateProxyArpEntry = iphlpapi.NewProc("CreateProxyArpEntry")
)

// dwAddress (DWORD), dwMask (DWORD), dwIfIndex (DWORD)
r1, _, err := procCreateProxyArpEntry.Call(
	uintptr(dwAddress),
	uintptr(dwMask),
	uintptr(dwIfIndex),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function CreateProxyArpEntry(
  dwAddress: DWORD;   // DWORD
  dwMask: DWORD;   // DWORD
  dwIfIndex: DWORD   // DWORD
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'CreateProxyArpEntry';
result := DllCall("IPHLPAPI\CreateProxyArpEntry"
    , "UInt", dwAddress   ; DWORD
    , "UInt", dwMask   ; DWORD
    , "UInt", dwIfIndex   ; DWORD
    , "UInt")   ; return: DWORD
●CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex) = DLL("IPHLPAPI.dll", "dword CreateProxyArpEntry(dword, dword, dword)")
# 呼び出し: CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
# dwAddress : DWORD -> "dword"
# dwMask : DWORD -> "dword"
# dwIfIndex : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "iphlpapi" fn CreateProxyArpEntry(
    dwAddress: u32, // DWORD
    dwMask: u32, // DWORD
    dwIfIndex: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc CreateProxyArpEntry(
    dwAddress: uint32,  # DWORD
    dwMask: uint32,  # DWORD
    dwIfIndex: uint32  # DWORD
): uint32 {.importc: "CreateProxyArpEntry", stdcall, dynlib: "IPHLPAPI.dll".}
pragma(lib, "iphlpapi");
extern(Windows)
uint CreateProxyArpEntry(
    uint dwAddress,   // DWORD
    uint dwMask,   // DWORD
    uint dwIfIndex   // DWORD
);
ccall((:CreateProxyArpEntry, "IPHLPAPI.dll"), stdcall, UInt32,
      (UInt32, UInt32, UInt32),
      dwAddress, dwMask, dwIfIndex)
# dwAddress : DWORD -> UInt32
# dwMask : DWORD -> UInt32
# dwIfIndex : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t CreateProxyArpEntry(
    uint32_t dwAddress,
    uint32_t dwMask,
    uint32_t dwIfIndex);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
-- dwAddress : DWORD
-- dwMask : DWORD
-- dwIfIndex : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const CreateProxyArpEntry = lib.func('__stdcall', 'CreateProxyArpEntry', 'uint32_t', ['uint32_t', 'uint32_t', 'uint32_t']);
// CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
// dwAddress : DWORD -> 'uint32_t'
// dwMask : DWORD -> 'uint32_t'
// dwIfIndex : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("IPHLPAPI.dll", {
  CreateProxyArpEntry: { parameters: ["u32", "u32", "u32"], result: "u32" },
});
// lib.symbols.CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex)
// dwAddress : DWORD -> "u32"
// dwMask : DWORD -> "u32"
// dwIfIndex : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t CreateProxyArpEntry(
    uint32_t dwAddress,
    uint32_t dwMask,
    uint32_t dwIfIndex);
C, "IPHLPAPI.dll");
// $ffi->CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex);
// dwAddress : DWORD
// dwMask : DWORD
// dwIfIndex : DWORD
// 構造体/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 CreateProxyArpEntry(
        int dwAddress,   // DWORD
        int dwMask,   // DWORD
        int dwIfIndex   // DWORD
    );
}
@[Link("iphlpapi")]
lib LibIPHLPAPI
  fun CreateProxyArpEntry = CreateProxyArpEntry(
    dwAddress : UInt32,   # DWORD
    dwMask : UInt32,   # DWORD
    dwIfIndex : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateProxyArpEntryNative = Uint32 Function(Uint32, Uint32, Uint32);
typedef CreateProxyArpEntryDart = int Function(int, int, int);
final CreateProxyArpEntry = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<CreateProxyArpEntryNative, CreateProxyArpEntryDart>('CreateProxyArpEntry');
// dwAddress : DWORD -> Uint32
// dwMask : DWORD -> Uint32
// dwIfIndex : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateProxyArpEntry(
  dwAddress: DWORD;   // DWORD
  dwMask: DWORD;   // DWORD
  dwIfIndex: DWORD   // DWORD
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'CreateProxyArpEntry';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateProxyArpEntry"
  c_CreateProxyArpEntry :: Word32 -> Word32 -> Word32 -> IO Word32
-- dwAddress : DWORD -> Word32
-- dwMask : DWORD -> Word32
-- dwIfIndex : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createproxyarpentry =
  foreign "CreateProxyArpEntry"
    (uint32_t @-> uint32_t @-> uint32_t @-> returning uint32_t)
(* dwAddress : DWORD -> uint32_t *)
(* dwMask : DWORD -> uint32_t *)
(* dwIfIndex : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("CreateProxyArpEntry" create-proxy-arp-entry :convention :stdcall) :uint32
  (dw-address :uint32)   ; DWORD
  (dw-mask :uint32)   ; DWORD
  (dw-if-index :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateProxyArpEntry = Win32::API::More->new('IPHLPAPI',
    'DWORD CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)');
# my $ret = $CreateProxyArpEntry->Call($dwAddress, $dwMask, $dwIfIndex);
# dwAddress : DWORD -> DWORD
# dwMask : DWORD -> DWORD
# dwIfIndex : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目