Java 类com.sun.jmx.snmp.SnmpPduTrap 实例源码

项目:OpenJSharp    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:OpenJSharp    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:OpenJSharp    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:OpenJSharp    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:jdk8u-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:jdk8u-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:jdk8u-jdk    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:jdk8u-jdk    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:jdk8u_jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:jdk8u_jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:jdk8u_jdk    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:jdk8u_jdk    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:lookaside_java-1.8.0-openjdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:lookaside_java-1.8.0-openjdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:lookaside_java-1.8.0-openjdk    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:lookaside_java-1.8.0-openjdk    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:infobip-open-jdk-8    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:infobip-open-jdk-8    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:infobip-open-jdk-8    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:infobip-open-jdk-8    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:jdk8u-dev-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:jdk8u-dev-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:jdk8u-dev-jdk    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:jdk8u-dev-jdk    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:jdk7-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:jdk7-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:jdk7-jdk    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:jdk7-jdk    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:openjdk-source-code-learn    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:openjdk-source-code-learn    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:openjdk-source-code-learn    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:openjdk-source-code-learn    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:OLD-OpenJDK8    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:OLD-OpenJDK8    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:OLD-OpenJDK8    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:OLD-OpenJDK8    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
项目:openjdk-jdk7u-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available).
 * If no ACL file or no destinations are available, the trap is sent
 * to the local host.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
public void snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic +
              ", specific=" + specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;
    pdu.community = null ;
    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
项目:openjdk-jdk7u-jdk    文件:SnmpAdaptorServer.java   
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified community string (and the ACL file
 * is not used).
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param cs The community string to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
public void snmpV1Trap(InetAddress addr, String cs, int generic,
                       int specific, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;

    pdu.enterprise = enterpriseOid ;
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    pdu.timeStamp = getSysUpTime();

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
    try {
        if (address != null)
            pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
        else pdu.agentAddr =
          handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
    } catch (UnknownHostException e) {
        byte[] zeroedAddr = new byte[4];
        pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
    }

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);
}
项目:openjdk-jdk7u-jdk    文件:SnmpAdaptorServer.java   
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
项目:openjdk-jdk7u-jdk    文件:SnmpRequestHandler.java   
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}