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