summaryrefslogtreecommitdiff
path: root/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2022-01-30 14:10:47 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2023-11-12 23:49:55 +0100
commitebec82011e1f83bd40f5bb94ea72c2552306e940 (patch)
treeb82b2fdd2d2300c067aaa0c76451baadc3cb6907 /src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
parente3f9330af263fba206c5901a5a23a26b9da52142 (diff)
Implement toString in various path attributes
Diffstat (limited to 'src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java')
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
index 14d5367..2146364 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
@@ -1,5 +1,8 @@
package com.lumaserv.bgp.protocol.attribute;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
import lombok.Getter;
import lombok.Setter;
@@ -8,10 +11,16 @@ import lombok.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() {
@@ -22,4 +31,10 @@ public class NextHopAttribute implements PathAttribute {
return address;
}
+ public String toString() {
+ if (ip != null)
+ return ip.getHostAddress();
+ else
+ return address.toString();
+ }
}