made ip-address-to-string method public

This commit is contained in:
Fredrik Osterlind 2013-08-14 12:36:14 +02:00
parent 1917ea574f
commit 4811d7f378

View File

@ -122,14 +122,14 @@ public class IPAddress extends MoteInterface {
return ipString;
}
public String getUncompressedIPv6Address() {
public byte[] getIPv6Address() {
byte[] ip = null;
/* IpV6: Struct sizes and offsets */
int ipv6NetworkInterfaceAddressOffset = moteMem.getByteValueOf("uip_ds6_netif_addr_list_offset");
int ipv6AddressStructSize = moteMem.getByteValueOf("uip_ds6_addr_size");
if (ipv6NetworkInterfaceAddressOffset == 0 || ipv6AddressStructSize == 0) {
return "";
return null;
}
/* TODO No need to copy the entire array! */
@ -164,7 +164,10 @@ public class IPAddress extends MoteInterface {
ip = new byte[16];
ipv6AddressIndex = -1;
}
return ip;
}
public static String getUncompressedIPv6AddressString(byte[] ip) {
StringBuilder sb = new StringBuilder();
for (int i=0; i < 14; i+=2) {
sb.append(String.format("%02x%02x:", 0xFF&ip[i+0], 0xFF&ip[i+1]));
@ -173,6 +176,14 @@ public class IPAddress extends MoteInterface {
return sb.toString();
}
public String getUncompressedIPv6Address() {
byte[] ip = getIPv6Address();
if (ip == null) {
return "";
}
return getUncompressedIPv6AddressString(ip);
}
/**
* @return True if mote has an IPv4 address
*/