001: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS;
004:
005: import java.io.*;
006:
007: /**
008: * Server Selection Record - finds hosts running services in a domain. An
009: * SRV record will normally be named <service>.<protocol>.domain - an
010: * example would be http.tcp.example.com (if HTTP used SRV records)
011: *
012: * @author Brian Wellington
013: */
014:
015: public class SRVRecord extends Record {
016:
017: private int priority, weight, port;
018: private Name target;
019:
020: SRVRecord() {
021: }
022:
023: Record getObject() {
024: return new SRVRecord();
025: }
026:
027: /**
028: * Creates an SRV Record from the given data
029: * @param priority The priority of this SRV. Records with lower priority
030: * are preferred.
031: * @param weight The weight, used to select between records at the same
032: * priority.
033: * @param port The TCP/UDP port that the service uses
034: * @param target The host running the service
035: */
036: public SRVRecord(Name name, int dclass, long ttl, int priority,
037: int weight, int port, Name target) {
038: super (name, Type.SRV, dclass, ttl);
039: this .priority = checkU16("priority", priority);
040: this .weight = checkU16("weight", weight);
041: this .port = checkU16("port", port);
042: this .target = checkName("target", target);
043: }
044:
045: void rrFromWire(DNSInput in) throws IOException {
046: priority = in.readU16();
047: weight = in.readU16();
048: port = in.readU16();
049: target = new Name(in);
050: }
051:
052: void rdataFromString(Tokenizer st, Name origin) throws IOException {
053: priority = st.getUInt16();
054: weight = st.getUInt16();
055: port = st.getUInt16();
056: target = st.getName(origin);
057: }
058:
059: /** Converts rdata to a String */
060: String rrToString() {
061: StringBuffer sb = new StringBuffer();
062: sb.append(priority + " ");
063: sb.append(weight + " ");
064: sb.append(port + " ");
065: sb.append(target);
066: return sb.toString();
067: }
068:
069: /** Returns the priority */
070: public int getPriority() {
071: return priority;
072: }
073:
074: /** Returns the weight */
075: public int getWeight() {
076: return weight;
077: }
078:
079: /** Returns the port that the service runs on */
080: public int getPort() {
081: return port;
082: }
083:
084: /** Returns the host running that the service */
085: public Name getTarget() {
086: return target;
087: }
088:
089: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
090: out.writeU16(priority);
091: out.writeU16(weight);
092: out.writeU16(port);
093: target.toWire(out, null, canonical);
094: }
095:
096: public Name getAdditionalName() {
097: return target;
098: }
099:
100: }
|