Win32 API 日本語リファレンス
ホームNetworking.WinSock › WSADATA

WSADATA

構造体
サイズx64: 408 バイト / x86: 400 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
wVersionWORD2+0+0Winsock実装が呼び出し側に提供するバージョンである。
wHighVersionWORD2+2+2実装がサポートする最上位Winsockバージョンである。
szDescriptionCHAR257+4+4Winsock実装の説明文字列(固定長)である。
szSystemStatusCHAR129+261+261Winsockの状態や構成を示す文字列(固定長)である。
iMaxSocketsWORD2+390+390同時にオープン可能な最大ソケット数である(Winsock1の名残)。
iMaxUdpDgWORD2+392+392送受信可能なUDPデータグラムの最大サイズである(Winsock1の名残)。
lpVendorInfoLPSTR8/4+400+396ベンダ固有情報へのポインタである(Winsock1の名残)。

各言語での定義

#include <windows.h>

// WSADATA  (x64 408 / x86 400 バイト)
typedef struct WSADATA {
    WORD wVersion;
    WORD wHighVersion;
    CHAR szDescription[257];
    CHAR szSystemStatus[129];
    WORD iMaxSockets;
    WORD iMaxUdpDg;
    LPSTR lpVendorInfo;
} WSADATA;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSADATA
{
    public ushort wVersion;
    public ushort wHighVersion;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 257)] public sbyte[] szDescription;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 129)] public sbyte[] szSystemStatus;
    public ushort iMaxSockets;
    public ushort iMaxUdpDg;
    public IntPtr lpVendorInfo;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure WSADATA
    Public wVersion As UShort
    Public wHighVersion As UShort
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=257)> Public szDescription() As SByte
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=129)> Public szSystemStatus() As SByte
    Public iMaxSockets As UShort
    Public iMaxUdpDg As UShort
    Public lpVendorInfo As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class WSADATA(ctypes.Structure):
    _fields_ = [
        ("wVersion", ctypes.c_ushort),
        ("wHighVersion", ctypes.c_ushort),
        ("szDescription", ctypes.c_byte * 257),
        ("szSystemStatus", ctypes.c_byte * 129),
        ("iMaxSockets", ctypes.c_ushort),
        ("iMaxUdpDg", ctypes.c_ushort),
        ("lpVendorInfo", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct WSADATA {
    pub wVersion: u16,
    pub wHighVersion: u16,
    pub szDescription: [i8; 257],
    pub szSystemStatus: [i8; 129],
    pub iMaxSockets: u16,
    pub iMaxUdpDg: u16,
    pub lpVendorInfo: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type WSADATA struct {
	wVersion uint16
	wHighVersion uint16
	szDescription [257]int8
	szSystemStatus [129]int8
	iMaxSockets uint16
	iMaxUdpDg uint16
	lpVendorInfo uintptr
}
type
  WSADATA = record
    wVersion: Word;
    wHighVersion: Word;
    szDescription: array[0..256] of Shortint;
    szSystemStatus: array[0..128] of Shortint;
    iMaxSockets: Word;
    iMaxUdpDg: Word;
    lpVendorInfo: Pointer;
  end;
const WSADATA = extern struct {
    wVersion: u16,
    wHighVersion: u16,
    szDescription: [257]i8,
    szSystemStatus: [129]i8,
    iMaxSockets: u16,
    iMaxUdpDg: u16,
    lpVendorInfo: ?*anyopaque,
};
type
  WSADATA {.bycopy.} = object
    wVersion: uint16
    wHighVersion: uint16
    szDescription: array[257, int8]
    szSystemStatus: array[129, int8]
    iMaxSockets: uint16
    iMaxUdpDg: uint16
    lpVendorInfo: pointer
struct WSADATA
{
    ushort wVersion;
    ushort wHighVersion;
    byte[257] szDescription;
    byte[129] szSystemStatus;
    ushort iMaxSockets;
    ushort iMaxUdpDg;
    void* lpVendorInfo;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; WSADATA サイズ: 400 バイト(x86)
dim st, 100    ; 4byte整数×100(構造体サイズ 400 / 4 切り上げ)
; wVersion : WORD (+0, 2byte)  wpoke st,0,値  /  値 = wpeek(st,0)
; wHighVersion : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; szDescription : CHAR (+4, 257byte)  varptr(st)+4 を基点に操作(257byte:入れ子/配列)
; szSystemStatus : CHAR (+261, 129byte)  varptr(st)+261 を基点に操作(129byte:入れ子/配列)
; iMaxSockets : WORD (+390, 2byte)  wpoke st,390,値  /  値 = wpeek(st,390)
; iMaxUdpDg : WORD (+392, 2byte)  wpoke st,392,値  /  値 = wpeek(st,392)
; lpVendorInfo : LPSTR (+396, 4byte)  st.99 = 値  /  値 = st.99   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; WSADATA サイズ: 408 バイト(x64)
dim st, 102    ; 4byte整数×102(構造体サイズ 408 / 4 切り上げ)
; wVersion : WORD (+0, 2byte)  wpoke st,0,値  /  値 = wpeek(st,0)
; wHighVersion : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; szDescription : CHAR (+4, 257byte)  varptr(st)+4 を基点に操作(257byte:入れ子/配列)
; szSystemStatus : CHAR (+261, 129byte)  varptr(st)+261 を基点に操作(129byte:入れ子/配列)
; iMaxSockets : WORD (+390, 2byte)  wpoke st,390,値  /  値 = wpeek(st,390)
; iMaxUdpDg : WORD (+392, 2byte)  wpoke st,392,値  /  値 = wpeek(st,392)
; lpVendorInfo : LPSTR (+400, 8byte)  qpoke st,400,値 / qpeek(st,400)  ※IronHSPのみ。3.7/3.8は lpoke st,400,下位 : lpoke st,404,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global WSADATA
    #field short wVersion
    #field short wHighVersion
    #field byte szDescription 257
    #field byte szSystemStatus 129
    #field short iMaxSockets
    #field short iMaxUdpDg
    #field intptr lpVendorInfo
#endstruct

stdim st, WSADATA        ; NSTRUCT 変数を確保
st->wVersion = 100
mes "wVersion=" + st->wVersion