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