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