int transactionID, DatagramPacket packet) throws IOException { DHCPMessage msg = new DHCPMessage(packet); BOOTPHeader hdr = msg.getHeader(); if (hdr.getOpcode() != BOOTPHeader.BOOTREPLY) {  return false;
int transactionID, DatagramPacket packet) throws IOException { DHCPMessage msg = new DHCPMessage(packet); BOOTPHeader hdr = msg.getHeader(); if (hdr.getOpcode() != BOOTPHeader.BOOTREPLY) {  return false; } if (hdr.getTransactionID() != transactionID) {  return false; }   if (log.isDebugEnabled()) { log.debug("Got Client IP address  : " + hdr.getClientIPAddress()); log.debug("Got Your IP address    : " + hdr.getYourIPAddress()); log.debug("Got Server IP address  : " + hdr.getServerIPAddress()); log.debug("Got Gateway IP address : " + hdr.getGatewayIPAddress()); for (int n = 1; n < 255; n++) { byte[] value = msg.getOption(n); if (value != null) { if (value.length == 1) log.debug("Option " + n + " : " + (int) (value[0])); else if (value.length == 2) log.debug("Option " + n + " : " + ((value[0] << 8) | value[1])); else if (value.length == 4) log.debug("Option " + n + " : " + InetAddress.getByAddress(value).toString()); else log.debug("Option " + n + " : " + new String(value));
    protected boolean processResponse(Device device, NetDeviceAPI api,            int transactionID, DatagramPacket packet) throws IOException {        DHCPMessage msg = new DHCPMessage(packet);        BOOTPHeader hdr = msg.getHeader();        if (hdr.getOpcode() != BOOTPHeader.BOOTREPLY) {            // Not a response            return false;        }        if (hdr.getTransactionID() != transactionID) {            // Not for me            return false;        }        // debug the DHCP message        if (log.isDebugEnabled()) {            log.debug("Got Client IP address  : " + hdr.getClientIPAddress());            log.debug("Got Your IP address    : " + hdr.getYourIPAddress());            log.debug("Got Server IP address  : " + hdr.getServerIPAddress());            log.debug("Got Gateway IP address : " + hdr.getGatewayIPAddress());            for (int n = 1; n < 255; n++) {                byte[] value = msg.getOption(n);                if (value != null) {                    if (value.length == 1)                        log.debug("Option " + n + " : " + (int) (value[0]));                    else if (value.length == 2)                        log.debug("Option " + n + " : "                                + ((value[0] << 8) | value[1]));                    else if (value.length == 4)                        log.debug("Option " + n + " : "                                + InetAddress.getByAddress(value).toString());                    else                        log.debug("Option " + n + " : " + new String(value));                }            }        }        switch (msg.getMessageType()) {        case DHCPMessage.DHCPOFFER:            byte[] serverID = msg                    .getOption(DHCPMessage.SERVER_IDENTIFIER_OPTION);            byte[] requestedIP = hdr.getYourIPAddress().getAddress();            hdr = new BOOTPHeader(BOOTPHeader.BOOTREQUEST, transactionID, hdr                    .getClientIPAddress(), hdr.getClientHwAddress());            msg = new DHCPMessage(hdr, DHCPMessage.DHCPREQUEST);            msg.setOption(DHCPMessage.REQUESTED_IP_ADDRESS_OPTION, requestedIP);            msg.setOption(DHCPMessage.SERVER_IDENTIFIER_OPTION, serverID);            packet = msg.toDatagramPacket();            packet.setAddress(IPv4Address.BROADCAST_ADDRESS);            packet.setPort(SERVER_PORT);            socket.send(packet);            break;        case DHCPMessage.DHCPACK:            configureNetwork(device, msg);            return true;        case DHCPMessage.DHCPNAK:            break;        }        return false;    }