예제 #1
0
  /**
   * Returns IP address string. Supports both IPv4 and IPv6 addresses.
   *
   * @see #setIPString(String)
   * @return IP address string
   */
  public String getIPString() {
    if (isVersion4()) {
      String ipString = "";
      byte[] ip = moteMem.getByteArray("uip_hostaddr", 4);
      for (int i = 0; i < 3; i++) {
        ipString += (0xFF & ip[i]) + ".";
      }
      ipString += (0xFF & ip[3]);
      return ipString;
    } else if (isVersion6()) {
      String ipString = "";

      /* XXX Assuming fixed offset in struct uip_netif (uip-netif.h) */
      int offset = 4 * 4 /* 4 uint32_t */ + 2 * moteMem.getIntegerLength() /* 2 uint8_t */;
      byte[] tmp = moteMem.getByteArray("uip_netif_physical_if", offset + 16);
      byte[] ip = new byte[16];
      System.arraycopy(tmp, offset, ip, 0, 16);

      int i = 0;
      while (i < 14) {
        int val = (0xFF & ip[i + 1]) + ((0xFF & ip[i]) << 8);
        ipString += hex16ToString(val) + ".";
        i += 2;
      }
      int val = (0xFF & ip[15]) + ((0xFF & ip[14]) << 8);
      ipString += hex16ToString(val);

      return ipString;
    }
    return null;
  }
예제 #2
0
 /** @return True if mote has an IPv6 address */
 public boolean isVersion6() {
   return moteMem.variableExists("uip_netif_physical_if");
 }
예제 #3
0
 /** @return True if mote has an IPv4 address */
 public boolean isVersion4() {
   return moteMem.variableExists("uip_hostaddr");
 }