1 7 8 package java.net; 9 10 19 public class InterfaceAddress { 20 private InetAddress address = null; 21 private Inet4Address broadcast = null; 22 private short maskLength = 0; 23 24 28 InterfaceAddress() { 29 } 30 31 36 public InetAddress getAddress() { 37 return address; 38 } 39 40 50 public InetAddress getBroadcast() { 51 return broadcast; 52 } 53 54 64 public short getNetworkPrefixLength() { 65 return maskLength; 66 } 67 68 83 public boolean equals(Object obj) { 84 if (!(obj instanceof InterfaceAddress )) { 85 return false; 86 } 87 InterfaceAddress cmp = (InterfaceAddress ) obj; 88 if ((address != null & cmp.address == null) || 89 (!address.equals(cmp.address))) 90 return false; 91 if ((broadcast != null & cmp.broadcast == null) || 92 (!broadcast.equals(cmp.broadcast))) 93 return false; 94 if (maskLength != cmp.maskLength) 95 return false; 96 return true; 97 } 98 99 104 public int hashCode() { 105 return address.hashCode() + ((broadcast != null) ? broadcast.hashCode() : 0) + maskLength; 106 } 107 108 114 public String toString() { 115 return address + "/" + maskLength + " [" + broadcast + "]"; 116 } 117 118 } 119 | Popular Tags |