SnmpSharpNet.SnmpV3Packet.encode C# (CSharp) Метод

encode() публичный Метод

Encode SNMP version 3 packet
Before encoding the packet into a byte array you need to ensure all required information is set. Examples of required information is request type, Vbs (Oid + values pairs), USM settings including SecretName, authentication method and secret (if needed), privacy method and secret (if needed), etc.
public encode ( ) : byte[]
Результат byte[]
        public override byte[] encode()
        {
            byte[] pkey = null;
            byte[] akey = null;
            if (_msgFlags.Authentication && _userSecurityModel.EngineId.Length > 0)
            {
                IAuthenticationDigest auth = Authentication.GetInstance(_userSecurityModel.Authentication);
                if (auth == null)
                    throw new SnmpException(SnmpException.UnsupportedNoAuthPriv, "Invalid authentication protocol.");
                akey = auth.PasswordToKey(_userSecurityModel.AuthenticationSecret, _userSecurityModel.EngineId);
                if (_msgFlags.Privacy && _userSecurityModel.EngineId.Length > 0)
                {
                    IPrivacyProtocol privacyProtocol = PrivacyProtocol.GetInstance(_userSecurityModel.Privacy);
                    if (privacyProtocol == null)
                        throw new SnmpException(SnmpException.UnsupportedPrivacyProtocol, "Specified privacy protocol is not supported.");
                    pkey = privacyProtocol.PasswordToKey(_userSecurityModel.PrivacySecret, _userSecurityModel.EngineId, auth);
                }
            }
            return encode(akey, pkey);
        }

Same methods

SnmpV3Packet::encode ( byte authKey, byte privKey ) : byte[]

Usage Example

 /// <summary>
 /// Send SNMP version 3 Trap notification
 /// </summary>
 /// <param name="packet">SNMP v3 Trap packet class</param>
 /// <param name="peer">Manager (receiver) IP address</param>
 /// <param name="port">Manager (receiver) UDP port number</param>
 public void SendV3Trap(SnmpV3Packet packet, IpAddress peer, int port)
 {
     if (packet.Pdu.Type != PduType.V2Trap)
     {
         throw new SnmpInvalidPduTypeException("Invalid Pdu type.");
     }
     byte[] outBuffer = packet.encode();
     _sock.SendTo(outBuffer, new IPEndPoint((IPAddress)peer, port));
 }
All Usage Examples Of SnmpSharpNet.SnmpV3Packet::encode