1
// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
9
* Address Record - maps a domain name to an Internet address
11
* @author Brian Wellington
14
public class ARecord extends Record {
25
private static final int
26
fromArray(byte [] array) {
27
return (((array[0] & 0xFF) << 24) |
28
((array[1] & 0xFF) << 16) |
29
((array[2] & 0xFF) << 8) |
33
private static final byte []
35
byte [] bytes = new byte[4];
36
bytes[0] = (byte) ((addr >>> 24) & 0xFF);
37
bytes[1] = (byte) ((addr >>> 16) & 0xFF);
38
bytes[2] = (byte) ((addr >>> 8) & 0xFF);
39
bytes[3] = (byte) (addr & 0xFF);
44
* Creates an A Record from the given data
45
* @param address The address that the name refers to
48
ARecord(Name name, int dclass, long ttl, InetAddress address) {
49
super(name, Type.A, dclass, ttl);
50
if (Address.familyOf(address) != Address.IPv4)
51
throw new IllegalArgumentException("invalid IPv4 address");
52
addr = fromArray(address.getAddress());
56
rrFromWire(DNSInput in) throws IOException {
57
addr = fromArray(in.readByteArray(4));
61
rdataFromString(Tokenizer st, Name origin) throws IOException {
62
InetAddress address = st.getAddress(Address.IPv4);
63
addr = fromArray(address.getAddress());
66
/** Converts rdata to a String */
69
return (Address.toDottedQuad(toArray(addr)));
72
/** Returns the Internet address */
76
return InetAddress.getByAddress(toArray(addr));
77
} catch (UnknownHostException e) {
83
rrToWire(DNSOutput out, Compression c, boolean canonical) {
84
out.writeU32(((long)addr) & 0xFFFFFFFFL);