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

IPV6_ADDRESS_EX

構造体
サイズx64: 26 バイト / x86: 26 バイトパッキング1

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

フィールド

フィールドサイズx64x86説明
sin6_portWORD2+0+0IPv6エンドポイントのポート番号をネットワークバイト順で保持する。
sin6_flowinfoDWORD4+2+2IPv6フロー情報フィールドを保持する。
sin6_addrWORD16+6+6IPv6アドレスを16ビット語8個の配列で保持する。
sin6_scope_idDWORD4+22+22リンクローカルアドレス用のスコープID(インターフェース識別子)を示す。

各言語での定義

#include <windows.h>

// IPV6_ADDRESS_EX  (x64 26 / x86 26 バイト)
#pragma pack(push, 1)
typedef struct IPV6_ADDRESS_EX {
    WORD sin6_port;
    DWORD sin6_flowinfo;
    WORD sin6_addr[8];
    DWORD sin6_scope_id;
} IPV6_ADDRESS_EX;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct IPV6_ADDRESS_EX
{
    public ushort sin6_port;
    public uint sin6_flowinfo;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public ushort[] sin6_addr;
    public uint sin6_scope_id;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure IPV6_ADDRESS_EX
    Public sin6_port As UShort
    Public sin6_flowinfo As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public sin6_addr() As UShort
    Public sin6_scope_id As UInteger
End Structure
import ctypes
from ctypes import wintypes

class IPV6_ADDRESS_EX(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("sin6_port", ctypes.c_ushort),
        ("sin6_flowinfo", wintypes.DWORD),
        ("sin6_addr", ctypes.c_ushort * 8),
        ("sin6_scope_id", wintypes.DWORD),
    ]
#[repr(C, packed(1))]
pub struct IPV6_ADDRESS_EX {
    pub sin6_port: u16,
    pub sin6_flowinfo: u32,
    pub sin6_addr: [u16; 8],
    pub sin6_scope_id: u32,
}
import "golang.org/x/sys/windows"

type IPV6_ADDRESS_EX struct {
	sin6_port uint16
	sin6_flowinfo uint32
	sin6_addr [8]uint16
	sin6_scope_id uint32
}
type
  IPV6_ADDRESS_EX = packed record
    sin6_port: Word;
    sin6_flowinfo: DWORD;
    sin6_addr: array[0..7] of Word;
    sin6_scope_id: DWORD;
  end;
const IPV6_ADDRESS_EX = extern struct {
    sin6_port: u16,
    sin6_flowinfo: u32,
    sin6_addr: [8]u16,
    sin6_scope_id: u32,
};
type
  IPV6_ADDRESS_EX {.packed.} = object
    sin6_port: uint16
    sin6_flowinfo: uint32
    sin6_addr: array[8, uint16]
    sin6_scope_id: uint32
align(1)
struct IPV6_ADDRESS_EX
{
    ushort sin6_port;
    uint sin6_flowinfo;
    ushort[8] sin6_addr;
    uint sin6_scope_id;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; IPV6_ADDRESS_EX サイズ: 26 バイト(x64)
dim st, 7    ; 4byte整数×7(構造体サイズ 26 / 4 切り上げ)
; sin6_port : WORD (+0, 2byte)  wpoke st,0,値  /  値 = wpeek(st,0)
; sin6_flowinfo : DWORD (+2, 4byte)  lpoke st,2,値  /  値 = lpeek(st,2)
; sin6_addr : WORD (+6, 16byte)  varptr(st)+6 を基点に操作(16byte:入れ子/配列)
; sin6_scope_id : DWORD (+22, 4byte)  lpoke st,22,値  /  値 = lpeek(st,22)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global IPV6_ADDRESS_EX, pack=1
    #field short sin6_port
    #field int sin6_flowinfo
    #field short sin6_addr 8
    #field int sin6_scope_id
#endstruct

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