1// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2
3package org.xbill.DNS;
4
5import 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
16public class SRVRecord extends Record {
17
18private static final long serialVersionUID = -3886460132387522052L;
19
20private int priority, weight, port;
21private Name target;
22
23SRVRecord() {}
24
25Record
26getObject() {
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 */
39public
40SRVRecord(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
50void
51rrFromWire(DNSInput in) throws IOException {
52	priority = in.readU16();
53	weight = in.readU16();
54	port = in.readU16();
55	target = new Name(in);
56}
57
58void
59rdataFromString(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 */
67String
68rrToString() {
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 */
78public int
79getPriority() {
80	return priority;
81}
82
83/** Returns the weight */
84public int
85getWeight() {
86	return weight;
87}
88
89/** Returns the port that the service runs on */
90public int
91getPort() {
92	return port;
93}
94
95/** Returns the host running that the service */
96public Name
97getTarget() {
98	return target;
99}
100
101void
102rrToWire(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
109public Name
110getAdditionalName() {
111	return target;
112}
113
114}
115