package org.kne.cloud.network.klalb;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Inet6Address;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;

import org.kne.cloud.network.ipv6.IPv6Address;
import org.kne.cloud.network.ipv6.IPv6AddressGroup;

public class VADDRPacket extends KLALBPacket {
	private static final int HEADER_LENGTH=18;
	public IPv6AddressGroup getVaddr() {
		long high=klalbHeader.getLong(1);
		long low=klalbHeader.getLong(9);
		int perf=klalbHeader.get(17)&0xff;
	
		return new IPv6AddressGroup(new IPv6Address(high, low), perf);
	}

	public VADDRPacket(IPv6AddressGroup vaddr) {
		super(VADDR,HEADER_LENGTH);
		klalbHeader.putLong(1, vaddr.getAddress().getHigh());
		klalbHeader.putLong(9, vaddr.getAddress().getLow());
		klalbHeader.put(17,(byte) vaddr.getPrefixLength());
	}

	public VADDRPacket(ByteBuffer bb) {
		super(bb,HEADER_LENGTH);
	}

	@Override
	public String toString() {
		return "VADDR "+getVaddr();
	}

}
