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

SERVICE_ADDRESS

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

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

フィールド

フィールドサイズx64x86説明
dwAddressTypeDWORD4+0+0アドレスの種別(プロトコル)を示す。
dwAddressFlagsDWORD4+4+4アドレスの動作を制御するフラグのビットマスク。
dwAddressLengthDWORD4+8+8lpAddressが指すアドレスの長さをバイト単位で示す。
dwPrincipalLengthDWORD4+12+12lpPrincipalが指すプリンシパルの長さをバイト単位で示す。
lpAddressBYTE*8/4+16+16ソケットアドレスのバイト列へのポインタ。
lpPrincipalBYTE*8/4+24+20プリンシパル(主体)情報のバイト列へのポインタ。

各言語での定義

#include <windows.h>

// SERVICE_ADDRESS  (x64 32 / x86 24 バイト)
typedef struct SERVICE_ADDRESS {
    DWORD dwAddressType;
    DWORD dwAddressFlags;
    DWORD dwAddressLength;
    DWORD dwPrincipalLength;
    BYTE* lpAddress;
    BYTE* lpPrincipal;
} SERVICE_ADDRESS;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERVICE_ADDRESS
{
    public uint dwAddressType;
    public uint dwAddressFlags;
    public uint dwAddressLength;
    public uint dwPrincipalLength;
    public IntPtr lpAddress;
    public IntPtr lpPrincipal;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SERVICE_ADDRESS
    Public dwAddressType As UInteger
    Public dwAddressFlags As UInteger
    Public dwAddressLength As UInteger
    Public dwPrincipalLength As UInteger
    Public lpAddress As IntPtr
    Public lpPrincipal As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class SERVICE_ADDRESS(ctypes.Structure):
    _fields_ = [
        ("dwAddressType", wintypes.DWORD),
        ("dwAddressFlags", wintypes.DWORD),
        ("dwAddressLength", wintypes.DWORD),
        ("dwPrincipalLength", wintypes.DWORD),
        ("lpAddress", ctypes.c_void_p),
        ("lpPrincipal", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct SERVICE_ADDRESS {
    pub dwAddressType: u32,
    pub dwAddressFlags: u32,
    pub dwAddressLength: u32,
    pub dwPrincipalLength: u32,
    pub lpAddress: *mut core::ffi::c_void,
    pub lpPrincipal: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type SERVICE_ADDRESS struct {
	dwAddressType uint32
	dwAddressFlags uint32
	dwAddressLength uint32
	dwPrincipalLength uint32
	lpAddress uintptr
	lpPrincipal uintptr
}
type
  SERVICE_ADDRESS = record
    dwAddressType: DWORD;
    dwAddressFlags: DWORD;
    dwAddressLength: DWORD;
    dwPrincipalLength: DWORD;
    lpAddress: Pointer;
    lpPrincipal: Pointer;
  end;
const SERVICE_ADDRESS = extern struct {
    dwAddressType: u32,
    dwAddressFlags: u32,
    dwAddressLength: u32,
    dwPrincipalLength: u32,
    lpAddress: ?*anyopaque,
    lpPrincipal: ?*anyopaque,
};
type
  SERVICE_ADDRESS {.bycopy.} = object
    dwAddressType: uint32
    dwAddressFlags: uint32
    dwAddressLength: uint32
    dwPrincipalLength: uint32
    lpAddress: pointer
    lpPrincipal: pointer
struct SERVICE_ADDRESS
{
    uint dwAddressType;
    uint dwAddressFlags;
    uint dwAddressLength;
    uint dwPrincipalLength;
    void* lpAddress;
    void* lpPrincipal;
}

HSP用 定義

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

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

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