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

SnmpVarBind

構造体
サイズx64: 32 バイト / x86: 24 バイトパッキング4

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

フィールド

フィールドサイズx64x86説明
nameAsnObjectIdentifier12/8+0+0対象オブジェクトの OID を表すオブジェクト識別子。
valueAsnAny20/16+12+8OID に対応付けられた値を保持する AsnAny 構造体。

各言語での定義

#include <windows.h>

// AsnObjectIdentifier  (x64 12 / x86 8 バイト)
#pragma pack(push, 4)
typedef struct AsnObjectIdentifier {
    DWORD idLength;
    DWORD* ids;
} AsnObjectIdentifier;
#pragma pack(pop)

// AsnAny  (x64 20 / x86 16 バイト)
#pragma pack(push, 4)
typedef struct AsnAny {
    BYTE asnType;
    _asnValue_e__Union asnValue;
} AsnAny;
#pragma pack(pop)

// SnmpVarBind  (x64 32 / x86 24 バイト)
#pragma pack(push, 4)
typedef struct SnmpVarBind {
    AsnObjectIdentifier name;
    AsnAny value;
} SnmpVarBind;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)]
public struct AsnObjectIdentifier
{
    public uint idLength;
    public IntPtr ids;
}

[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)]
public struct AsnAny
{
    public byte asnType;
    public _asnValue_e__Union asnValue;
}

[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)]
public struct SnmpVarBind
{
    public AsnObjectIdentifier name;
    public AsnAny value;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)>
Public Structure AsnObjectIdentifier
    Public idLength As UInteger
    Public ids As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)>
Public Structure AsnAny
    Public asnType As Byte
    Public asnValue As _asnValue_e__Union
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)>
Public Structure SnmpVarBind
    Public name As AsnObjectIdentifier
    Public value As AsnAny
End Structure
import ctypes
from ctypes import wintypes

class AsnObjectIdentifier(ctypes.Structure):
    _pack_ = 4
    _fields_ = [
        ("idLength", wintypes.DWORD),
        ("ids", ctypes.c_void_p),
    ]

class AsnAny(ctypes.Structure):
    _pack_ = 4
    _fields_ = [
        ("asnType", ctypes.c_ubyte),
        ("asnValue", _asnValue_e__Union),
    ]

class SnmpVarBind(ctypes.Structure):
    _pack_ = 4
    _fields_ = [
        ("name", AsnObjectIdentifier),
        ("value", AsnAny),
    ]
#[repr(C, packed(4))]
pub struct AsnObjectIdentifier {
    pub idLength: u32,
    pub ids: *mut core::ffi::c_void,
}

#[repr(C, packed(4))]
pub struct AsnAny {
    pub asnType: u8,
    pub asnValue: _asnValue_e__Union,
}

#[repr(C, packed(4))]
pub struct SnmpVarBind {
    pub name: AsnObjectIdentifier,
    pub value: AsnAny,
}
import "golang.org/x/sys/windows"

type AsnObjectIdentifier struct {
	idLength uint32
	ids uintptr
}

type AsnAny struct {
	asnType byte
	asnValue _asnValue_e__Union
}

type SnmpVarBind struct {
	name AsnObjectIdentifier
	value AsnAny
}
type
  AsnObjectIdentifier = packed record
    idLength: DWORD;
    ids: Pointer;
  end;

  AsnAny = packed record
    asnType: Byte;
    asnValue: _asnValue_e__Union;
  end;

  SnmpVarBind = packed record
    name: AsnObjectIdentifier;
    value: AsnAny;
  end;
const AsnObjectIdentifier = extern struct {
    idLength: u32,
    ids: ?*anyopaque,
};

const AsnAny = extern struct {
    asnType: u8,
    asnValue: _asnValue_e__Union,
};

const SnmpVarBind = extern struct {
    name: AsnObjectIdentifier,
    value: AsnAny,
};
type
  AsnObjectIdentifier {.packed.} = object
    idLength: uint32
    ids: pointer

  AsnAny {.packed.} = object
    asnType: uint8
    asnValue: _asnValue_e__Union

  SnmpVarBind {.packed.} = object
    name: AsnObjectIdentifier
    value: AsnAny
align(4)
struct AsnObjectIdentifier
{
    uint idLength;
    void* ids;
}

align(4)
struct AsnAny
{
    ubyte asnType;
    _asnValue_e__Union asnValue;
}

align(4)
struct SnmpVarBind
{
    AsnObjectIdentifier name;
    AsnAny value;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; SnmpVarBind サイズ: 24 バイト(x86)
dim st, 6    ; 4byte整数×6(構造体サイズ 24 / 4 切り上げ)
; name : AsnObjectIdentifier (+0, 8byte)  varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; value : AsnAny (+8, 16byte)  varptr(st)+8 を基点に操作(16byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SnmpVarBind サイズ: 32 バイト(x64)
dim st, 8    ; 4byte整数×8(構造体サイズ 32 / 4 切り上げ)
; name : AsnObjectIdentifier (+0, 12byte)  varptr(st)+0 を基点に操作(12byte:入れ子/配列)
; value : AsnAny (+12, 20byte)  varptr(st)+12 を基点に操作(20byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global AsnObjectIdentifier, pack=4
    #field int idLength
    #field intptr ids
#endstruct

#defstruct global AsnAny, pack=4
    #field byte asnType
    #field byte asnValue 16
#endstruct

#defstruct global SnmpVarBind, pack=4
    #field AsnObjectIdentifier name
    #field AsnAny value
#endstruct

stdim st, SnmpVarBind        ; NSTRUCT 変数を確保