[][src]Crate snmp_mp

Primitives to send and receive SNMP messages.

Supported PDU types:

  • GetRequest
  • GetNextRequest
  • GetBulkRequest
  • Response
  • SetRequest
  • SNMPv2-Trap
  • InformRequest

Examples

use snmp_mp::{ObjectIdent, SnmpMsg, VarBind};

let mut msg = SnmpMsg::new(1);
msg.set_reportable_flag();

if let Some(scoped_pdu) = msg.scoped_pdu_data.plaintext_mut() {
    let sys_desc = ObjectIdent::from_slice(&[0x01, 0x03, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00]);
    let var_bind = VarBind::new(sys_desc);

    scoped_pdu
        .set_request_id(1)
        .set_engine_id(b"context_engine_id")
        .push_var_bind(var_bind);
}

let encoded_msg = msg.encode();
// Send the encoded message over the network.

encrypt_scoped_pdu and decrypt_scoped_pdu are provided to make it easy to use a security model:

msg.encrypt_scoped_pdu(|encoded_scoped_pdu| {
    // A security model encrypts and returns the scoped PDU.
    // let (encrypted_scoped_pdu, priv_params) =
    //     priv_key.encrypt(encoded_scoped_pdu, &security_params, salt);
    // security_params.set_priv_params(&priv_params);

    encrypted_scoped_pdu
});

msg.decrypt_scoped_pdu(|encrypted_scoped_pdu| {
    // A security model returns the decrypted scoped PDU wrapped in an `Option`.
    // priv_key
    //     .decrypt(encrypted_scoped_pdu, &security_params)
    //     .ok()
});

Structs

ObjectIdent

Represents an object identifier.

ScopedPdu

Scoped PDU contained in an SNMP message.

SnmpMsg

SNMP message that can be encoded and sent over the network.

VarBind

Represents a variable binding.

Enums

MsgProcessingError

The error type for message processing related operations.

PduErrorStatus

Response PDU error status.

PduType

Represents a PDU type.

ScopedPduData

Represents either the plaintext scoped PDU if the privacy flag is not set, or it represents an encrypted PDU encoded as a byte string.

VarValue

Represents a variable binding value.

Type Definitions

MsgProcessingResult

Type alias for the result of a message processing operation.