@Override public int hashCode() { return intValue(); }
return BADALG; default: return new DnsResponseCode(responseCode);
private static DnsResponse newResponse(DatagramPacket packet, ByteBuf buf) { final int id = buf.readUnsignedShort(); final int flags = buf.readUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } final DnsResponse response = new DatagramDnsResponse( packet.sender(), packet.recipient(), id, DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf))); response.setRecursionDesired((flags >> 8 & 1) == 1); response.setAuthoritativeAnswer((flags >> 10 & 1) == 1); response.setTruncated((flags >> 9 & 1) == 1); response.setRecursionAvailable((flags >> 7 & 1) == 1); response.setZ(flags >> 4 & 0x7); return response; }
private static DnsResponse newResponse(DatagramPacket packet, ByteBuf buf) { final int id = buf.readUnsignedShort(); final int flags = buf.readUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } final DnsResponse response = new DatagramDnsResponse( packet.sender(), packet.recipient(), id, DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf))); response.setRecursionDesired((flags >> 8 & 1) == 1); response.setAuthoritativeAnswer((flags >> 10 & 1) == 1); response.setTruncated((flags >> 9 & 1) == 1); response.setRecursionAvailable((flags >> 7 & 1) == 1); response.setZ(flags >> 4 & 0x7); return response; }
private static DnsResponse newResponse(DatagramPacket packet, ByteBuf buf) { final int id = buf.readUnsignedShort(); final int flags = buf.readUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } final DnsResponse response = new DatagramDnsResponse( packet.sender(), packet.recipient(), id, DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf))); response.setRecursionDesired((flags >> 8 & 1) == 1); response.setAuthoritativeAnswer((flags >> 10 & 1) == 1); response.setTruncated((flags >> 9 & 1) == 1); response.setRecursionAvailable((flags >> 7 & 1) == 1); response.setZ(flags >> 4 & 0x7); return response; }
return BADALG; default: return new DnsResponseCode(responseCode);
/** * Returns a formatted error message for this {@link DnsResponseCode}. */ @Override public String toString() { String text = this.text; if (text == null) { this.text = text = name + '(' + intValue() + ')'; } return text; } }
private static DnsResponse newResponse(DatagramPacket packet, ByteBuf buf) { final int id = buf.readUnsignedShort(); final int flags = buf.readUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } final DnsResponse response = new DatagramDnsResponse( packet.sender(), packet.recipient(), id, DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf))); response.setRecursionDesired((flags >> 8 & 1) == 1); response.setAuthoritativeAnswer((flags >> 10 & 1) == 1); response.setTruncated((flags >> 9 & 1) == 1); response.setRecursionAvailable((flags >> 7 & 1) == 1); response.setZ(flags >> 4 & 0x7); return response; }
return BADALG; default: return new DnsResponseCode(responseCode);
private static DnsResponse newResponse(DatagramPacket packet, ByteBuf buf) { final int id = buf.readUnsignedShort(); final int flags = buf.readUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } final DnsResponse response = new DatagramDnsResponse( packet.sender(), packet.recipient(), id, DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf))); response.setRecursionDesired((flags >> 8 & 1) == 1); response.setAuthoritativeAnswer((flags >> 10 & 1) == 1); response.setTruncated((flags >> 9 & 1) == 1); response.setRecursionAvailable((flags >> 7 & 1) == 1); response.setZ(flags >> 4 & 0x7); return response; }
return BADALG; default: return new DnsResponseCode(responseCode);
return BADALG; default: return new DnsResponseCode(responseCode);
/** * Returns a formatted error message for this {@link DnsResponseCode}. */ @Override public String toString() { String text = this.text; if (text == null) { this.text = text = name + '(' + intValue() + ')'; } return text; } }
@Override public int hashCode() { return intValue(); }
void handle(DnsResponse msg) { DnsResponseCode code = DnsResponseCode.valueOf(msg.code().intValue()); if (code == DnsResponseCode.NOERROR) { inProgressMap.remove(msg.id()); if (timerID >= 0) { vertx.cancelTimer(timerID); } int count = msg.count(DnsSection.ANSWER); List<T> records = new ArrayList<>(count); for (int idx = 0;idx < count;idx++) { DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx); T record = RecordDecoder.decode(a); if (isRequestedType(a.type(), types)) { records.add(record); } } if (records.size() > 0 && (records.get(0) instanceof MxRecordImpl || records.get(0) instanceof SrvRecordImpl)) { Collections.sort((List) records); } actualCtx.executeFromIO(v -> { fut.tryComplete(records); }); } else { actualCtx.executeFromIO(new DnsException(code), this::fail); } }
/** * Encodes the header that is always 12 bytes long. * * @param response the response header being encoded * @param buf the buffer the encoded data should be written to */ private static void encodeHeader(DnsResponse response, ByteBuf buf) { buf.writeShort(response.id()); int flags = 32768; flags |= (response.opCode().byteValue() & 0xFF) << 11; if (response.isAuthoritativeAnswer()) { flags |= 1 << 10; } if (response.isTruncated()) { flags |= 1 << 9; } if (response.isRecursionDesired()) { flags |= 1 << 8; } if (response.isRecursionAvailable()) { flags |= 1 << 7; } flags |= response.z() << 4; flags |= response.code().intValue(); buf.writeShort(flags); buf.writeShort(response.count(DnsSection.QUESTION)); buf.writeShort(response.count(DnsSection.ANSWER)); buf.writeShort(response.count(DnsSection.AUTHORITY)); buf.writeShort(response.count(DnsSection.ADDITIONAL)); }