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 * Server Selection Record - finds hosts running services in a domain. An 9 * SRV record will normally be named _<service>._<protocol>.domain 10 * - examples would be _sips._tcp.example.org (for the secure SIP protocol) and 11 * _http._tcp.example.com (if HTTP used SRV records) 12 * 13 * @author Brian Wellington 14 */ 15 16 public class SRVRecord extends Record { 17 18 private static final long serialVersionUID = -3886460132387522052L; 19 20 private int priority, weight, port; 21 private Name target; 22 23 SRVRecord() {} 24 25 Record 26 getObject() { 27 return new SRVRecord(); 28 } 29 30 /** 31 * Creates an SRV Record from the given data 32 * @param priority The priority of this SRV. Records with lower priority 33 * are preferred. 34 * @param weight The weight, used to select between records at the same 35 * priority. 36 * @param port The TCP/UDP port that the service uses 37 * @param target The host running the service 38 */ 39 public 40 SRVRecord(Name name, int dclass, long ttl, int priority, 41 int weight, int port, Name target) 42 { 43 super(name, Type.SRV, dclass, ttl); 44 this.priority = checkU16("priority", priority); 45 this.weight = checkU16("weight", weight); 46 this.port = checkU16("port", port); 47 this.target = checkName("target", target); 48 } 49 50 void 51 rrFromWire(DNSInput in) throws IOException { 52 priority = in.readU16(); 53 weight = in.readU16(); 54 port = in.readU16(); 55 target = new Name(in); 56 } 57 58 void 59 rdataFromString(Tokenizer st, Name origin) throws IOException { 60 priority = st.getUInt16(); 61 weight = st.getUInt16(); 62 port = st.getUInt16(); 63 target = st.getName(origin); 64 } 65 66 /** Converts rdata to a String */ 67 String 68 rrToString() { 69 StringBuffer sb = new StringBuffer(); 70 sb.append(priority + " "); 71 sb.append(weight + " "); 72 sb.append(port + " "); 73 sb.append(target); 74 return sb.toString(); 75 } 76 77 /** Returns the priority */ 78 public int 79 getPriority() { 80 return priority; 81 } 82 83 /** Returns the weight */ 84 public int 85 getWeight() { 86 return weight; 87 } 88 89 /** Returns the port that the service runs on */ 90 public int 91 getPort() { 92 return port; 93 } 94 95 /** Returns the host running that the service */ 96 public Name 97 getTarget() { 98 return target; 99 } 100 101 void 102 rrToWire(DNSOutput out, Compression c, boolean canonical) { 103 out.writeU16(priority); 104 out.writeU16(weight); 105 out.writeU16(port); 106 target.toWire(out, null, canonical); 107 } 108 109 public Name 110 getAdditionalName() { 111 return target; 112 } 113 114 } 115