@SuppressWarnings("static-access")
	private void manejarDiscovery() throws UnknownHostException, IOException {

		PaqueteDHCP data = new PaqueteDHCP();
		data.setOP((byte) 0x02);
		data.setHTYPE(pack.getHTYPE());
		data.setHLEN(pack.getHLEN());
		data.setHOPS((byte) 0x00);
		data.setXID(pack.getXID());
		byte[] a = { hexToByte("00"), hexToByte("00") };
		data.setSECS(a);
		data.setFLAGS(pack.getFLAGS());
		byte[] b = { hexToByte("00"), hexToByte("00"), hexToByte("00"),
				hexToByte("00") };
		data.setCIADDR(b);
		String tempId = new String();
		if (database.existeCliente(pack.getStringHexa(pack.getCHADDR())))
			tempId = database.getIPdeMAC(pack.getStringHexa(pack.getCHADDR()));
		else if (pack.existInOption(50).getIntOption() != 0) {

			OpcionDHCP opc = pack.existInOption(50);
			byte[] dir = opc.getValues();
			int[] dirAux = new int[4];
			for (int i = 0; i < 4; i++) {
				if (dir[i] < 0) {
					dir[i] = (byte) (dir[i] & 0x7F);
					dirAux[i] = (int) dir[i];
					dirAux[i] = dirAux[i] | 0x80;
				} else
					dirAux[i] = (int) dir[i];
			}
			tempId = String.format("%d.%d.%d.%d", dirAux[0], dirAux[1],
					dirAux[2], dirAux[3]);

			if (tempId.equals(database.getOwnIp())) {
				sendNak();
				return;
			}

			else if (!database.existeIp(tempId)) {

				database.sacarIP(pack.getStringHexa(pack.getCHADDR()),
						getRequestedIP(pack));

			} else {

				tempId = database.getIPLibre(
						pack.getStringHexa(pack.getCHADDR()),
						IPdesdeByte(pack.getGIADDR()));
			}
		} else {

			tempId = database.getIPLibre(pack.getStringHexa(pack.getCHADDR()),
					IPdesdeByte(pack.getGIADDR()));
		}
		if (tempId == null) {
			// no hay mas direcciones
			System.out.println("No hay mas direcciones");
			return;
		}
		int subred = database.identificarSubRed(tempId);

		if (subred != -1) {

			data.setYIADDR(pack.getIPOfStr(tempId));
			data.setSIADDR(b);
			data.setGIADDR(b);
			data.setCHADDR(pack.getCHADDR());
			data.setMagicCookie(pack.getMagicCookie());

			// Relleno de las opciones del DHCP-OFFER
			byte[] opt1 = new byte[3];
			// ponemos las opciones
			opt1[0] = (hexToByte(Integer.toHexString(53))); // DHCP Message Type
			opt1[1] = (hexToByte(Integer.toHexString(1))); // lenght
			opt1[2] = (hexToByte(Integer.toHexString(PaqueteDHCP.OFFER))); // DHCP-OFFER
			data.addDHCPOPTION(opt1);

			byte[] opt2 = new byte[6];
			opt2[0] = (hexToByte(Integer.toHexString(1))); // Subnet Mask
			opt2[1] = (hexToByte(Integer.toHexString(4))); // lenght
			byte[] aux = new byte[4];
			aux = pack.getIPOfStr(database.getMascara().get(
					database.identificarSubRed(tempId)));// máscara
			opt2[2] = aux[0];
			opt2[3] = aux[1];
			opt2[4] = aux[2];
			opt2[5] = aux[3];
			data.addDHCPOPTION(opt2);

			opt2[0] = (hexToByte(Integer.toHexString(3))); // opción router
			opt2[1] = (hexToByte(Integer.toHexString(4))); // lenght
			aux = pack.getIPOfStr(database.getGateway().get(
					database.identificarSubRed(tempId)));// Gateway
			opt2[2] = aux[0];
			opt2[3] = aux[1];
			opt2[4] = aux[2];
			opt2[5] = aux[3];
			data.addDHCPOPTION(opt2);

			// Primero buscamos si el paquete tiene un requerimiento de lease:

			opt2[0] = (hexToByte(Integer.toHexString(51))); // IP Address Lease
															// Time
			opt2[1] = (hexToByte(Integer.toHexString(4))); // lenght
			byte[] leaseTime = fragmentarInt(database.getLease());
			opt2[2] = leaseTime[0];
			opt2[3] = leaseTime[1];
			opt2[4] = leaseTime[2];
			opt2[5] = leaseTime[3];
			data.addDHCPOPTION(opt2);

			opt2[0] = (hexToByte(Integer.toHexString(6))); // Domain Name server
			opt2[1] = (hexToByte(Integer.toHexString(4))); // lenght
			aux = pack.getIPOfStr(database.getDns().get(
					database.identificarSubRed(tempId)));
			opt2[2] = aux[0];
			opt2[3] = aux[1];
			opt2[4] = aux[2];
			opt2[5] = aux[3];
			data.addDHCPOPTION(opt2);

			String miIp = InetAddress.getLocalHost().getHostAddress();
			byte[] ipServer = pack.getIPOfStr(miIp);
			opt2[0] = (hexToByte(Integer.toHexString(54)));// Server Identifier
			opt2[1] = (hexToByte(Integer.toHexString(4))); // lenght
			opt2[2] = ipServer[0]; // Server DHCP
			opt2[3] = ipServer[1]; // Server DHCP
			opt2[4] = ipServer[2]; // Server DHCP
			opt2[5] = ipServer[3]; // Server DHCP
			data.addDHCPOPTION(opt2);
			data.finalizarDatagrama(); // Finalizamoa el datagrama

			byte[] broadcast = { hexToByte("FF"), hexToByte("FF"),
					hexToByte("FF"), hexToByte("FF") };// Broadcast
			if (!IPdesdeByte(pack.getGIADDR()).equals("0.0.0.0")) {
				broadcast = pack.getGIADDR();

			}

			DatagramPacket ep = new DatagramPacket(data.getData(),
					data.getLengthData(), InetAddress.getByAddress(broadcast),
					68);
			socket.send(ep);
			System.out.println("OFFER " + pack.getStringHexa(pack.getCHADDR())
					+ "IP OFRECIDA: " + tempId);
			DHCPlog.reportar("Se envió DHCP_OFFFER a: ["
					+ pack.getStringHexa(pack.getCHADDR()) + "] con la IP: ["
					+ tempId + "] || FECHA: " + new Date());
		} else
			System.out.println("DESCONOCIDO: " + tempId);
	}