-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathAAAARecord.java
More file actions
92 lines (81 loc) · 2.48 KB
/
Copy pathAAAARecord.java
File metadata and controls
92 lines (81 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
package org.xbill.DNS;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* IPv6 Address Record - maps a domain name to an IPv6 address
*
* @author Brian Wellington
* @see <a href="https://datatracker.ietf.org/doc/html/rfc3596">RFC 3596: DNS Extensions to Support
* IP Version 6</a>
*/
public class AAAARecord extends Record {
private byte[] address;
AAAARecord() {}
/**
* Creates an AAAA record from the given address.
*
* @param address The address that the name refers to.
*/
public AAAARecord(Name name, int dclass, long ttl, InetAddress address) {
super(name, Type.AAAA, dclass, ttl);
if (Address.familyOf(address) != Address.IPv4 && Address.familyOf(address) != Address.IPv6) {
throw new IllegalArgumentException("invalid IPv4/IPv6 address");
}
this.address = address.getAddress();
}
/**
* Creates an AAAA record from the given data.
*
* @param address The address that the name refers to
* @since 3.6
*/
public AAAARecord(Name name, int dclass, long ttl, byte[] address) {
super(name, Type.AAAA, dclass, ttl);
if (address == null || address.length != 16) {
throw new IllegalArgumentException("invalid IPv6 address");
}
this.address = address;
}
@Override
protected void rrFromWire(DNSInput in) throws IOException {
address = in.readByteArray(16);
}
@Override
protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
address = st.getAddressBytes(Address.IPv6);
}
/** Converts rdata to a String */
@Override
protected String rrToString() {
InetAddress addr;
try {
addr = InetAddress.getByAddress(null, address);
} catch (UnknownHostException e) {
return null;
}
if (addr.getAddress().length == 4) {
// Deal with Java's broken handling of mapped IPv4 addresses.
return "::ffff:" + addr.getHostAddress();
}
return addr.getHostAddress();
}
/** Returns the address */
public InetAddress getAddress() {
try {
if (name == null) {
return InetAddress.getByAddress(address);
} else {
return InetAddress.getByAddress(name.toString(), address);
}
} catch (UnknownHostException e) {
return null;
}
}
@Override
protected void rrToWire(DNSOutput out, Compression c, boolean canonical) {
out.writeByteArray(address);
}
}