package com.lumaserv.bgp.protocol.attribute; import java.net.InetAddress; import java.net.UnknownHostException; import lombok.Getter; import lombok.Setter; import java.nio.ByteBuffer; @Getter @Setter public class NextHopAttribute implements PathAttribute { byte[] address; InetAddress ip; public NextHopAttribute(byte typeCode, byte[] data) { this.address = new byte[data.length]; System.arraycopy(data, 0, address, 0, address.length); try { ip = InetAddress.getByAddress(address); } catch (UnknownHostException ex) { // Ignore } } public byte getTypeCode() { return 3; } public void build(ByteBuffer b) { b.put(address); } public String toString() { if (ip != null) return ip.getHostAddress(); else return address.toString(); } }