亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? dhcpoption.java

?? DHCP 的JAVA實(shí)現(xiàn)
?? JAVA
?? 第 1 頁 / 共 4 頁
字號:
/*
 *	This file is part of dhcp4java, a DHCP API for the Java language.
 *	(c) 2006 Stephan Hadinger
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU Lesser General Public
 *	License along with this library; if not, write to the Free Software
 *	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.dhcp4java;

import static org.dhcp4java.DHCPConstants.*;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Class for manipulating DHCP options (used internally).
 * 
 * @author Stephan Hadinger
 * @version 1.00
 * 
 * Immutable object.
 */
public class DHCPOption implements Serializable {
	private static final long   serialVersionUID = 2L;
    private static final Logger logger = Logger.getLogger(DHCPOption.class.getName().toLowerCase());

    /**
     * The code of the option. 0 is reserved for padding, -1 for end of options.
     */
    private final byte code;
    
    /**
     * Raw bytes value of the option. Some methods are provided for higher
     * level of data structures, depending on the <tt>code</tt>.
     */
    private final byte[] value;
    
    /**
     * Used to mark an option as having a mirroring behaviour. This means that
     * this option if used by a server will first mirror the option the client sent
     * then provide a default value if this option was not present in the request.
     * 
     * <p>This is only meant to be used by servers through the <tt>getMirrorValue</tt>
     * method.
     */
    private final boolean mirror;
    
    /**
     * Constructor for <tt>DHCPOption</tt>.
     * 
     * <p>Note: you must not prefix the value by a length-byte. The length prefix
     * will be added automatically by the API.
     * 
     * <p>If value is <tt>null</tt> it is considered as an empty option.
     * If you add an empty option to a DHCPPacket, it removes the option from the packet.
     * 
     * <p>This constructor adds a parameter to mark the option as "mirror". See comments above.
     * 
     * @param code DHCP option code
     * @param value DHCP option value as a byte array.
     */
    public DHCPOption(byte code, byte[] value, boolean mirror) {
    	if (code == DHO_PAD) {
    		throw new IllegalArgumentException("code=0 is not allowed (reserved for padding");
        }
        if (code == DHO_END) {
    		throw new IllegalArgumentException("code=-1 is not allowed (reserved for End Of Options)");
        }

        this.code  = code;
        this.value = (value != null) ? value.clone() : null;
        this.mirror = mirror;
    }

    /**
     * Constructor for <tt>DHCPOption</tt>. This is the default constructor.
     * 
     * <p>Note: you must not prefix the value by a length-byte. The length prefix
     * will be added automatically by the API.
     * 
     * <p>If value is <tt>null</tt> it is considered as an empty option.
     * If you add an empty option to a DHCPPacket, it removes the option from the packet.
     * 
     * @param code DHCP option code
     * @param value DHCP option value as a byte array.
     */
    public DHCPOption(byte code, byte[] value) {
    	this(code, value, false);
    }
    
    /**
     * Return the <tt>code</tt> field (byte).
     * 
     * @return code field
     */
    public byte getCode() {
        return this.code;
    }

    /**
     * returns true if two <tt>DHCPOption</tt> objects are equal, i.e. have same <tt>code</tt>
     * and same <tt>value</tt>.
     */
    @Override
    public boolean equals(Object o) {
    	if (o == this) {
            return true;
        }
        if (!(o instanceof DHCPOption)) {
            return false;
        }
        DHCPOption opt = (DHCPOption) o;
        return ((opt.code == this.code) &&
        		 (opt.mirror == this.mirror) &&
        		 Arrays.equals(opt.value, this.value));
    	
    }

    /**
     * Returns hashcode.
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return this.code ^ Arrays.hashCode(this.value) ^
			    (this.mirror ? 0x80000000 : 0);
	}

	/**
     * 
     * @return option value, can be null.
     */
    public byte[] getValue() {
        return ((this.value == null) ? null : this.value.clone());
    }

    /**
     * 
     * @return option value, never <tt>null</tt>. Minimal value is <tt>byte[0]</tt>.
     */
    public byte[] getValueFast() {
        return this.value;
    }

    /**
     * Returns whether the option is marked as "mirror", meaning it should mirror
     * the option value in the client request.
     * 
     * <p>To be used only in servers.
     * 
     * @return is the option marked is mirror?
     */
    public boolean isMirror() {
    	return this.mirror;
    }

    public static final boolean isOptionAsByte(byte code) {
    	return OptionFormat.BYTE.equals(_DHO_FORMATS.get(code));
    }
    
