檢視原始碼 snmp_pdus (snmp v5.18)

SNMP PDU 的編碼與解碼函式

在使用此模組 snmp_pdus 之前,應仔細研讀 RFC1157、RFC1905 和/或 RFC2272。

模組 snmp_pdus 包含用於編碼和解碼 SNMP 協定資料單元 (PDU) 的函式。簡而言之,此模組會將位元組列表轉換為 Erlang 記錄表示法,反之亦然。記錄定義可以在檔案 snmp/include/snmp_types.hrl 中找到。如果使用 snmpv3,則包含 snmp_types.hrl 的模組必須在包含標頭檔之前定義常數 SNMP_USE_V3。範例

-define(SNMP_USE_V3, true).
-include_lib("snmp/include/snmp_types.hrl").

當編寫自己的網路處理程序時,必須明確地執行編碼和解碼。

摘要

類型

訊息與版本相關。「vsn_hdr」是社群字串(v1 和 v2)或「v3_hdr」記錄(v3)。「data」是 PDU(v1 和 v2c)或(可能已加密的)「scopedPdu」。

函式

將位元組列表解碼為 SNMP 訊息。請注意,如果存在 v3 訊息,則不會解碼 msgSecurityParameters。它們必須由呼叫特定安全性模型解碼函式(例如 dec_usm_security_parameters/1)明確解碼。另請注意,如果 scopedPDU 已加密,則在 data 欄位中會出現編碼的 OCTET STRING encryptedPDU

將位元組列表解碼為 SNMP 訊息,但不解碼訊息的資料部分。這表示 data 仍然是位元組列表,通常是編碼的 PDU(v1 和 V2)或編碼且可能已加密的 scopedPDU(v3)。

將位元組列表解碼為 SNMP Pdu。

將位元組列表解碼為 SNMP ScopedPdu。

將位元組列表解碼為 scoped pdu 記錄,或者 - 如果 scoped pdu 已加密 - 解碼為位元組列表。

將位元組列表解碼為 SNMP UsmSecurityParameters。

將訊息記錄編碼為位元組列表。

Message 是一個記錄,其中 data 欄位假設為已編碼(位元組列表)。如果存在 v1 或 v2 訊息,則 data 欄位是已編碼的 PDU,如果存在 v3 訊息,則 data 是已編碼且可能已加密的 scopedPDU

將 SNMP Pdu 編碼為位元組列表。

將 SNMP ScopedPdu 編碼為位元組列表,該列表可以加密,並且在加密後,可以呼叫 enc_encrypted_scoped_pdu/1 來編碼;或者可以用作 message 記錄中的 data 欄位,然後可以使用 enc_message_only/1 來編碼。

將 SNMP UsmSecurityParameters 編碼為位元組列表。

類型

-type message() :: #message{version :: term(), vsn_hdr :: term(), data :: term()}.

訊息與版本相關。「vsn_hdr」是社群字串(v1 和 v2)或「v3_hdr」記錄(v3)。「data」是 PDU(v1 和 v2c)或(可能已加密的)「scopedPdu」。

-type msg_id() :: 0..2147483647.
-type msg_security_model() :: 0..2147483647.
-type pdu() ::
          #pdu{type :: term(),
               request_id :: term(),
               error_status :: term(),
               error_index :: term(),
               varbinds :: term()}.
-type pdu_type() ::
          'get-request' | 'get-next-request' | 'get-bulk-request' | 'get-response' | 'set-request' |
          'inform-request' | 'snmpv2-trap' | report.
-type scoped_pdu() :: #scopedPdu{contextEngineID :: term(), contextName :: term(), data :: term()}.
-type trappdu() ::
          #trappdu{enterprise :: term(),
                   agent_addr :: term(),
                   generic_trap :: term(),
                   specific_trap :: term(),
                   time_stamp :: term(),
                   varbinds :: term()}.
此類型的連結

usm_security_parameters()

檢視原始碼
-type usm_security_parameters() ::
          #usmSecurityParameters{msgAuthoritativeEngineID :: term(),
                                 msgAuthoritativeEngineBoots :: term(),
                                 msgAuthoritativeEngineTime :: term(),
                                 msgUserName :: term(),
                                 msgAuthenticationParameters :: term(),
                                 msgPrivacyParameters :: term()}.
