001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *       http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *
019 */
020
021package org.apache.directory.server.dhcp.options;
022
023
024import java.net.InetAddress;
025import java.net.UnknownHostException;
026
027import org.apache.directory.server.i18n.I18n;
028
029
030/**
031 * The Dynamic Host Configuration Protocol (DHCP) provides a framework
032 * for passing configuration information to hosts on a TCP/IP network.  
033 * Configuration parameters and other control information are carried in
034 * tagged data items that are stored in the 'options' field of the DHCP
035 * message.  The data items themselves are also called "options."
036 *
037 * This abstract base class is for options that carry a single IP address.
038 *
039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
040 */
041public abstract class AddressOption extends DhcpOption
042{
043    private InetAddress address;
044
045
046    /*
047     * @see org.apache.directory.server.dhcp.options.DhcpOption#getData()
048     */
049    @Override
050    public byte[] getData()
051    {
052        return address.getAddress();
053    }
054
055
056    /*
057     * @see org.apache.directory.server.dhcp.options.DhcpOption#setData(byte[])
058     */
059    @Override
060    public void setData( byte[] data )
061    {
062        try
063        {
064            address = InetAddress.getByAddress( data );
065        }
066        catch ( UnknownHostException e )
067        {
068            throw new IllegalArgumentException( I18n.err( I18n.ERR_638 ), e );
069        }
070    }
071
072
073    public InetAddress getAddress()
074    {
075        return address;
076    }
077
078
079    public void setAddress( InetAddress address )
080    {
081        this.address = address;
082    }
083}