⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asnobject.java

📁 snmp zip 包开发snmp协议
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                  + ", correct = " + me.isCorrect);        }        return me;    }    /** Adds a child to the sequence     */    AsnObject add (AsnObject child)    {        return child;    }    /** recursively look for a pduSequence object     *  if not overridden - then not a sequence -     */    AsnObject findPdu()    {        return null;    }    /** recursively look for a pduSequence object     *  if not overridden - then not a sequence -     */    AsnObject findTrapPduv1()    {        return null;    }    /**      * Output ASN header.     */    void AsnBuildHeader(OutputStream out, byte t, int length)           throws IOException    {        int count;        type = t;        // Type byte        out.write(type);        // Length bytes        count = getLengthBytes(length);        headerLength = count + 1;        contentsLength = length;        if (debug > 10)        {            System.out.println("AsnBuildHeader(): "                + "type = 0x" + SnmpUtilities.toHex(type)                + ", headerLength = " + headerLength                + ", contentsLength = " + contentsLength);        }        if (count > 1)        {            // Write long form prefix byte            --count;            byte tmp = (byte) (0x80 | (byte) count);            out.write(tmp);        }        while(count!=0)        {            // Write length bytes            out.write((byte)((length >> (--count << 3)) & 0xFF));        }    }    int size() throws EncodingException    {         return 0;     }    /**      * Returns length field size for a packet length.     * Returns:     * 1   if length will fit in short form (0x00-0x7f)     * 2+  if length >= 0x80     */    int getLengthBytes(int length)    {        int mask, count;        if (length < 0x80)        {            // Short form.. 1 byte            return 1;        }        else        {          // Long form.. prefix byte + length bytes          mask = 0xFF000000;          for(count=4; (length&mask)==0; count--)          {              mask >>= 8;          }          return count+1;        }    }    int getLengthPacket(InputStream in) throws IOException    {        int length = 0;        byte mask =(byte) 0x7f;        byte len = (byte) in.read();        if ((0x80 & len) != 0)        {            // long form            int count = (mask & len);            if (count < 4)            {                byte data[] = new byte[count];                int n = in.read(data, 0, count);                if (n !=  count)                {                    throw new IOException("AsnObject.getLengthPacket(): Not enough data");                }                 else                 {                    /*                     * Thanks to Julien Conan (jconan@protego.net)                      * for improving this code.                     */                    DataInputStream dis = new DataInputStream(                          new ByteArrayInputStream(data));                    for (n=0; n<count; n++)                    {                        length = (length << 8) + dis.readUnsignedByte();                    }                }            }        }         else        {            // short form            length = (int) (mask & len);        }        return (length);    }    int getContentsPos()    {        return startPos + headerLength;    }    int getContentsLength()    {        return contentsLength;    }    /**     * Returns the type of this Asn object, such as ASN_INTEGER or     * IPADDRESS.      *     * Note, the name of this method is deceiving; It has     * nothing (more) to do with a response.     *     * @return The AsnObject type.     * @see #getRespTypeString()     * @see SnmpConstants     */    public byte getRespType()    {        return type;    }    /**     * Returns the object type as string, such as "ASN_INTEGER" or     * "IPADDRESS".     *     * Note, the name of this method is deceiving; It has     * nothing (more) to do with a response.     *     * @return The AsnObject type.     * @see #getRespType()     * @see SnmpConstants     */    public String getRespTypeString()    {        String str = "";        switch(type)        {            case ASN_BOOLEAN:                str = "ASN_BOOLEAN";                break;            case ASN_INTEGER:                str = "ASN_INTEGER";                break;            case ASN_BIT_STR:                str = "ASN_BIT_STR";                break;            case ASN_OCTET_STR:                str = "ASN_OCTET_STR";                break;            case ASN_NULL:                str = "ASN_NULL";                break;            case ASN_OBJECT_ID:                str = "ASN_OBJECT_ID";                break;            case ASN_SEQUENCE:                str = "ASN_SEQUENCE";                break;            case ASN_SET:                str = "ASN_SET";                break;            case ASN_UNIVERSAL:                str = "ASN_UNIVERSAL";                break;            case ASN_PRIVATE:                str = "ASN_PRIVATE";                break;            case ASN_CONSTRUCTOR:                str = "ASN_CONSTRUCTOR";                break;            case ASN_EXTENSION_ID:                str = "ASN_EXTENSION_ID";                break;            case IPADDRESS:                str = "IPADDRESS";                break;            case COUNTER:                str = "COUNTER";                break;            case GAUGE:                str = "GAUGE";                break;            case TIMETICKS:                str = "TIMETICKS";                break;            case OPAQUE:                str = "OPAQUE";                break;            case NSAP_ADDRESS:                str = "NSAP_ADDRESS";                break;            case COUNTER64:                str = "COUNTER64";                break;            case OBSOLETED_RFC1442_UINTEGER32:                str = "OBSOLETED_RFC1442_UINTEGER32 (SMI v1)";                break;            case CONS_SEQ:                str = "CONS_SEQ";                break;            case SNMP_VAR_NOSUCHOBJECT:                str = "SNMP_VAR_NOSUCHOBJECT";                break;            case SNMP_VAR_NOSUCHINSTANCE:                str = "SNMP_VAR_NOSUCHINSTANCE";                break;            case SNMP_VAR_ENDOFMIBVIEW:                str = "SNMP_VAR_ENDOFMIBVIEW";                break;            case GET_REQ_MSG:                str = "GET_REQ_MSG";                break;            case GETNEXT_REQ_MSG:                str = "GETNEXT_REQ_MSG";                break;            case SET_REQ_MSG:                str = "SET_REQ_MSG";                break;            case GETBULK_REQ_MSG:                str = "GETBULK_REQ_MSG";                break;            case INFORM_REQ_MSG:                str = "INFORM_REQ_MSG";                break;            case GET_RSP_MSG:                str = "GET_RSP_MSG";                break;            case GET_RPRT_MSG:                str = "GET_RPRT_MSG";                break;            case TRP_REQ_MSG :                str = "TRP_REQ_MSG";                break;            case TRPV2_REQ_MSG:                str = "TRPV2_REQ_MSG";                break;            default:                str = "0x" + SnmpUtilities.toHex(type);        }        return str;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -