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 024/** 025 * The Dynamic Host Configuration Protocol (DHCP) provides a framework for 026 * passing configuration information to hosts on a TCP/IP network. Configuration 027 * parameters and other control information are carried in tagged data items 028 * that are stored in the 'options' field of the DHCP message. The data items 029 * themselves are also called "options." 030 * 031 * This abstract base class is for options that carry an unsigned short value 032 * (16 bit). 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 */ 036public abstract class ShortOption extends DhcpOption 037{ 038 /** 039 * The short value (represented as an int because of the unsignedness). 040 */ 041 private int shortValue; 042 043 044 /* 045 * @see org.apache.directory.server.dhcp.options.DhcpOption#setData(byte[]) 046 */ 047 @Override 048 public void setData( byte[] data ) 049 { 050 shortValue = ( data[0] & 0xff ) << 8 | ( data[1] & 0xff ); 051 } 052 053 054 /* 055 * @see org.apache.directory.server.dhcp.options.DhcpOption#getData() 056 */ 057 @Override 058 public byte[] getData() 059 { 060 return new byte[] 061 { ( byte ) ( shortValue >> 8 & 0xff ), 062 ( byte ) ( shortValue & 0xff ) }; 063 } 064 065 066 public int getShortValue() 067 { 068 return shortValue; 069 } 070 071 072 public void setShortValue( int shortValue ) 073 { 074 this.shortValue = shortValue; 075 } 076}