ホーム › Networking.WinSock › ICMP_MESSAGE
ICMP_MESSAGE
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| Header | ICMP_HEADER | 4 | +0 | +0 | ICMPメッセージの共通ヘッダーを保持するICMP_HEADER。 |
| Data | _Data_e__Union | 4 | +4 | +4 | メッセージ種別に応じたデータを保持する無名共用体。 |
共用体: _Data_e__Union x64 4B / x86 4B
| フィールド | 型 | サイズ | x64 | x86 |
|---|---|---|---|---|
| Data32 | DWORD | 4 | +0 | +0 |
| Data16 | WORD | 4 | +0 | +0 |
| Data8 | BYTE | 4 | +0 | +0 |
各言語での定義
#include <windows.h>
// ICMP_HEADER (x64 4 / x86 4 バイト)
typedef struct ICMP_HEADER {
BYTE Type;
BYTE Code;
WORD Checksum;
} ICMP_HEADER;
// ICMP_MESSAGE (x64 8 / x86 8 バイト)
typedef struct ICMP_MESSAGE {
ICMP_HEADER Header;
_Data_e__Union Data;
} ICMP_MESSAGE;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ICMP_HEADER
{
public byte Type;
public byte Code;
public ushort Checksum;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ICMP_MESSAGE
{
public ICMP_HEADER Header;
public _Data_e__Union Data;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ICMP_HEADER
Public Type As Byte
Public Code As Byte
Public Checksum As UShort
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ICMP_MESSAGE
Public Header As ICMP_HEADER
Public Data As _Data_e__Union
End Structureimport ctypes
from ctypes import wintypes
class ICMP_HEADER(ctypes.Structure):
_fields_ = [
("Type", ctypes.c_ubyte),
("Code", ctypes.c_ubyte),
("Checksum", ctypes.c_ushort),
]
class ICMP_MESSAGE(ctypes.Structure):
_fields_ = [
("Header", ICMP_HEADER),
("Data", _Data_e__Union),
]#[repr(C)]
pub struct ICMP_HEADER {
pub Type: u8,
pub Code: u8,
pub Checksum: u16,
}
#[repr(C)]
pub struct ICMP_MESSAGE {
pub Header: ICMP_HEADER,
pub Data: _Data_e__Union,
}import "golang.org/x/sys/windows"
type ICMP_HEADER struct {
Type byte
Code byte
Checksum uint16
}
type ICMP_MESSAGE struct {
Header ICMP_HEADER
Data _Data_e__Union
}type
ICMP_HEADER = record
Type: Byte;
Code: Byte;
Checksum: Word;
end;
ICMP_MESSAGE = record
Header: ICMP_HEADER;
Data: _Data_e__Union;
end;const ICMP_HEADER = extern struct {
Type: u8,
Code: u8,
Checksum: u16,
};
const ICMP_MESSAGE = extern struct {
Header: ICMP_HEADER,
Data: _Data_e__Union,
};type
ICMP_HEADER {.bycopy.} = object
Type: uint8
Code: uint8
Checksum: uint16
ICMP_MESSAGE {.bycopy.} = object
Header: ICMP_HEADER
Data: _Data_e__Unionstruct ICMP_HEADER
{
ubyte Type;
ubyte Code;
ushort Checksum;
}
struct ICMP_MESSAGE
{
ICMP_HEADER Header;
_Data_e__Union Data;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; ICMP_MESSAGE サイズ: 8 バイト(x64)
dim st, 2 ; 4byte整数×2(構造体サイズ 8 / 4 切り上げ)
; Header : ICMP_HEADER (+0, 4byte) varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; Data : _Data_e__Union (+4, 4byte) varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global ICMP_HEADER
#field byte Type
#field byte Code
#field short Checksum
#endstruct
#defstruct global ICMP_MESSAGE
#field ICMP_HEADER Header
#field byte Data 4
#endstruct
stdim st, ICMP_MESSAGE ; NSTRUCT 変数を確保
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。