1 // Copyright (c) 1999-2004 Brian Wellington (bwelling (at) xbill.org) 2 3 package org.xbill.DNS; 4 5 import java.io.*; 6 7 /** 8 * Host Information - describes the CPU and OS of a host 9 * 10 * @author Brian Wellington 11 */ 12 13 public class HINFORecord extends Record { 14 15 private static final long serialVersionUID = -4732870630947452112L; 16 17 private byte [] cpu, os; 18 19 HINFORecord() {} 20 21 Record 22 getObject() { 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 */ 32 public 33 HINFORecord(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 44 void 45 rrFromWire(DNSInput in) throws IOException { 46 cpu = in.readCountedString(); 47 os = in.readCountedString(); 48 } 49 50 void 51 rdataFromString(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 */ 64 public String 65 getCPU() { 66 return byteArrayToString(cpu, false); 67 } 68 69 /** 70 * Returns the host's OS 71 */ 72 public String 73 getOS() { 74 return byteArrayToString(os, false); 75 } 76 77 void 78 rrToWire(DNSOutput out, Compression c, boolean canonical) { 79 out.writeCountedString(cpu); 80 out.writeCountedString(os); 81 } 82 83 /** 84 * Converts to a string 85 */ 86 String 87 rrToString() { 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 } 96