org.nhindirect.config.store.util
Class DNSRecordUtils

java.lang.Object
  extended by org.nhindirect.config.store.util.DNSRecordUtils

public class DNSRecordUtils
extends Object

Utility class for creating and serializing DNS records.

Since:
1.1
Author:
Greg Meyer

Constructor Summary
DNSRecordUtils()
           
 
Method Summary
static DNSRecord createARecord(String name, long ttl, String ip)
          Creates a DNS A type record.
static DNSRecord createMXRecord(String name, String target, long ttl, int priority)
          Creates a DNS MX record.
static DNSRecord createSOARecord(String name, long ttl, String nameServer, String hostMaster, int serial, long refresh, long retry, long expire, long minumum)
          Create a DNS SOA record.
static DNSRecord createSRVRecord(String name, String target, long ttl, int port, int priority, int weight)
          Create a DNS SRV type record.
static DNSRecord createX509CERTRecord(String address, long ttl, X509Certificate cert)
          Creates a DNS CERT record containing an X509 public certificate.
static DNSRecord fromWire(byte[] data)
          Converts a raw wire transfer format of a record to a DNS record.
static byte[] toWire(DNSRecord rec)
          Converts a DNS record to a raw wire transfer format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DNSRecordUtils

public DNSRecordUtils()
Method Detail

createARecord

public static DNSRecord createARecord(String name,
                                      long ttl,
                                      String ip)
                               throws ConfigurationStoreException
Creates a DNS A type record.

Parameters:
name - The record name. Generally a fully qualified domain name such as host.example.com.
ttl - The time to live in seconds.
ip - The ip4 address that the name will resolve.
Returns:
A DNSRecord representing an A type record.
Throws:
ConfigurationStoreException

createSRVRecord

public static DNSRecord createSRVRecord(String name,
                                        String target,
                                        long ttl,
                                        int port,
                                        int priority,
                                        int weight)
                                 throws ConfigurationStoreException
Create a DNS SRV type record.

Parameters:
name - The service name.
target - The target name that is hosting the service.
ttl - The time to live in seconds.
port - The port that the service is offered on.
priority - The priority of the service. Lower priorities are preferred.
weight - A value used to select between services with the same priority.
Returns:
A DNSRecord representing an SRV type record.
Throws:
ConfigurationStoreException

createX509CERTRecord

public static DNSRecord createX509CERTRecord(String address,
                                             long ttl,
                                             X509Certificate cert)
                                      throws ConfigurationStoreException
Creates a DNS CERT record containing an X509 public certificate.

Parameters:
address - The name or address corresponding to the certificate.
ttl - The time to live in seconds.
cert - The X509 public certificate to be stored with the name/address.
Returns:
A DNSRecord representing a CERT type record.
Throws:
ConfigurationStoreException

createMXRecord

public static DNSRecord createMXRecord(String name,
                                       String target,
                                       long ttl,
                                       int priority)
                                throws ConfigurationStoreException
Creates a DNS MX record.

Parameters:
name - The email domain or host used to determine where email should be sent to.
target - The host server that email should be sent to.
ttl - The time to live in seconds.
priority - The priority of the target host. Lower priorities are preferred.
Returns:
A DNSRecord representing an MX type record.
Throws:
ConfigurationStoreException

createSOARecord

public static DNSRecord createSOARecord(String name,
                                        long ttl,
                                        String nameServer,
                                        String hostMaster,
                                        int serial,
                                        long refresh,
                                        long retry,
                                        long expire,
                                        long minumum)
Create a DNS SOA record.

Parameters:
name - The root name of the zone.
ttl - The time to live in seconds.
nameServer - Name of the server that responds authoritatively to this zone.
hostMaster - The email address of the administrator of the zone. The @ symbol is replaced with a "."
serial - The current serial number of record.
refresh - The time in seconds the a slave server tries to refresh its information from the master.
retry - The time in seconds that a slave server retires after a failed refresh.
expire - Time in seconds when the zone data is not longer authoritative.
minumum - See RFC 2308.
Returns:
A DNSRecord representing an SOA record.

toWire

public static byte[] toWire(DNSRecord rec)
                     throws IOException
Converts a DNS record to a raw wire transfer format.

Parameters:
rec - The DNSRecord to convert.
Returns:
A byte array representation of the DNSRecord in raw wire transfer format.
Throws:
IOException

fromWire

public static DNSRecord fromWire(byte[] data)
                          throws IOException
Converts a raw wire transfer format of a record to a DNS record.

Parameters:
data - The raw byte stream of a record in wire transfer format.
Returns:
A DNSRecord converted from the wire format.
Throws:
IOException


Copyright © 2011. All Rights Reserved.