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    
021    package org.apache.directory.server.dhcp.options;
022    
023    
024    import java.net.InetAddress;
025    import java.net.UnknownHostException;
026    
027    import 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     * @version $Rev: 902331 $, $Date: 2010-01-23 02:41:35 +0100 (Sat, 23 Jan 2010) $
041     */
042    public abstract class AddressOption extends DhcpOption
043    {
044        private InetAddress address;
045    
046    
047        /*
048         * @see org.apache.directory.server.dhcp.options.DhcpOption#getData()
049         */
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        public void setData( byte[] data )
060        {
061            try
062            {
063                address = InetAddress.getByAddress( data );
064            }
065            catch ( UnknownHostException e )
066            {
067                throw new IllegalArgumentException( I18n.err( I18n.ERR_638 ), e );
068            }
069        }
070    
071    
072        public InetAddress getAddress()
073        {
074            return address;
075        }
076    
077    
078        public void setAddress( InetAddress address )
079        {
080            this.address = address;
081        }
082    }