ホーム › Networking.WinSock › WSASetSocketSecurity
WSASetSocketSecurity
関数ソケットにIPsec等のセキュリティ設定を適用する。
シグネチャ
// fwpuclnt.dll
#include <windows.h>
INT WSASetSocketSecurity(
SOCKET Socket,
const SOCKET_SECURITY_SETTINGS* SecuritySettings, // optional
DWORD SecuritySettingsLen,
OVERLAPPED* Overlapped, // optional
LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Socket | SOCKET | in |
| SecuritySettings | SOCKET_SECURITY_SETTINGS* | inoptional |
| SecuritySettingsLen | DWORD | in |
| Overlapped | OVERLAPPED* | inoptional |
| CompletionRoutine | LPWSAOVERLAPPED_COMPLETION_ROUTINE | inoptional |
戻り値の型: INT
各言語での呼び出し定義
// fwpuclnt.dll
#include <windows.h>
INT WSASetSocketSecurity(
SOCKET Socket,
const SOCKET_SECURITY_SETTINGS* SecuritySettings, // optional
DWORD SecuritySettingsLen,
OVERLAPPED* Overlapped, // optional
LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine // optional
);[DllImport("fwpuclnt.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSASetSocketSecurity(
UIntPtr Socket, // SOCKET
IntPtr SecuritySettings, // SOCKET_SECURITY_SETTINGS* optional
uint SecuritySettingsLen, // DWORD
IntPtr Overlapped, // OVERLAPPED* optional
IntPtr CompletionRoutine // LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
);<DllImport("fwpuclnt.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSASetSocketSecurity(
Socket As UIntPtr, ' SOCKET
SecuritySettings As IntPtr, ' SOCKET_SECURITY_SETTINGS* optional
SecuritySettingsLen As UInteger, ' DWORD
Overlapped As IntPtr, ' OVERLAPPED* optional
CompletionRoutine As IntPtr ' LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
) As Integer
End Function' Socket : SOCKET
' SecuritySettings : SOCKET_SECURITY_SETTINGS* optional
' SecuritySettingsLen : DWORD
' Overlapped : OVERLAPPED* optional
' CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
Declare PtrSafe Function WSASetSocketSecurity Lib "fwpuclnt" ( _
ByVal Socket As LongPtr, _
ByVal SecuritySettings As LongPtr, _
ByVal SecuritySettingsLen As Long, _
ByVal Overlapped As LongPtr, _
ByVal CompletionRoutine As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSASetSocketSecurity = ctypes.windll.fwpuclnt.WSASetSocketSecurity
WSASetSocketSecurity.restype = ctypes.c_int
WSASetSocketSecurity.argtypes = [
ctypes.c_size_t, # Socket : SOCKET
ctypes.c_void_p, # SecuritySettings : SOCKET_SECURITY_SETTINGS* optional
wintypes.DWORD, # SecuritySettingsLen : DWORD
ctypes.c_void_p, # Overlapped : OVERLAPPED* optional
ctypes.c_void_p, # CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('fwpuclnt.dll')
WSASetSocketSecurity = Fiddle::Function.new(
lib['WSASetSocketSecurity'],
[
Fiddle::TYPE_UINTPTR_T, # Socket : SOCKET
Fiddle::TYPE_VOIDP, # SecuritySettings : SOCKET_SECURITY_SETTINGS* optional
-Fiddle::TYPE_INT, # SecuritySettingsLen : DWORD
Fiddle::TYPE_VOIDP, # Overlapped : OVERLAPPED* optional
Fiddle::TYPE_VOIDP, # CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
],
Fiddle::TYPE_INT)#[link(name = "fwpuclnt")]
extern "system" {
fn WSASetSocketSecurity(
Socket: usize, // SOCKET
SecuritySettings: *const SOCKET_SECURITY_SETTINGS, // SOCKET_SECURITY_SETTINGS* optional
SecuritySettingsLen: u32, // DWORD
Overlapped: *mut OVERLAPPED, // OVERLAPPED* optional
CompletionRoutine: *const core::ffi::c_void // LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("fwpuclnt.dll", SetLastError = true)]
public static extern int WSASetSocketSecurity(UIntPtr Socket, IntPtr SecuritySettings, uint SecuritySettingsLen, IntPtr Overlapped, IntPtr CompletionRoutine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'fwpuclnt_WSASetSocketSecurity' -Namespace Win32 -PassThru
# $api::WSASetSocketSecurity(Socket, SecuritySettings, SecuritySettingsLen, Overlapped, CompletionRoutine)#uselib "fwpuclnt.dll"
#func global WSASetSocketSecurity "WSASetSocketSecurity" sptr, sptr, sptr, sptr, sptr
; WSASetSocketSecurity Socket, varptr(SecuritySettings), SecuritySettingsLen, varptr(Overlapped), CompletionRoutine ; 戻り値は stat
; Socket : SOCKET -> "sptr"
; SecuritySettings : SOCKET_SECURITY_SETTINGS* optional -> "sptr"
; SecuritySettingsLen : DWORD -> "sptr"
; Overlapped : OVERLAPPED* optional -> "sptr"
; CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "fwpuclnt.dll" #cfunc global WSASetSocketSecurity "WSASetSocketSecurity" sptr, var, int, var, sptr ; res = WSASetSocketSecurity(Socket, SecuritySettings, SecuritySettingsLen, Overlapped, CompletionRoutine) ; Socket : SOCKET -> "sptr" ; SecuritySettings : SOCKET_SECURITY_SETTINGS* optional -> "var" ; SecuritySettingsLen : DWORD -> "int" ; Overlapped : OVERLAPPED* optional -> "var" ; CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "fwpuclnt.dll" #cfunc global WSASetSocketSecurity "WSASetSocketSecurity" sptr, sptr, int, sptr, sptr ; res = WSASetSocketSecurity(Socket, varptr(SecuritySettings), SecuritySettingsLen, varptr(Overlapped), CompletionRoutine) ; Socket : SOCKET -> "sptr" ; SecuritySettings : SOCKET_SECURITY_SETTINGS* optional -> "sptr" ; SecuritySettingsLen : DWORD -> "int" ; Overlapped : OVERLAPPED* optional -> "sptr" ; CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT WSASetSocketSecurity(SOCKET Socket, SOCKET_SECURITY_SETTINGS* SecuritySettings, DWORD SecuritySettingsLen, OVERLAPPED* Overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine) #uselib "fwpuclnt.dll" #cfunc global WSASetSocketSecurity "WSASetSocketSecurity" intptr, var, int, var, intptr ; res = WSASetSocketSecurity(Socket, SecuritySettings, SecuritySettingsLen, Overlapped, CompletionRoutine) ; Socket : SOCKET -> "intptr" ; SecuritySettings : SOCKET_SECURITY_SETTINGS* optional -> "var" ; SecuritySettingsLen : DWORD -> "int" ; Overlapped : OVERLAPPED* optional -> "var" ; CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT WSASetSocketSecurity(SOCKET Socket, SOCKET_SECURITY_SETTINGS* SecuritySettings, DWORD SecuritySettingsLen, OVERLAPPED* Overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine) #uselib "fwpuclnt.dll" #cfunc global WSASetSocketSecurity "WSASetSocketSecurity" intptr, intptr, int, intptr, intptr ; res = WSASetSocketSecurity(Socket, varptr(SecuritySettings), SecuritySettingsLen, varptr(Overlapped), CompletionRoutine) ; Socket : SOCKET -> "intptr" ; SecuritySettings : SOCKET_SECURITY_SETTINGS* optional -> "intptr" ; SecuritySettingsLen : DWORD -> "int" ; Overlapped : OVERLAPPED* optional -> "intptr" ; CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
fwpuclnt = windows.NewLazySystemDLL("fwpuclnt.dll")
procWSASetSocketSecurity = fwpuclnt.NewProc("WSASetSocketSecurity")
)
// Socket (SOCKET), SecuritySettings (SOCKET_SECURITY_SETTINGS* optional), SecuritySettingsLen (DWORD), Overlapped (OVERLAPPED* optional), CompletionRoutine (LPWSAOVERLAPPED_COMPLETION_ROUTINE optional)
r1, _, err := procWSASetSocketSecurity.Call(
uintptr(Socket),
uintptr(SecuritySettings),
uintptr(SecuritySettingsLen),
uintptr(Overlapped),
uintptr(CompletionRoutine),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction WSASetSocketSecurity(
Socket: NativeUInt; // SOCKET
SecuritySettings: Pointer; // SOCKET_SECURITY_SETTINGS* optional
SecuritySettingsLen: DWORD; // DWORD
Overlapped: Pointer; // OVERLAPPED* optional
CompletionRoutine: Pointer // LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
): Integer; stdcall;
external 'fwpuclnt.dll' name 'WSASetSocketSecurity';result := DllCall("fwpuclnt\WSASetSocketSecurity"
, "UPtr", Socket ; SOCKET
, "Ptr", SecuritySettings ; SOCKET_SECURITY_SETTINGS* optional
, "UInt", SecuritySettingsLen ; DWORD
, "Ptr", Overlapped ; OVERLAPPED* optional
, "Ptr", CompletionRoutine ; LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
, "Int") ; return: INT●WSASetSocketSecurity(Socket, SecuritySettings, SecuritySettingsLen, Overlapped, CompletionRoutine) = DLL("fwpuclnt.dll", "int WSASetSocketSecurity(int, void*, dword, void*, void*)")
# 呼び出し: WSASetSocketSecurity(Socket, SecuritySettings, SecuritySettingsLen, Overlapped, CompletionRoutine)
# Socket : SOCKET -> "int"
# SecuritySettings : SOCKET_SECURITY_SETTINGS* optional -> "void*"
# SecuritySettingsLen : DWORD -> "dword"
# Overlapped : OVERLAPPED* optional -> "void*"
# CompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。