snmp_pdus(3)
π snmp_pdus β the Erlang module that does SNMP PDU glow-ups
okay so bestie, welcome to snmp_pdus(3), an Erlang module definition, and honestly? it's giving protocol translator icon. she encodes and decodes SNMP PDUs, and she does NOT miss. π
β¨ NAME β¨
snmp_pdus β Encode and Decode Functions for SNMP PDUs. periodt.
πΈ DESCRIPTION πΈ
no cap, before you touch this module, snmp_pdus, you NEED to go sit down and study RFC1157, RFC1905 and/or RFC2272 carefully. like, actually carefully. this is not a skim-the-abstract situation, bestie. π
so what does snmp_pdus actually do? she has functions for encoding and decoding SNMP protocol data units (PDUs). short version: this module converts a list of bytes into Erlang record representations, and vice versa. iconic behavior, truly. π¦
the record definitions live in the file snmp/include/snmp_types.hrl. and here's the tea β if snmpv3 is being used, the module that includes snmp_types.hrl must define the constant SNMP_USE_V3 before the header file is included. order matters, she's picky. example:
-define(SNMP_USE_V3, true).
-include_lib("snmp/include/snmp_types.hrl").
also, real talk: encoding and decoding must be done explicitly when you're writing your own Net if process. nobody's doing it for you, main character, you do it yourself. πͺ
π§ DATA TYPES π§
message() :: #message{}.β the message is version dependent, okay?'vsn_hdr'is either a community string (v1 and v2) or a'v3_hdr'record (v3).'data'is either a PDU (v1 and v2c) or a (possibly encrypted)'scopedPdu'. yes literally all of that.msg_id() :: 0..2147483647.β that's the range. respect it. β¨msg_security_model() :: 0..2147483647.β same range, different vibe.pdu() :: #pdu{}.β the PDU record, slay.pdu_type() ::'get-request' | 'get-next-request' | 'get-bulk-request' | 'get-response' | 'set-request' | 'inform-request' | 'snmpv2-trap' | report.β the whole squad, all eight of them. πscoped_pdu() :: #scopedPdu{}.β scoped pdu record, we love her.trappdu() :: #trappdu{}.usm_security_parameters() :: #usmSecurityParameters{}.v3_hdr() :: #v3_hdr{}.version() :: 'version-1' | 'version-2' | 'version-3'.β the three eras, bestie. π
π₯ FUNCTIONS π₯
dec_message(Bytes) -> Message when Bytes :: [byte()], Message :: message().
decodes a list of bytes into an SNMP Message. π
β οΈ heads up though: if there's a v3 message, themsgSecurityParametersare not decoded. they must be explicitly decoded by a call to a security model specific decoding function, e.g.dec_usm_security_parameters/1. and also β if thescopedPDUis encrypted, the OCTET STRING encodedencryptedPDUwill be present in thedatafield. so like, know that going in.
dec_message_only(Bytes) -> Message when Bytes :: [byte()], Message :: message().
decodes a list of bytes into an SNMP Message, but β does not decode the data part of the Message. which means data is still a list of bytes β normally an encoded PDU (v1 and V2), or an encoded and possibly encrypted scopedPDU (v3). leaving that part untouched on purpose, she's got boundaries. π«Ά
dec_pdu(Bytes) -> Pdu when Bytes :: [byte()], Pdu :: trappdu() | pdu().
decodes a list of bytes into an SNMP Pdu. simple, clean, ate. β
dec_scoped_pdu(Bytes) -> ScopedPDU when Bytes :: [byte()], ScopedPDU :: scoped_pdu().
decodes a list of bytes into an SNMP ScopedPdu. πΈ
dec_scoped_pdu_data(Bytes) -> ScopedPduData when Bytes :: [byte()], ScopedPduData :: scoped_pdu() | EncryptedPDU, EncryptedPDU :: [byte()].
decodes a list of bytes into either a scoped pdu record, or β if the scoped pdu was encrypted β to a list of bytes. two possible outcomes, she contains multitudes. π
dec_usm_security_parameters(Bytes) -> UsmSecParams when Bytes :: [byte()], UsmSecParams :: usm_security_parameters().
decodes a list of bytes into an SNMP UsmSecurityParameters. β¨
enc_message(Message) -> Bytes when Message :: message(), Bytes :: [byte()].
encodes a message record to a list of bytes. that's it, that's the function. π
enc_message_only(Message) -> Bytes when Message :: message(), Bytes :: [byte()].
here Message is a record where the data field is assumed to be encoded (a list of bytes). so: if there's a v1 or v2 message, the data field is an encoded PDU, and if there's a v3 message, data is an encoded and possibly encrypted scopedPDU. you bring the encoded bytes, she handles the rest. π
enc_pdu(Pdu) -> Bytes when Pdu :: pdu(), Bytes :: [byte()].
encodes an SNMP Pdu into a list of bytes. π₯
enc_scoped_pdu(ScopedPdu) -> Bytes when ScopedPdu :: scoped_pdu(), Bytes :: [byte()].
encodes an SNMP ScopedPdu into a list of bytes β which can be encrypted, and after encryption, encoded with a call to enc_encrypted_scoped_pdu/1; or it can be used as the data field in a message record, which then can be encoded with enc_message_only/1. two routes, both valid, choose your adventure bestie. π¦
enc_usm_security_parameters(UsmSecParams) -> Bytes when UsmSecParams :: usm_security_parameters(), Bytes :: [byte()].
encodes SNMP UsmSecurityParameters into a list of bytes. π
π reminder for the girlies in the back: study those RFCs first.RFC1157,RFC1905,RFC2272. iykyk.
and that's the whole page, bestie!! π₯³ this glamorous little document was brought to you by Ericsson AB, shipping with snmp 5.20.5 β yeah, snmp_pdus(3), that's her. go encode something. π
β¨π
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms