1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.dns;
17
18 import io.netty.util.internal.StringUtil;
19
20
21
22
23
24
25
26 public abstract class AbstractDnsOptPseudoRrRecord extends AbstractDnsRecord implements DnsOptPseudoRecord {
27
28 protected AbstractDnsOptPseudoRrRecord(int maxPayloadSize, int extendedRcode, int version) {
29 super(StringUtil.EMPTY_STRING, DnsRecordType.OPT, maxPayloadSize, packIntoLong(extendedRcode, version));
30 }
31
32 protected AbstractDnsOptPseudoRrRecord(int maxPayloadSize) {
33 super(StringUtil.EMPTY_STRING, DnsRecordType.OPT, maxPayloadSize, 0);
34 }
35
36
37 private static long packIntoLong(int val, int val2) {
38
39 return ((val & 0xffL) << 24 | (val2 & 0xff) << 16) & 0xFFFFFFFFL;
40 }
41
42 @Override
43 public int extendedRcode() {
44 return (short) (((int) timeToLive() >> 24) & 0xff);
45 }
46
47 @Override
48 public int version() {
49 return (short) (((int) timeToLive() >> 16) & 0xff);
50 }
51
52 @Override
53 public int flags() {
54 return (short) ((short) timeToLive() & 0xff);
55 }
56
57 @Override
58 public String toString() {
59 return toStringBuilder().toString();
60 }
61
62 final StringBuilder toStringBuilder() {
63 return new StringBuilder(64)
64 .append(StringUtil.simpleClassName(this))
65 .append('(')
66 .append("OPT flags:")
67 .append(flags())
68 .append(" version:")
69 .append(version())
70 .append(" extendedRecode:")
71 .append(extendedRcode())
72 .append(" udp:")
73 .append(dnsClass())
74 .append(')');
75 }
76 }