/*
 * @(#)MailExchanger.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */

/**
 * MailExchanger record stores information about how to route messages
 * for a specified domain name.
 */
package com.jscape.inet.dns.record;


import com.jscape.inet.dns.DnsInputStream;

import java.io.IOException;


/**
 * MailExchanger record represents a host responsible for sending email
 */
public class MailExchanger
        extends DnsRecord {
    private int preference;
    private String mx;

    protected void decode(DnsInputStream inputStream)
            throws IOException {
        preference = inputStream.readShort();
        mx = inputStream.readDomainName();
    }

    /**
     * Gets domain name willing to act as mail exchange.
     *
     * @return mail exchange
     */
    public String getMX() {
        return mx;
    }

    /**
     * Gets preference given to this record.
     * Lower values are preferred.
     *
     * @return preference
     */
    public int getPreference() {
        return preference;
    }

    /**
     * Gets String representation of this record.
     *
     * @return String
     */
    public String toString() {
        return getRecordName() + "\tpreference = " + preference + ", mail exchanger = " + mx;
    }
}