    /**
     * Creates a DHCP Option as Byte format.
     * 
     * <p>This method is only allowed for the following option codes:
     * <pre>
	 * DHO_IP_FORWARDING(19)
	 * DHO_NON_LOCAL_SOURCE_ROUTING(20)
	 * DHO_DEFAULT_IP_TTL(23)
	 * DHO_ALL_SUBNETS_LOCAL(27)
	 * DHO_PERFORM_MASK_DISCOVERY(29)
	 * DHO_MASK_SUPPLIER(30)
	 * DHO_ROUTER_DISCOVERY(31)
	 * DHO_TRAILER_ENCAPSULATION(34)
	 * DHO_IEEE802_3_ENCAPSULATION(36)
	 * DHO_DEFAULT_TCP_TTL(37)
	 * DHO_TCP_KEEPALIVE_GARBAGE(39)
	 * DHO_NETBIOS_NODE_TYPE(46)
	 * DHO_DHCP_OPTION_OVERLOAD(52)
	 * DHO_DHCP_MESSAGE_TYPE(53)
	 * DHO_AUTO_CONFIGURE(116)
     * </pre>
     * 
     * @param code the option code.
     * @param val the value
     * @throws IllegalArgumentException the option code is not in the list above.
     */
    public static DHCPOption newOptionAsByte(byte code, byte val) {
    	if (!isOptionAsByte(code)) {
            throw new IllegalArgumentException("DHCP option type (" + code + ") is not byte");
        }
        return new DHCPOption(code, byte2Bytes(val));
    }

    /**
     * Returns a DHCP Option as Byte format.
     * 
     * This method is only allowed for the following option codes:
     * <pre>
	 * DHO_IP_FORWARDING(19)
	 * DHO_NON_LOCAL_SOURCE_ROUTING(20)
	 * DHO_DEFAULT_IP_TTL(23)
	 * DHO_ALL_SUBNETS_LOCAL(27)
	 * DHO_PERFORM_MASK_DISCOVERY(29)
	 * DHO_MASK_SUPPLIER(30)
	 * DHO_ROUTER_DISCOVERY(31)
	 * DHO_TRAILER_ENCAPSULATION(34)
	 * DHO_IEEE802_3_ENCAPSULATION(36)
	 * DHO_DEFAULT_TCP_TTL(37)
	 * DHO_TCP_KEEPALIVE_GARBAGE(39)
	 * DHO_NETBIOS_NODE_TYPE(46)
	 * DHO_DHCP_OPTION_OVERLOAD(52)
	 * DHO_DHCP_MESSAGE_TYPE(53)
	 * DHO_AUTO_CONFIGURE(116)
     * </pre>
     * 
     * @return the option value, <tt>null</tt> if option is not present.
     * @throws IllegalArgumentException the option code is not in the list above.
     * @throws DHCPBadPacketException the option value in packet is of wrong size.
     */
    public byte getValueAsByte() throws IllegalArgumentException {
        if (!isOptionAsByte(code)) {
            throw new IllegalArgumentException("DHCP option type (" + this.code + ") is not byte");
        }
        if (this.value == null) {
        	throw new IllegalStateException("value is null");
        }
        if (this.value.length != 1) {
        	throw new DHCPBadPacketException("option " + this.code + " is wrong size:" + this.value.length + " should be 1");
        }
        return this.value[0];
    }

    public static final boolean isOptionAsShort(byte code) {
    	return OptionFormat.SHORT.equals(_DHO_FORMATS.get(code));
    }
    /**
     * Returns a DHCP Option as Short format.
     * 
     * <p>This method is only allowed for the following option codes:
     * <pre>
	 * DHO_BOOT_SIZE(13)
	 * DHO_MAX_DGRAM_REASSEMBLY(22)
	 * DHO_INTERFACE_MTU(26)
	 * DHO_DHCP_MAX_MESSAGE_SIZE(57)
     * </pre>
     * 
     * @return the option value, <tt>null</tt> if option is not present.
     * @throws IllegalArgumentException the option code is not in the list above.
     * @throws DHCPBadPacketException the option value in packet is of wrong size.
     */
    public short getValueAsShort() throws IllegalArgumentException {
    	if (!isOptionAsShort(code)) {
            throw new IllegalArgumentException("DHCP option type (" + this.code + ") is not short");
        }
        if (this.value == null) {
        	throw new IllegalStateException("value is null");
        }
        if (this.value.length != 2) {
        	throw new DHCPBadPacketException("option " + this.code + " is wrong size:" + this.value.length + " should be 2");
        }

        return (short) ((this.value[0] & 0xff) << 8 | (this.value[1] & 0xFF));
    }

