package org.kne.cloud.network.klalb;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.net.Inet6Address;

public class VADDRPacket extends KLALBPacket {
	private Inet6Address vaddr;
	public Inet6Address getVaddr() {
		return vaddr;
	}

	public VADDRPacket(Inet6Address vaddr) {
		super(VADDR);
		this.vaddr=vaddr;
	}

	public VADDRPacket() {
		super(VADDR);
	}

	@Override
	public String toString() {
		return "VADDR "+vaddr.getHostAddress();
	}

	@Override
	public long getLength() {
		return super.getLength()+16;
	}

	@Override
	protected void writeToStream(DataOutput dto) throws IOException {
		super.writeToStream(dto);
		dto.write(vaddr.getAddress());
	}

	@Override
	protected void readFromStream(DataInput din) throws IOException {
		super.readFromStream(din);
		byte[]b=new byte[16];
		din.readFully(b);
		vaddr=(Inet6Address) Inet6Address.getByAddress(b);
	}
}
