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

ICMPV4_TIMESTAMP_MESSAGE

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

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

フィールド

フィールドサイズx64x86説明
HeaderICMP_MESSAGE8+0+0タイムスタンプメッセージのヘッダーを保持するICMP_MESSAGE。
OriginateTimestampDWORD4+8+8送信側が要求を送出した時刻(深夜からのミリ秒)を示す。
ReceiveTimestampDWORD4+12+12応答側が要求を受信した時刻を示す。
TransmitTimestampDWORD4+16+16応答側が応答を送出した時刻を示す。

各言語での定義

#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;

// ICMPV4_TIMESTAMP_MESSAGE  (x64 20 / x86 20 バイト)
typedef struct ICMPV4_TIMESTAMP_MESSAGE {
    ICMP_MESSAGE Header;
    DWORD OriginateTimestamp;
    DWORD ReceiveTimestamp;
    DWORD TransmitTimestamp;
} ICMPV4_TIMESTAMP_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;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ICMPV4_TIMESTAMP_MESSAGE
{
    public ICMP_MESSAGE Header;
    public uint OriginateTimestamp;
    public uint ReceiveTimestamp;
    public uint TransmitTimestamp;
}
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 Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ICMPV4_TIMESTAMP_MESSAGE
    Public Header As ICMP_MESSAGE
    Public OriginateTimestamp As UInteger
    Public ReceiveTimestamp As UInteger
    Public TransmitTimestamp As UInteger
End Structure
import 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),
    ]

class ICMPV4_TIMESTAMP_MESSAGE(ctypes.Structure):
    _fields_ = [
        ("Header", ICMP_MESSAGE),
        ("OriginateTimestamp", wintypes.DWORD),
        ("ReceiveTimestamp", wintypes.DWORD),
        ("TransmitTimestamp", wintypes.DWORD),
    ]
#[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,
}

#[repr(C)]
pub struct ICMPV4_TIMESTAMP_MESSAGE {
    pub Header: ICMP_MESSAGE,
    pub OriginateTimestamp: u32,
    pub ReceiveTimestamp: u32,
    pub TransmitTimestamp: u32,
}
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 ICMPV4_TIMESTAMP_MESSAGE struct {
	Header ICMP_MESSAGE
	OriginateTimestamp uint32
	ReceiveTimestamp uint32
	TransmitTimestamp uint32
}
type
  ICMP_HEADER = record
    Type: Byte;
    Code: Byte;
    Checksum: Word;
  end;

  ICMP_MESSAGE = record
    Header: ICMP_HEADER;
    Data: _Data_e__Union;
  end;

  ICMPV4_TIMESTAMP_MESSAGE = record
    Header: ICMP_MESSAGE;
    OriginateTimestamp: DWORD;
    ReceiveTimestamp: DWORD;
    TransmitTimestamp: DWORD;
  end;
const ICMP_HEADER = extern struct {
    Type: u8,
    Code: u8,
    Checksum: u16,
};

const ICMP_MESSAGE = extern struct {
    Header: ICMP_HEADER,
    Data: _Data_e__Union,
};

const ICMPV4_TIMESTAMP_MESSAGE = extern struct {
    Header: ICMP_MESSAGE,
    OriginateTimestamp: u32,
    ReceiveTimestamp: u32,
    TransmitTimestamp: u32,
};
type
  ICMP_HEADER {.bycopy.} = object
    Type: uint8
    Code: uint8
    Checksum: uint16

  ICMP_MESSAGE {.bycopy.} = object
    Header: ICMP_HEADER
    Data: _Data_e__Union

  ICMPV4_TIMESTAMP_MESSAGE {.bycopy.} = object
    Header: ICMP_MESSAGE
    OriginateTimestamp: uint32
    ReceiveTimestamp: uint32
    TransmitTimestamp: uint32
struct ICMP_HEADER
{
    ubyte Type;
    ubyte Code;
    ushort Checksum;
}

struct ICMP_MESSAGE
{
    ICMP_HEADER Header;
    _Data_e__Union Data;
}

struct ICMPV4_TIMESTAMP_MESSAGE
{
    ICMP_MESSAGE Header;
    uint OriginateTimestamp;
    uint ReceiveTimestamp;
    uint TransmitTimestamp;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; ICMPV4_TIMESTAMP_MESSAGE サイズ: 20 バイト(x64)
dim st, 5    ; 4byte整数×5(構造体サイズ 20 / 4 切り上げ)
; Header : ICMP_MESSAGE (+0, 8byte)  varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; OriginateTimestamp : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; ReceiveTimestamp : DWORD (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; TransmitTimestamp : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; ※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

#defstruct global ICMPV4_TIMESTAMP_MESSAGE
    #field ICMP_MESSAGE Header
    #field int OriginateTimestamp
    #field int ReceiveTimestamp
    #field int TransmitTimestamp
#endstruct

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