01: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
02:
03: package org.xbill.DNS;
04:
05: import java.io.*;
06:
07: /**
08: * Host Information - describes the CPU and OS of a host
09: *
10: * @author Brian Wellington
11: */
12:
13: public class HINFORecord extends Record {
14:
15: private byte[] cpu, os;
16:
17: HINFORecord() {
18: }
19:
20: Record getObject() {
21: return new HINFORecord();
22: }
23:
24: /**
25: * Creates an HINFO Record from the given data
26: * @param cpu A string describing the host's CPU
27: * @param os A string describing the host's OS
28: * @throws IllegalArgumentException One of the strings has invalid escapes
29: */
30: public HINFORecord(Name name, int dclass, long ttl, String cpu,
31: String os) {
32: super (name, Type.HINFO, dclass, ttl);
33: try {
34: this .cpu = byteArrayFromString(cpu);
35: this .os = byteArrayFromString(os);
36: } catch (TextParseException e) {
37: throw new IllegalArgumentException(e.getMessage());
38: }
39: }
40:
41: void rrFromWire(DNSInput in) throws IOException {
42: cpu = in.readCountedString();
43: os = in.readCountedString();
44: }
45:
46: void rdataFromString(Tokenizer st, Name origin) throws IOException {
47: try {
48: cpu = byteArrayFromString(st.getString());
49: os = byteArrayFromString(st.getString());
50: } catch (TextParseException e) {
51: throw st.exception(e.getMessage());
52: }
53: }
54:
55: /**
56: * Returns the host's CPU
57: */
58: public String getCPU() {
59: return byteArrayToString(cpu, false);
60: }
61:
62: /**
63: * Returns the host's OS
64: */
65: public String getOS() {
66: return byteArrayToString(os, false);
67: }
68:
69: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
70: out.writeCountedString(cpu);
71: out.writeCountedString(os);
72: }
73:
74: /**
75: * Converts to a string
76: */
77: String rrToString() {
78: StringBuffer sb = new StringBuffer();
79: sb.append(byteArrayToString(cpu, true));
80: sb.append(" ");
81: sb.append(byteArrayToString(os, true));
82: return sb.toString();
83: }
84:
85: }
|