ホーム › Networking.WinSock › WSAMSG
WSAMSG
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| name | SOCKADDR* | 8/4 | +0 | +0 | 相手側のソケットアドレスへのポインタである。 |
| namelen | INT | 4 | +8 | +4 | nameが指すアドレスの長さをバイト単位で示す。 |
| lpBuffers | WSABUF* | 8/4 | +16 | +8 | 送受信データバッファ(WSABUF)配列へのポインタである。 |
| dwBufferCount | DWORD | 4 | +24 | +12 | lpBuffers配列に含まれるバッファの数である。 |
| Control | WSABUF | 16/8 | +32 | +16 | 補助制御データ(コントロールメッセージ)を保持するWSABUFである。 |
| dwFlags | DWORD | 4 | +48 | +24 | メッセージのフラグ(MSG_*)を示す値である。 |
各言語での定義
#include <windows.h>
// WSABUF (x64 16 / x86 8 バイト)
typedef struct WSABUF {
DWORD len;
LPSTR buf;
} WSABUF;
// WSAMSG (x64 56 / x86 28 バイト)
typedef struct WSAMSG {
SOCKADDR* name;
INT namelen;
WSABUF* lpBuffers;
DWORD dwBufferCount;
WSABUF Control;
DWORD dwFlags;
} WSAMSG;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSABUF
{
public uint len;
public IntPtr buf;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSAMSG
{
public IntPtr name;
public int namelen;
public IntPtr lpBuffers;
public uint dwBufferCount;
public WSABUF Control;
public uint dwFlags;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure WSABUF
Public len As UInteger
Public buf As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure WSAMSG
Public name As IntPtr
Public namelen As Integer
Public lpBuffers As IntPtr
Public dwBufferCount As UInteger
Public Control As WSABUF
Public dwFlags As UInteger
End Structureimport ctypes
from ctypes import wintypes
class WSABUF(ctypes.Structure):
_fields_ = [
("len", wintypes.DWORD),
("buf", ctypes.c_void_p),
]
class WSAMSG(ctypes.Structure):
_fields_ = [
("name", ctypes.c_void_p),
("namelen", ctypes.c_int),
("lpBuffers", ctypes.c_void_p),
("dwBufferCount", wintypes.DWORD),
("Control", WSABUF),
("dwFlags", wintypes.DWORD),
]#[repr(C)]
pub struct WSABUF {
pub len: u32,
pub buf: *mut core::ffi::c_void,
}
#[repr(C)]
pub struct WSAMSG {
pub name: *mut core::ffi::c_void,
pub namelen: i32,
pub lpBuffers: *mut core::ffi::c_void,
pub dwBufferCount: u32,
pub Control: WSABUF,
pub dwFlags: u32,
}import "golang.org/x/sys/windows"
type WSABUF struct {
len uint32
buf uintptr
}
type WSAMSG struct {
name uintptr
namelen int32
lpBuffers uintptr
dwBufferCount uint32
Control WSABUF
dwFlags uint32
}type
WSABUF = record
len: DWORD;
buf: Pointer;
end;
WSAMSG = record
name: Pointer;
namelen: Integer;
lpBuffers: Pointer;
dwBufferCount: DWORD;
Control: WSABUF;
dwFlags: DWORD;
end;const WSABUF = extern struct {
len: u32,
buf: ?*anyopaque,
};
const WSAMSG = extern struct {
name: ?*anyopaque,
namelen: i32,
lpBuffers: ?*anyopaque,
dwBufferCount: u32,
Control: WSABUF,
dwFlags: u32,
};type
WSABUF {.bycopy.} = object
len: uint32
buf: pointer
WSAMSG {.bycopy.} = object
name: pointer
namelen: int32
lpBuffers: pointer
dwBufferCount: uint32
Control: WSABUF
dwFlags: uint32struct WSABUF
{
uint len;
void* buf;
}
struct WSAMSG
{
void* name;
int namelen;
void* lpBuffers;
uint dwBufferCount;
WSABUF Control;
uint dwFlags;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; WSAMSG サイズ: 28 バイト(x86)
dim st, 7 ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; name : SOCKADDR* (+0, 4byte) varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; namelen : INT (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; lpBuffers : WSABUF* (+8, 4byte) varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; dwBufferCount : DWORD (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; Control : WSABUF (+16, 8byte) varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; dwFlags : DWORD (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; WSAMSG サイズ: 56 バイト(x64)
dim st, 14 ; 4byte整数×14(構造体サイズ 56 / 4 切り上げ)
; name : SOCKADDR* (+0, 8byte) varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; namelen : INT (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; lpBuffers : WSABUF* (+16, 8byte) varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; dwBufferCount : DWORD (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; Control : WSABUF (+32, 16byte) varptr(st)+32 を基点に操作(16byte:入れ子/配列)
; dwFlags : DWORD (+48, 4byte) st.12 = 値 / 値 = st.12 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global WSABUF
#field int len
#field intptr buf
#endstruct
#defstruct global WSAMSG
#field intptr name
#field int namelen
#field intptr lpBuffers
#field int dwBufferCount
#field WSABUF Control
#field int dwFlags
#endstruct
stdim st, WSAMSG ; NSTRUCT 変数を確保
st->namelen = 100
mes "namelen=" + st->namelen