001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with this
004 * work for additional information regarding copyright ownership. The ASF
005 * licenses this file to you under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations under
015 * the License.
016 *
017 */
018
019 package org.apache.directory.server.dhcp.options;
020
021 /**
022 * The Dynamic Host Configuration Protocol (DHCP) provides a framework for
023 * passing configuration information to hosts on a TCP/IP network. Configuration
024 * parameters and other control information are carried in tagged data items
025 * that are stored in the 'options' field of the DHCP message. The data items
026 * themselves are also called "options."
027 *
028 * This abstract base class is for options that carry a short value (16 bit).
029 *
030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
031 * @version $Rev: 551805 $, $Date: 2007-06-29 00:57:04 -0500 (Fr, 29 Jun 2007) $
032 */
033 public abstract class IntOption extends DhcpOption {
034 /**
035 * The int value (represented as a long because of the unsignedness).
036 */
037 private long intValue;
038
039 /*
040 * @see org.apache.directory.server.dhcp.options.DhcpOption#setData(byte[])
041 */
042 public void setData(byte[] data) {
043 intValue = (data[0] & 0xff) << 24 | (data[1] & 0xff) << 16
044 | (data[2] & 0xff) << 8 | (data[3] & 0xff);
045 }
046
047 /*
048 * @see org.apache.directory.server.dhcp.options.DhcpOption#getData()
049 */
050 public byte[] getData() {
051 return new byte[]{(byte) (intValue >> 24 & 0xff),
052 (byte) (intValue >> 16 & 0xff), (byte) (intValue >> 8 & 0xff),
053 (byte) (intValue & 0xff)};
054 }
055
056 public long getIntValue() {
057 return intValue;
058 }
059
060 public void setIntValue(long intValue) {
061 this.intValue = intValue;
062 }
063 }