    public static final boolean isOptionAsInt(byte code) {
    	return OptionFormat.INT.equals(_DHO_FORMATS.get(code));
    }
    /**
     * Returns a DHCP Option as Integer format.
     * 
     * <p>This method is only allowed for the following option codes:
     * <pre>
	 * DHO_TIME_OFFSET(2)
	 * DHO_PATH_MTU_AGING_TIMEOUT(24)
	 * DHO_ARP_CACHE_TIMEOUT(35)
	 * DHO_TCP_KEEPALIVE_INTERVAL(38)
	 * DHO_DHCP_LEASE_TIME(51)
	 * DHO_DHCP_RENEWAL_TIME(58)
	 * DHO_DHCP_REBINDING_TIME(59)
     * </pre>
     * 
     * @return the option value, <tt>null</tt> if option is not present.
     * @throws IllegalArgumentException the option code is not in the list above.
     * @throws DHCPBadPacketException the option value in packet is of wrong size.
     */
    public int getValueAsInt() throws IllegalArgumentException {
    	if (!isOptionAsInt(code)) {
            throw new IllegalArgumentException("DHCP option type (" + this.code + ") is not int");
        }
        if (this.value == null) {
        	throw new IllegalStateException("value is null");
        }
        if (this.value.length != 4) {
        	throw new DHCPBadPacketException("option " + this.code + " is wrong size:" + this.value.length + " should be 4");
        }
        return ((this.value[0] & 0xFF) << 24 |
                (this.value[1] & 0xFF) << 16 |
                (this.value[2] & 0xFF) <<  8 |
                (this.value[3] & 0xFF));
    }

    // TODO
    /**
     * Returns a DHCP Option as Integer format, but is usable for any numerical type: int, short or byte.
     * 
     * <p>There is no check on the option
     * 
     * @return the option value <tt>null</tt> if option is not present, or wrong number of bytes.
     */
    public Integer getValueAsNum() throws IllegalArgumentException {
    	if (value == null) {
    		return null;
    	}
    	if (value.length == 1) {			// byte
            return value[0] & 0xFF;
    	} else if (value.length == 2) {		// short
            return ((value[0] & 0xff) << 8 | (value[1] & 0xFF));
    	} else if (value.length == 4) {
            return ((this.value[0] & 0xFF) << 24 |
                    (this.value[1] & 0xFF) << 16 |
                    (this.value[2] & 0xFF) <<  8 |
                    (this.value[3] & 0xFF));
    	} else {
    		return null;
    	}
    }
    

