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