-type v3_hdr() ::
          #v3_hdr{msgID :: term(),
                  msgMaxSize :: term(),
                  msgFlags :: term(),
                  msgSecurityModel :: term(),
                  msgSecurityParameters :: term(),
                  hdr_size :: term()}.
-type version() :: 'version-1' | 'version-2' | 'version-3'.

函式

-spec dec_message(Bytes) -> Message when Bytes :: [byte()], Message :: message().

將位元組列表解碼為 SNMP 訊息。請注意,如果存在 v3 訊息,則不會解碼 msgSecurityParameters。它們必須由呼叫特定安全性模型解碼函式(例如 dec_usm_security_parameters/1)明確解碼。另請注意,如果 scopedPDU 已加密,則在 data 欄位中會出現編碼的 OCTET STRING encryptedPDU

此函式的連結

dec_message_only(Bytes)

檢視原始碼
-spec dec_message_only(Bytes) -> Message when Bytes :: [byte()], Message :: message().

將位元組列表解碼為 SNMP 訊息,但不解碼訊息的資料部分。這表示 data 仍然是位元組列表,通常是編碼的 PDU(v1 和 V2)或編碼且可能已加密的 scopedPDU(v3)。

-spec dec_pdu(Bytes) -> Pdu when Bytes :: [byte()], Pdu :: trappdu() | pdu().

將位元組列表解碼為 SNMP Pdu。

-spec dec_scoped_pdu(Bytes) -> ScopedPDU when Bytes :: [byte()], ScopedPDU :: scoped_pdu().

將位元組列表解碼為 SNMP ScopedPdu。

此函式的連結

dec_scoped_pdu_data(Bytes)

檢視原始碼
-spec dec_scoped_pdu_data(Bytes) -> ScopedPduData
                             when
                                 Bytes :: [byte()],
                                 ScopedPduData :: scoped_pdu() | EncryptedPDU,
                                 EncryptedPDU :: [byte()].

將位元組列表解碼為 scoped pdu 記錄,或者 - 如果 scoped pdu 已加密 - 解碼為位元組列表。

此函式的連結

dec_usm_security_parameters(Bytes)

檢視原始碼
-spec dec_usm_security_parameters(Bytes) -> UsmSecParams
                                     when Bytes :: [byte()], UsmSecParams :: usm_security_parameters().

將位元組列表解碼為 SNMP UsmSecurityParameters。

-spec enc_message(Message) -> Bytes when Message :: message(), Bytes :: [byte()].

將訊息記錄編碼為位元組列表。

此函式的連結

enc_message_only(Message)

檢視原始碼
-spec enc_message_only(Message) -> Bytes when Message :: message(), Bytes :: [byte()].

Message 是一個記錄,其中 data 欄位假設為已編碼(位元組列表)。如果存在 v1 或 v2 訊息,則 data 欄位是已編碼的 PDU,如果存在 v3 訊息,則 data 是已編碼且可能已加密的 scopedPDU

-spec enc_pdu(Pdu) -> Bytes when Pdu :: pdu(), Bytes :: [byte()].

將 SNMP Pdu 編碼為位元組列表。

此函式的連結

enc_scoped_pdu(ScopedPdu)

檢視原始碼
-spec enc_scoped_pdu(ScopedPdu) -> Bytes when ScopedPdu :: scoped_pdu(), Bytes :: [byte()].

將 SNMP ScopedPdu 編碼為位元組列表,該列表可以加密,並且在加密後,可以呼叫 enc_encrypted_scoped_pdu/1 來編碼;或者可以用作 message 記錄中的 data 欄位,然後可以使用 enc_message_only/1 來編碼。

此函式的連結

enc_usm_security_parameters(UsmSecParams)

檢視原始碼
-spec enc_usm_security_parameters(UsmSecParams) -> Bytes
                                     when UsmSecParams :: usm_security_parameters(), Bytes :: [byte()].

將 SNMP UsmSecurityParameters 編碼為位元組列表。