Skip to content

Commit

Permalink
Extract method to IPAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
pzygielo committed Nov 21, 2024
1 parent 3747d7b commit 0c97c1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,8 @@ public void setIPAddress(byte[] newip) {
* @throws IllegalArgumentException
*/
public void setIPAddress(byte[] newip, byte[] mac) {
ip.setAddress(newip, mac);

ip.setAddress(newip);

if (mac != null && ip.getType() != IPAddress.IPV6) {
// Only set mac if we are not IPV6
ip.setMac(mac);
}
dirty = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class IPAddress implements Cloneable, Serializable {
// Address types
private static final int UNKNOWN = 0;
private static final int IPV4 = 1; // IPv4-mapped IPv6
public static final int IPV6 = 2; // IPv6 unicast
private static final int IPV6 = 2; // IPv6 unicast
private static final int IPV4MAC = 3; // iMQ IPV4 + MAC

// Format of address. One of above types
Expand Down Expand Up @@ -198,10 +198,19 @@ public byte[] getAddressUnsafe() {
return ip;
}

public void setAddress(byte[] newip, byte[] mac) {
setAddress(newip);

if (mac != null && getType() != IPV6) {
// Only set mac if we are not IPV6
setMac(mac);
}
}

/**
* Set a 48 bit MAC address into an iPv4-mapped IPv6 address.
*/
public void setMac(byte[] mac) {
private void setMac(byte[] mac) {
if (getType() != IPV4 && getType() != IPV4MAC) {
throw new IllegalArgumentException("Address is not an IPv4 or IPv4-mapped IPv6 address");
}
Expand Down

0 comments on commit 0c97c1f

Please sign in to comment.