Win32 API 日本語リファレンス
ホームNetworkManagement.Multicast › MCAST_SCOPE_CTX

MCAST_SCOPE_CTX

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

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

フィールド

フィールドサイズx64x86説明
ScopeIDIPNG_ADDRESS16+0+0マルチキャストスコープの識別アドレス(IPNG_ADDRESS)である。
InterfaceIPNG_ADDRESS16+16+16スコープに関連付けられたインタフェースアドレス(IPNG_ADDRESS)である。
ServerIDIPNG_ADDRESS16+32+32マルチキャストアドレス割り当てサーバーのアドレス(IPNG_ADDRESS)である。

各言語での定義

#include <windows.h>

// IPNG_ADDRESS  (x64 16 / x86 16 バイト)
typedef struct IPNG_ADDRESS {
    DWORD IpAddrV4;
    BYTE IpAddrV6[16];
} IPNG_ADDRESS;

// MCAST_SCOPE_CTX  (x64 48 / x86 48 バイト)
typedef struct MCAST_SCOPE_CTX {
    IPNG_ADDRESS ScopeID;
    IPNG_ADDRESS Interface;
    IPNG_ADDRESS ServerID;
} MCAST_SCOPE_CTX;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IPNG_ADDRESS
{
    public uint IpAddrV4;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] IpAddrV6;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MCAST_SCOPE_CTX
{
    public IPNG_ADDRESS ScopeID;
    public IPNG_ADDRESS Interface;
    public IPNG_ADDRESS ServerID;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure IPNG_ADDRESS
    Public IpAddrV4 As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public IpAddrV6() As Byte
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MCAST_SCOPE_CTX
    Public ScopeID As IPNG_ADDRESS
    Public Interface As IPNG_ADDRESS
    Public ServerID As IPNG_ADDRESS
End Structure
import ctypes
from ctypes import wintypes

class IPNG_ADDRESS(ctypes.Structure):
    _fields_ = [
        ("IpAddrV4", wintypes.DWORD),
        ("IpAddrV6", ctypes.c_ubyte * 16),
    ]

class MCAST_SCOPE_CTX(ctypes.Structure):
    _fields_ = [
        ("ScopeID", IPNG_ADDRESS),
        ("Interface", IPNG_ADDRESS),
        ("ServerID", IPNG_ADDRESS),
    ]
#[repr(C)]
pub struct IPNG_ADDRESS {
    pub IpAddrV4: u32,
    pub IpAddrV6: [u8; 16],
}

#[repr(C)]
pub struct MCAST_SCOPE_CTX {
    pub ScopeID: IPNG_ADDRESS,
    pub Interface: IPNG_ADDRESS,
    pub ServerID: IPNG_ADDRESS,
}
import "golang.org/x/sys/windows"

type IPNG_ADDRESS struct {
	IpAddrV4 uint32
	IpAddrV6 [16]byte
}

type MCAST_SCOPE_CTX struct {
	ScopeID IPNG_ADDRESS
	Interface IPNG_ADDRESS
	ServerID IPNG_ADDRESS
}
type
  IPNG_ADDRESS = record
    IpAddrV4: DWORD;
    IpAddrV6: array[0..15] of Byte;
  end;

  MCAST_SCOPE_CTX = record
    ScopeID: IPNG_ADDRESS;
    Interface: IPNG_ADDRESS;
    ServerID: IPNG_ADDRESS;
  end;
const IPNG_ADDRESS = extern struct {
    IpAddrV4: u32,
    IpAddrV6: [16]u8,
};

const MCAST_SCOPE_CTX = extern struct {
    ScopeID: IPNG_ADDRESS,
    Interface: IPNG_ADDRESS,
    ServerID: IPNG_ADDRESS,
};
type
  IPNG_ADDRESS {.bycopy.} = object
    IpAddrV4: uint32
    IpAddrV6: array[16, uint8]

  MCAST_SCOPE_CTX {.bycopy.} = object
    ScopeID: IPNG_ADDRESS
    Interface: IPNG_ADDRESS
    ServerID: IPNG_ADDRESS
struct IPNG_ADDRESS
{
    uint IpAddrV4;
    ubyte[16] IpAddrV6;
}

struct MCAST_SCOPE_CTX
{
    IPNG_ADDRESS ScopeID;
    IPNG_ADDRESS Interface;
    IPNG_ADDRESS ServerID;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; MCAST_SCOPE_CTX サイズ: 48 バイト(x64)
dim st, 12    ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; ScopeID : IPNG_ADDRESS (+0, 16byte)  varptr(st)+0 を基点に操作(16byte:入れ子/配列)
; Interface : IPNG_ADDRESS (+16, 16byte)  varptr(st)+16 を基点に操作(16byte:入れ子/配列)
; ServerID : IPNG_ADDRESS (+32, 16byte)  varptr(st)+32 を基点に操作(16byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global MCAST_SCOPE_CTX
    #field byte ScopeID 16
    #field byte Interface 16
    #field byte ServerID 16
#endstruct

stdim st, MCAST_SCOPE_CTX        ; NSTRUCT 変数を確保
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。