Dependents:   SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1

Revision:
0:3717b703f76d
Child:
1:e52ec2a24c6a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/if/net/ipaddr.h	Mon May 24 10:23:42 2010 +0000
@@ -0,0 +1,80 @@
+#ifndef IPADDR_H
+#define IPADDR_H
+
+#include "mbed.h"
+
+#include "netCfg.h"
+#if NET_LWIP_STACK
+#include "lwip/ip_addr.h"
+#endif
+class IpAddr;
+
+class IpAddr //Basically a C++ frontend to ip_addr_t
+{
+public:
+  #if NET_LWIP_STACK
+  IpAddr(ip_addr_t* pIp)
+  {
+    *((uint32_t*)m_ip) = pIp->addr;
+  }
+  #endif
+  
+  IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3)
+  {
+    //We are in LE
+    m_ip[0] = ip0;
+    m_ip[1] = ip1;
+    m_ip[2] = ip2;
+    m_ip[3] = ip3;
+  }
+  
+  IpAddr()
+  {
+    m_ip[0] = 0;
+    m_ip[1] = 0;
+    m_ip[2] = 0;
+    m_ip[3] = 0;
+  }
+  
+  #if NET_LWIP_STACK
+  ip_addr_t getStruct() const
+  {
+    ip_addr_t ip_struct;
+    ip_struct.addr = *((uint32_t*)m_ip);
+    return ip_struct;
+  }
+  #endif
+  
+  uint8_t operator[](unsigned int i) const
+  {
+    uint8_t null = 0;
+    if( i > 3 )
+      return null;
+    return m_ip[i];
+  }
+  
+  bool isEq(const IpAddr& b) const
+  {
+    return (*((uint32_t*)m_ip) == *((uint32_t*)(b.m_ip)));
+  }
+  
+  bool operator==(const IpAddr& b) const
+  {
+    return isEq(b);
+  }
+  
+  bool operator!=(const IpAddr& b) const
+  {
+    return !(operator==(b));
+  }
+  
+  bool isNull() const
+  {
+    return (*((uint32_t*)m_ip) == 0);
+  }
+  
+private:
+  uint8_t m_ip[4];
+};
+
+#endif