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

PROTOCOL_INFOW

構造体
サイズx64: 40 バイト / x86: 32 バイト

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

フィールド

フィールドサイズx64x86説明
dwServiceFlagsDWORD4+0+0プロトコルが提供するサービス特性を示すフラグのビットマスク。
iAddressFamilyINT4+4+4プロトコルが属するアドレスファミリを示す。
iMaxSockAddrINT4+8+8ソケットアドレスの最大バイト長を示す。
iMinSockAddrINT4+12+12ソケットアドレスの最小バイト長を示す。
iSocketTypeINT4+16+16ソケット種別(SOCK_STREAM等)を示す。
iProtocolINT4+20+20プロトコル番号を示す。
dwMessageSizeDWORD4+24+24プロトコルが扱える最大メッセージサイズをバイト単位で示す。
lpProtocolLPWSTR8/4+32+28プロトコル名を表すUnicode文字列へのポインタ。

各言語での定義

#include <windows.h>

// PROTOCOL_INFOW  (x64 40 / x86 32 バイト)
typedef struct PROTOCOL_INFOW {
    DWORD dwServiceFlags;
    INT iAddressFamily;
    INT iMaxSockAddr;
    INT iMinSockAddr;
    INT iSocketType;
    INT iProtocol;
    DWORD dwMessageSize;
    LPWSTR lpProtocol;
} PROTOCOL_INFOW;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct PROTOCOL_INFOW
{
    public uint dwServiceFlags;
    public int iAddressFamily;
    public int iMaxSockAddr;
    public int iMinSockAddr;
    public int iSocketType;
    public int iProtocol;
    public uint dwMessageSize;
    public IntPtr lpProtocol;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure PROTOCOL_INFOW
    Public dwServiceFlags As UInteger
    Public iAddressFamily As Integer
    Public iMaxSockAddr As Integer
    Public iMinSockAddr As Integer
    Public iSocketType As Integer
    Public iProtocol As Integer
    Public dwMessageSize As UInteger
    Public lpProtocol As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class PROTOCOL_INFOW(ctypes.Structure):
    _fields_ = [
        ("dwServiceFlags", wintypes.DWORD),
        ("iAddressFamily", ctypes.c_int),
        ("iMaxSockAddr", ctypes.c_int),
        ("iMinSockAddr", ctypes.c_int),
        ("iSocketType", ctypes.c_int),
        ("iProtocol", ctypes.c_int),
        ("dwMessageSize", wintypes.DWORD),
        ("lpProtocol", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct PROTOCOL_INFOW {
    pub dwServiceFlags: u32,
    pub iAddressFamily: i32,
    pub iMaxSockAddr: i32,
    pub iMinSockAddr: i32,
    pub iSocketType: i32,
    pub iProtocol: i32,
    pub dwMessageSize: u32,
    pub lpProtocol: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type PROTOCOL_INFOW struct {
	dwServiceFlags uint32
	iAddressFamily int32
	iMaxSockAddr int32
	iMinSockAddr int32
	iSocketType int32
	iProtocol int32
	dwMessageSize uint32
	lpProtocol uintptr
}
type
  PROTOCOL_INFOW = record
    dwServiceFlags: DWORD;
    iAddressFamily: Integer;
    iMaxSockAddr: Integer;
    iMinSockAddr: Integer;
    iSocketType: Integer;
    iProtocol: Integer;
    dwMessageSize: DWORD;
    lpProtocol: Pointer;
  end;
const PROTOCOL_INFOW = extern struct {
    dwServiceFlags: u32,
    iAddressFamily: i32,
    iMaxSockAddr: i32,
    iMinSockAddr: i32,
    iSocketType: i32,
    iProtocol: i32,
    dwMessageSize: u32,
    lpProtocol: ?*anyopaque,
};
type
  PROTOCOL_INFOW {.bycopy.} = object
    dwServiceFlags: uint32
    iAddressFamily: int32
    iMaxSockAddr: int32
    iMinSockAddr: int32
    iSocketType: int32
    iProtocol: int32
    dwMessageSize: uint32
    lpProtocol: pointer
struct PROTOCOL_INFOW
{
    uint dwServiceFlags;
    int iAddressFamily;
    int iMaxSockAddr;
    int iMinSockAddr;
    int iSocketType;
    int iProtocol;
    uint dwMessageSize;
    void* lpProtocol;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; PROTOCOL_INFOW サイズ: 32 バイト(x86)
dim st, 8    ; 4byte整数×8(構造体サイズ 32 / 4 切り上げ)
; dwServiceFlags : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; iAddressFamily : INT (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; iMaxSockAddr : INT (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; iMinSockAddr : INT (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; iSocketType : INT (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; iProtocol : INT (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; dwMessageSize : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; lpProtocol : LPWSTR (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; PROTOCOL_INFOW サイズ: 40 バイト(x64)
dim st, 10    ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; dwServiceFlags : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; iAddressFamily : INT (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; iMaxSockAddr : INT (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; iMinSockAddr : INT (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; iSocketType : INT (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; iProtocol : INT (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; dwMessageSize : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; lpProtocol : LPWSTR (+32, 8byte)  qpoke st,32,値 / qpeek(st,32)  ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global PROTOCOL_INFOW
    #field int dwServiceFlags
    #field int iAddressFamily
    #field int iMaxSockAddr
    #field int iMinSockAddr
    #field int iSocketType
    #field int iProtocol
    #field int dwMessageSize
    #field intptr lpProtocol
#endstruct

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