/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// java imports
//
/**
* A partially decoded representation of an SNMP packet. It contains
* the information contained in any SNMP message (SNMPv1, SNMPv2 or
* SNMPv3).
* <p><b>This API is a Sun Microsystems internal API and is subject
* to change without notice.</b></p>
* @since 1.5
*/
/**
* The protocol version.
* <P><CODE>decodeMessage</CODE> and <CODE>encodeMessage</CODE> do not
* perform any check on this value.
* <BR><CODE>decodeSnmpPdu</CODE> and <CODE>encodeSnmpPdu</CODE> only
* accept the values 0 (for SNMPv1), 1 (for SNMPv2) and 3 (for SNMPv3).
*/
/**
* Encoding of the PDU.
* <P>This is usually the BER encoding of the PDU's syntax
* defined in RFC1157 and RFC1902. However, this can be authenticated
* or encrypted data (but you need to implemented your own
* <CODE>SnmpPduFactory</CODE> class).
*/
/**
* Number of useful bytes in the <CODE>data</CODE> field.
*/
/**
* Source or destination address.
* <BR>For an incoming message it's the source.
* For an outgoing message it's the destination.
*/
/**
* Source or destination port.
* <BR>For an incoming message it's the source.
* For an outgoing message it's the destination.
*/
/**
* Security parameters. Contain informations according to Security Model (Usm, community string based, ...).
*/
/**
* Returns the encoded SNMP version present in the passed byte array.
* @param data The unmarshalled SNMP message.
* @return The SNMP version (0, 1 or 3).
*/
throws SnmpStatusException {
int version = 0;
try {
bdec.openSequence();
}
catch(BerException x) {
throw new SnmpStatusException("Invalid encoding") ;
}
try {
}
catch(BerException x) {
}
return version;
}
/**
* Returns the associated request ID.
* @param data The flat message.
* @return The request ID.
*/
/**
* Encodes this message and puts the result in the specified byte array.
* For internal use only.
*
* @param outputBytes An array to receive the resulting encoding.
*
* @exception ArrayIndexOutOfBoundsException If the result does not fit
* into the specified array.
*/
throws SnmpTooBigException;
/**
* Decodes the specified bytes and initializes this message.
* For internal use only.
*
* @param inputBytes The bytes to be decoded.
*
* @exception SnmpStatusException If the specified bytes are not a valid encoding.
*/
throws SnmpStatusException;
/**
* Initializes this message with the specified <CODE>pdu</CODE>.
* <P>
* This method initializes the data field with an array of
* <CODE>maxDataLength</CODE> bytes. It encodes the <CODE>pdu</CODE>.
* The resulting encoding is stored in the data field
* and the length of the encoding is stored in <CODE>dataLength</CODE>.
* <p>
* If the encoding length exceeds <CODE>maxDataLength</CODE>,
* the method throws an exception.
*
* @param pdu The PDU to be encoded.
* @param maxDataLength The maximum length permitted for the data field.
*
* @exception SnmpStatusException If the specified <CODE>pdu</CODE> is not valid.
* @exception SnmpTooBigException If the resulting encoding does not fit
* into <CODE>maxDataLength</CODE> bytes.
* @exception ArrayIndexOutOfBoundsException If the encoding exceeds <CODE>maxDataLength</CODE>.
*/
throws SnmpStatusException, SnmpTooBigException;
/**
* Gets the PDU encoded in this message.
* <P>
* This method decodes the data field and returns the resulting PDU.
*
* @return The resulting PDU.
* @exception SnmpStatusException If the encoding is not valid.
*/
throws SnmpStatusException;
/**
* Dumps the content of a byte buffer using hexadecimal form.
*
* @param b The buffer to dump.
* @param offset The position of the first byte to be dumped.
* @param len The number of bytes to be dumped starting from offset.
*
* @return The string containing the dump.
*/
int k = 1 ;
int j = b[i] & 0xFF ;
k++ ;
if (k%16 == 0) {
k = 1 ;
} else
}
}
/**
* Dumps this message in a string.
*
* @return The string containing the dump.
*/
}
else {
}
}
/**
* For SNMP Runtime private use only.
*/
throws SnmpStatusException, SnmpTooBigException {
//
// Remember: the encoder does backward encoding
//
int encodedVarBindCount = 0 ;
try {
benc.openSequence() ;
if (varBindList != null) {
benc.openSequence() ;
benc.closeSequence() ;
}
}
}
benc.closeSequence() ;
}
catch(ArrayIndexOutOfBoundsException x) {
throw new SnmpTooBigException(encodedVarBindCount) ;
}
}
/**
* For SNMP Runtime private use only.
*/
SnmpValue v)throws SnmpStatusException {
if (v == null) {
}
else if (v instanceof SnmpIpAddress) {
}
else if (v instanceof SnmpCounter) {
}
else if (v instanceof SnmpGauge) {
}
else if (v instanceof SnmpTimeticks) {
}
else if (v instanceof SnmpOpaque) {
}
else if (v instanceof SnmpInt) {
}
else if (v instanceof SnmpString) {
}
else if (v instanceof SnmpOid) {
}
else if (v instanceof SnmpCounter64) {
if (version == snmpVersionOne) {
throw new SnmpStatusException("Invalid value for SNMP v1 : " + v) ;
}
}
else if (v instanceof SnmpNull) {
throw new SnmpStatusException("Invalid value for SNMP v1 : " + v) ;
}
if ((version == snmpVersionTwo) &&
throw new SnmpStatusException("Invalid value " + v) ;
}
}
else {
throw new SnmpStatusException("Invalid value " + v) ;
}
}
/**
* For SNMP Runtime private use only.
*/
throws BerException {
bdec.openSequence() ;
while (bdec.cannotCloseSequence()) {
bdec.openSequence() ;
bdec.closeSequence() ;
}
bdec.closeSequence() ;
return varBindList ;
}
/**
* For SNMP Runtime private use only.
*/
throws BerException {
// bugId 4641696 : RuntimeExceptions must be transformed in
// BerException.
switch(tag) {
//
// Simple syntax
//
case BerDecoder.IntegerTag :
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpInt from decoded value.");
}
break ;
case BerDecoder.OctetStringTag :
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpString from decoded value.");
}
break ;
case BerDecoder.OidTag :
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpOid from decoded value.");
}
break ;
case BerDecoder.NullTag :
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpNull from decoded value.");
}
break ;
//
// Application syntax
//
case SnmpValue.IpAddressTag :
try {
} catch (RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpIpAddress from decoded value.");
}
break ;
case SnmpValue.CounterTag :
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpCounter from decoded value.");
}
break ;
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpGauge from decoded value.");
}
break ;
case SnmpValue.TimeticksTag :
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpTimeticks from decoded value.");
}
break ;
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpOpaque from decoded value.");
}
break ;
//
// V2 syntaxes
//
case SnmpValue.Counter64Tag :
if (version == snmpVersionOne) {
}
try {
} catch(RuntimeException r) {
throw new BerException();
// BerException("Can't build SnmpCounter64 from decoded value.");
}
break ;
case SnmpVarBind.errNoSuchObjectTag :
if (version == snmpVersionOne) {
}
break ;
case SnmpVarBind.errNoSuchInstanceTag :
if (version == snmpVersionOne) {
}
break ;
case SnmpVarBind.errEndOfMibViewTag :
if (version == snmpVersionOne) {
}
break ;
default:
throw new BerException() ;
}
return result ;
}
}