    public static final boolean isOptionAsInetAddr(byte code) {
    	return OptionFormat.INET.equals(_DHO_FORMATS.get(code));
    }
    /**
     * Returns a DHCP Option as InetAddress format.
     * 
     * <p>This method is only allowed for the following option codes:
     * <pre>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品乱码一区二区三区软件 | 日韩欧美电影在线| 国产精品综合一区二区三区| 亚洲天堂中文字幕| 久久一区二区视频| 91麻豆精品国产91久久久资源速度| 国产露脸91国语对白| 日韩av网站免费在线| 亚洲人成网站精品片在线观看| 日韩精品在线一区| 777色狠狠一区二区三区| 91在线视频播放地址| 韩国v欧美v亚洲v日本v| 三级久久三级久久久| 一区二区三区不卡在线观看| 国产午夜精品福利| 日韩免费视频一区| 欧美一区二区黄色| 欧美乱妇一区二区三区不卡视频| 91污片在线观看| 高清shemale亚洲人妖| 国产在线视频不卡二| 日韩av在线播放中文字幕| 亚洲va欧美va国产va天堂影院| 欧美激情在线观看视频免费| 久久人人爽人人爽| 精品久久一区二区三区| 日韩午夜激情av| 日韩久久久精品| 欧美日韩精品福利| 欧美精品777| 欧美日韩国产大片| 欧美剧情电影在线观看完整版免费励志电影| av电影一区二区| 97国产一区二区| 99re8在线精品视频免费播放| 国产电影一区二区三区| 国产成人免费视频网站| 国产一区二区导航在线播放| 国产麻豆精品在线| 国产成人三级在线观看| 成人精品一区二区三区四区 | 色悠悠亚洲一区二区| bt欧美亚洲午夜电影天堂| 国产馆精品极品| 成人激情开心网| 99国产精品久| 欧美特级限制片免费在线观看| 色婷婷激情综合| 欧美日韩国产天堂| 欧美一区二区三区婷婷月色| 日韩欧美一区二区久久婷婷| 欧美mv日韩mv| 中文久久乱码一区二区| 亚洲天堂2016| 亚洲国产精品欧美一二99| 亚洲v日本v欧美v久久精品| 日韩高清一级片| 国产精品99久久久| 成人99免费视频| 欧美三区在线视频| 51精品视频一区二区三区| 欧美zozozo| 亚洲国产精品t66y| 亚洲一区在线视频| 午夜电影一区二区| 国产精品一区在线| 色婷婷精品久久二区二区蜜臂av | 欧美一级搡bbbb搡bbbb| 久久久精品黄色| 亚洲精品免费视频| 麻豆91精品91久久久的内涵| 国产成人无遮挡在线视频| 色综合久久中文综合久久牛| 欧美日韩1234| 久久精品亚洲一区二区三区浴池| 中文字幕永久在线不卡| 日韩中文字幕不卡| 国产91精品一区二区麻豆网站| 色婷婷综合久色| 日韩免费观看2025年上映的电影| 国产午夜精品久久久久久免费视| 一级特黄大欧美久久久| 激情六月婷婷综合| 欧美系列亚洲系列| 久久久青草青青国产亚洲免观| 亚洲视频免费看| 麻豆精品蜜桃视频网站| 91香蕉视频mp4| 欧美大片拔萝卜| 亚洲激情欧美激情| 国产夫妻精品视频| 7777精品久久久大香线蕉| 国产亚洲一区二区三区| 亚洲一区二区av在线| 高清日韩电视剧大全免费| 欧美日韩国产一区二区三区地区| 国产精品色眯眯| 久久精品国产在热久久| 91婷婷韩国欧美一区二区| 日韩女优视频免费观看| 亚洲国产毛片aaaaa无费看| 成人国产精品视频| 精品国产免费久久| 亚洲成人手机在线| 色综合天天天天做夜夜夜夜做| 欧美成人一区二区三区| 亚洲一区二区三区在线| 9色porny自拍视频一区二区| 欧美电影免费观看高清完整版在 | 在线影视一区二区三区| 国产日韩一级二级三级| 久久精品国产亚洲a| 欧美三级韩国三级日本三斤| 亚洲三级在线免费| 大胆亚洲人体视频| 日韩免费一区二区| 三级影片在线观看欧美日韩一区二区 | 99国产精品久久久久| 国产日本亚洲高清| 国产在线精品一区二区| 欧美一级片在线观看| 日韩福利电影在线观看| 欧美挠脚心视频网站| 亚洲成a人v欧美综合天堂| 91麻豆国产精品久久| 国产精品色在线观看| 国产.欧美.日韩| 国产精品视频yy9299一区| 国产91丝袜在线播放九色| 亚洲国产精品精华液2区45| 国产iv一区二区三区| 欧美韩日一区二区三区四区| 国产成人av一区二区三区在线| 久久先锋资源网| 国产精品亚洲午夜一区二区三区| 精品久久人人做人人爽| 国产在线视频一区二区| 国产日韩欧美在线一区| 国产麻豆精品95视频| 久久一区二区三区四区| 福利一区二区在线观看| 欧美国产国产综合| 99久久久国产精品| 国产精品久久久久aaaa| 91免费版在线看| 亚洲影视在线播放| 欧美精选午夜久久久乱码6080| 亚洲123区在线观看| 欧美一卡二卡在线观看| 国内精品久久久久影院色| xf在线a精品一区二区视频网站| 国内精品伊人久久久久影院对白| 国产三级一区二区| kk眼镜猥琐国模调教系列一区二区 | 一区二区高清视频在线观看| 欧美性色综合网| 日日摸夜夜添夜夜添亚洲女人| 日韩欧美中文字幕精品| 国产精品影视在线| 亚洲三级电影网站| 欧美日韩成人一区二区| 精品亚洲免费视频| 国产精品久久久久精k8 | 69久久夜色精品国产69蝌蚪网| 免费av成人在线| 国产欧美日韩亚州综合 | 午夜久久久久久久久| 日韩免费性生活视频播放| 丁香六月综合激情| 一区二区欧美视频| 亚洲精品一区二区三区蜜桃下载 | 风间由美一区二区av101| 一区二区三区91| 久久综合狠狠综合久久综合88 | 国产麻豆午夜三级精品| 亚洲日本在线a| 日韩一区二区三| 91亚洲永久精品| 久久精品国产在热久久| 亚洲视频在线观看一区| 欧美va亚洲va国产综合| 色综合色狠狠天天综合色| 麻豆91精品91久久久的内涵| 中文字幕一区二区三区在线观看 | 精品福利av导航| 日本高清免费不卡视频| 麻豆精品一区二区三区| 亚洲欧洲综合另类| 欧美精品一区二区三| 欧美性受极品xxxx喷水| 国产91丝袜在线播放| 免费一级片91| 夜色激情一区二区| 欧美激情在线一区二区| 日韩一级在线观看| 欧美性色aⅴ视频一区日韩精品| 国产成人综合网| 免费在线观看成人| 亚洲线精品一区二区三区|