ホーム › Networking.WinSock › ARP_HEADER
ARP_HEADER
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| HardwareAddressSpace | WORD | 2 | +0 | +0 | ハードウェアアドレス種別(Ethernet=1等)を示す。 |
| ProtocolAddressSpace | WORD | 2 | +2 | +2 | プロトコルアドレス種別(IPv4=0x0800等)を示す。 |
| HardwareAddressLength | BYTE | 1 | +4 | +4 | ハードウェアアドレスの長さをバイト単位で示す。 |
| ProtocolAddressLength | BYTE | 1 | +5 | +5 | プロトコルアドレスの長さをバイト単位で示す。 |
| Opcode | WORD | 2 | +6 | +6 | ARP操作コード(要求=1,応答=2)を示す。 |
| SenderHardwareAddress | BYTE | 1 | +8 | +8 | 送信元ハードウェアアドレス以降の可変部の先頭。 |
各言語での定義
#include <windows.h>
// ARP_HEADER (x64 10 / x86 10 バイト)
typedef struct ARP_HEADER {
WORD HardwareAddressSpace;
WORD ProtocolAddressSpace;
BYTE HardwareAddressLength;
BYTE ProtocolAddressLength;
WORD Opcode;
BYTE SenderHardwareAddress[1];
} ARP_HEADER;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ARP_HEADER
{
public ushort HardwareAddressSpace;
public ushort ProtocolAddressSpace;
public byte HardwareAddressLength;
public byte ProtocolAddressLength;
public ushort Opcode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] SenderHardwareAddress;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ARP_HEADER
Public HardwareAddressSpace As UShort
Public ProtocolAddressSpace As UShort
Public HardwareAddressLength As Byte
Public ProtocolAddressLength As Byte
Public Opcode As UShort
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public SenderHardwareAddress() As Byte
End Structureimport ctypes
from ctypes import wintypes
class ARP_HEADER(ctypes.Structure):
_fields_ = [
("HardwareAddressSpace", ctypes.c_ushort),
("ProtocolAddressSpace", ctypes.c_ushort),
("HardwareAddressLength", ctypes.c_ubyte),
("ProtocolAddressLength", ctypes.c_ubyte),
("Opcode", ctypes.c_ushort),
("SenderHardwareAddress", ctypes.c_ubyte * 1),
]#[repr(C)]
pub struct ARP_HEADER {
pub HardwareAddressSpace: u16,
pub ProtocolAddressSpace: u16,
pub HardwareAddressLength: u8,
pub ProtocolAddressLength: u8,
pub Opcode: u16,
pub SenderHardwareAddress: [u8; 1],
}import "golang.org/x/sys/windows"
type ARP_HEADER struct {
HardwareAddressSpace uint16
ProtocolAddressSpace uint16
HardwareAddressLength byte
ProtocolAddressLength byte
Opcode uint16
SenderHardwareAddress [1]byte
}type
ARP_HEADER = record
HardwareAddressSpace: Word;
ProtocolAddressSpace: Word;
HardwareAddressLength: Byte;
ProtocolAddressLength: Byte;
Opcode: Word;
SenderHardwareAddress: array[0..0] of Byte;
end;const ARP_HEADER = extern struct {
HardwareAddressSpace: u16,
ProtocolAddressSpace: u16,
HardwareAddressLength: u8,
ProtocolAddressLength: u8,
Opcode: u16,
SenderHardwareAddress: [1]u8,
};type
ARP_HEADER {.bycopy.} = object
HardwareAddressSpace: uint16
ProtocolAddressSpace: uint16
HardwareAddressLength: uint8
ProtocolAddressLength: uint8
Opcode: uint16
SenderHardwareAddress: array[1, uint8]struct ARP_HEADER
{
ushort HardwareAddressSpace;
ushort ProtocolAddressSpace;
ubyte HardwareAddressLength;
ubyte ProtocolAddressLength;
ushort Opcode;
ubyte[1] SenderHardwareAddress;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; ARP_HEADER サイズ: 10 バイト(x64)
dim st, 3 ; 4byte整数×3(構造体サイズ 10 / 4 切り上げ)
; HardwareAddressSpace : WORD (+0, 2byte) wpoke st,0,値 / 値 = wpeek(st,0)
; ProtocolAddressSpace : WORD (+2, 2byte) wpoke st,2,値 / 値 = wpeek(st,2)
; HardwareAddressLength : BYTE (+4, 1byte) poke st,4,値 / 値 = peek(st,4)
; ProtocolAddressLength : BYTE (+5, 1byte) poke st,5,値 / 値 = peek(st,5)
; Opcode : WORD (+6, 2byte) wpoke st,6,値 / 値 = wpeek(st,6)
; SenderHardwareAddress : BYTE (+8, 1byte) varptr(st)+8 を基点に操作(1byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global ARP_HEADER
#field short HardwareAddressSpace
#field short ProtocolAddressSpace
#field byte HardwareAddressLength
#field byte ProtocolAddressLength
#field short Opcode
#field byte SenderHardwareAddress 1
#endstruct
stdim st, ARP_HEADER ; NSTRUCT 変数を確保
st->HardwareAddressSpace = 100
mes "HardwareAddressSpace=" + st->HardwareAddressSpace