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

IP_PATTERN

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

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

フィールド

フィールドサイズx64x86説明
Reserved1DWORD4+0+0将来の使用のために予約済みです。
Reserved2DWORD4+4+4将来の使用のために予約済みです。
SrcAddrDWORD4+8+8送信元アドレスです。
DstAddrDWORD4+12+12宛先アドレスです。
S_un_S_un_e__Union8/4+16+16送信元/宛先ポートまたはICMPの種別/コードを保持する共用体。
ProtocolIdBYTE1+24+20プロトコル識別子です。
Reserved3BYTE3+25+21将来の使用のために予約済みです。

共用体: _S_un_e__Union x64 8B / x86 4B

フィールドサイズx64x86説明
S_un_ports_S_un_ports_e__Struct8/4+0+0
S_un_ports.s_srcport,s_dstport

送信元ポートおよび宛先ポートです。

S_un_icmp_S_un_icmp_e__Struct8/4+0+0
S_un_icmp.s_type,s_code

ICMP メッセージの種類および ICMP メッセージのコードです。

S_SpiDWORD4+0+0サービスプロバイダーインターフェイスです。

公式ドキュメント

IP_PATTERN 構造体は、IP プロトコルに対する特定のパターンまたは対応するマスクを適用します。 IP_PATTERN 構造体の指定は、パケットフィルターの適用時にトラフィック制御インターフェイスによって使用されます。

解説(Remarks)

共用体のメンバーを参照しやすくするために、Traffic.h では次のマクロが定義されています。

#define tcSrcPort S_un.S_un_ports.s_srcport
#define tcDstPort S_un.S_un_ports.s_dstport
#define tcIcmpType        S_un.S_un_icmp.s_type
#define tcIcmpCode        S_un.S_un_icmp.s_code
#define tcSpi             S_un.S_Spi
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// IP_PATTERN  (x64 32 / x86 24 バイト)
typedef struct IP_PATTERN {
    DWORD Reserved1;
    DWORD Reserved2;
    DWORD SrcAddr;
    DWORD DstAddr;
    _S_un_e__Union S_un;
    BYTE ProtocolId;
    BYTE Reserved3[3];
} IP_PATTERN;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IP_PATTERN
{
    public uint Reserved1;
    public uint Reserved2;
    public uint SrcAddr;
    public uint DstAddr;
    public _S_un_e__Union S_un;
    public byte ProtocolId;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] Reserved3;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure IP_PATTERN
    Public Reserved1 As UInteger
    Public Reserved2 As UInteger
    Public SrcAddr As UInteger
    Public DstAddr As UInteger
    Public S_un As _S_un_e__Union
    Public ProtocolId As Byte
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Public Reserved3() As Byte
End Structure
import ctypes
from ctypes import wintypes

class IP_PATTERN(ctypes.Structure):
    _fields_ = [
        ("Reserved1", wintypes.DWORD),
        ("Reserved2", wintypes.DWORD),
        ("SrcAddr", wintypes.DWORD),
        ("DstAddr", wintypes.DWORD),
        ("S_un", _S_un_e__Union),
        ("ProtocolId", ctypes.c_ubyte),
        ("Reserved3", ctypes.c_ubyte * 3),
    ]
#[repr(C)]
pub struct IP_PATTERN {
    pub Reserved1: u32,
    pub Reserved2: u32,
    pub SrcAddr: u32,
    pub DstAddr: u32,
    pub S_un: _S_un_e__Union,
    pub ProtocolId: u8,
    pub Reserved3: [u8; 3],
}
import "golang.org/x/sys/windows"

type IP_PATTERN struct {
	Reserved1 uint32
	Reserved2 uint32
	SrcAddr uint32
	DstAddr uint32
	S_un _S_un_e__Union
	ProtocolId byte
	Reserved3 [3]byte
}
type
  IP_PATTERN = record
    Reserved1: DWORD;
    Reserved2: DWORD;
    SrcAddr: DWORD;
    DstAddr: DWORD;
    S_un: _S_un_e__Union;
    ProtocolId: Byte;
    Reserved3: array[0..2] of Byte;
  end;
const IP_PATTERN = extern struct {
    Reserved1: u32,
    Reserved2: u32,
    SrcAddr: u32,
    DstAddr: u32,
    S_un: _S_un_e__Union,
    ProtocolId: u8,
    Reserved3: [3]u8,
};
type
  IP_PATTERN {.bycopy.} = object
    Reserved1: uint32
    Reserved2: uint32
    SrcAddr: uint32
    DstAddr: uint32
    S_un: _S_un_e__Union
    ProtocolId: uint8
    Reserved3: array[3, uint8]
struct IP_PATTERN
{
    uint Reserved1;
    uint Reserved2;
    uint SrcAddr;
    uint DstAddr;
    _S_un_e__Union S_un;
    ubyte ProtocolId;
    ubyte[3] Reserved3;
}

HSP用 定義

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

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

stdim st, IP_PATTERN        ; NSTRUCT 変数を確保
st->Reserved1 = 100
mes "Reserved1=" + st->Reserved1
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。