Index: uKadecot/trunk/uip/net/ip/psock.h
===================================================================
--- uKadecot/trunk/uip/net/ip/psock.h	(revision 158)
+++ uKadecot/trunk/uip/net/ip/psock.h	(revision 262)
@@ -111,5 +111,5 @@
   uint8_t *readptr;         /* Pointer to the next data to be read. */
 
-  char *bufptr;          /* Pointer to the buffer used for buffering
+  uint8_t *bufptr;          /* Pointer to the buffer used for buffering
                             incoming data. */
 
@@ -124,5 +124,5 @@
 };
 
-void psock_init(struct psock *psock, char *buffer, unsigned int buffersize);
+void psock_init(struct psock *psock, uint8_t *buffer, unsigned int buffersize);
 /**
  * Initialize a protosocket.
@@ -135,5 +135,5 @@
  * initialized
  *
- * \param buffer (char *) A pointer to the input buffer for the
+ * \param buffer (uint8_t *) A pointer to the input buffer for the
  * protosocket.
  *
@@ -158,5 +158,5 @@
 #define PSOCK_BEGIN(psock) PT_BEGIN(&((psock)->pt))
 
-PT_THREAD(psock_send(struct psock *psock, const char *buf, unsigned int len));
+PT_THREAD(psock_send(struct psock *psock, const uint8_t *buf, unsigned int len));
 /**
  * Send data.
@@ -169,5 +169,5 @@
  * data is to be sent.
  *
- * \param data (char *) A pointer to the data that is to be sent.
+ * \param data (uint8_t *) A pointer to the data that is to be sent.
  *
  * \param datalen (unsigned int) The length of the data that is to be
@@ -190,5 +190,5 @@
  */
 #define PSOCK_SEND_STR(psock, str)      		\
-    PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, str, strlen(str)))
+  PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, (uint8_t *)str, strlen(str)))
 
 PT_THREAD(psock_generator_send(struct psock *psock,
@@ -257,5 +257,5 @@
  * This macro will block waiting for data and read the data into the
  * input buffer specified with the call to PSOCK_INIT(). Data is only
- * read until the specifieed character appears in the data stream.
+ * read until the specified character appears in the data stream.
  *
  * \param psock (struct psock *) A pointer to the protosocket from which
@@ -353,5 +353,5 @@
    PSOCK_BEGIN(s);
 
-   PSOCK_WAIT_UNTIL(s, PSOCK_NEWADATA(s) || timer_expired(t));
+   PSOCK_WAIT_UNTIL(s, PSOCK_NEWDATA(s) || timer_expired(t));
 
    if(PSOCK_NEWDATA(s)) {
@@ -379,2 +379,3 @@
 
 /** @} */
+/** @} */
Index: uKadecot/trunk/uip/net/ip/uip.h
===================================================================
--- uKadecot/trunk/uip/net/ip/uip.h	(revision 158)
+++ uKadecot/trunk/uip/net/ip/uip.h	(revision 262)
@@ -15,5 +15,4 @@
  *
  */
-
 
 /*
@@ -57,12 +56,22 @@
 
 /**
- * Repressentation of an IP address.
- *
- */
-typedef uint16_t uip_ip4addr_t[2];
-typedef uint16_t uip_ip6addr_t[8];
+ * Representation of an IP address.
+ *
+ */
 #if UIP_CONF_IPV6
+typedef union uip_ip6addr_t {
+  uint8_t  u8[16];			/* Initializer, must come first!!! */
+  uint16_t u16[8];
+} uip_ip6addr_t;
+
 typedef uip_ip6addr_t uip_ipaddr_t;
 #else /* UIP_CONF_IPV6 */
+typedef union uip_ip4addr_t {
+  uint8_t  u8[4];			/* Initializer, must come first!!! */
+  uint16_t u16[2];
+#if 0
+  uint32_t u32;
+#endif
+} uip_ip4addr_t;
 typedef uip_ip4addr_t uip_ipaddr_t;
 #endif /* UIP_CONF_IPV6 */
@@ -73,5 +82,4 @@
  * handled by the following three functions.
  */
-
 /**
  * \defgroup uipconffunc uIP configuration functions
@@ -104,5 +112,5 @@
  * \hideinitializer
  */
-#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr))
+#define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
 
 /**
@@ -124,5 +132,5 @@
  * \hideinitializer
  */
-#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr)
+#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
 
 /**
@@ -136,5 +144,5 @@
  * \hideinitializer
  */
-#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))
+#define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
 
 /**
@@ -148,5 +156,5 @@
  * \hideinitializer
  */
-#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr))
+#define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
 
 
@@ -159,5 +167,5 @@
  * \hideinitializer
  */
-#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)
+#define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
 
 /**
@@ -169,5 +177,5 @@
  * \hideinitializer
  */
-#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask)
+#define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
 
 /** @} */
@@ -238,5 +246,5 @@
   uip_len = ethernet_devicedrver_poll();
   if(uip_len > 0) {
-    if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+    if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) {
       uip_arp_ipin();
       uip_input();
@@ -245,5 +253,5 @@
         ethernet_devicedriver_send();
       }
-    } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+    } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) {
       uip_arp_arpin();
       if(uip_len > 0) {
@@ -257,4 +265,5 @@
 #define uip_input()        uip_process(UIP_DATA)
 
+
 /**
  * Periodic processing for a connection identified by its number.
@@ -270,5 +279,5 @@
  * should be called to send out the packet.
  *
- * The ususal way of calling the function is through a for() loop like
+ * The usual way of calling the function is through a for() loop like
  * this:
  \code
@@ -325,5 +334,5 @@
 
 /**
- * Reuqest that a particular connection should be polled.
+ * Request that a particular connection should be polled.
  *
  * Similar to uip_periodic_conn() but does not perform any timer
@@ -390,6 +399,4 @@
 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
                                          uip_process(UIP_UDP_TIMER); } while (0)
-
-
 #endif /* UIP_UDP */
 
@@ -444,8 +451,8 @@
  *
  * \note Since this function expects the port number in network byte
- * order, a conversion using HTONS() or htons() is necessary.
- *
- \code
- uip_listen(HTONS(80));
+ * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
+ *
+ \code
+ uip_listen(UIP_HTONS(80));
  \endcode
  *
@@ -458,8 +465,8 @@
  *
  * \note Since this function expects the port number in network byte
- * order, a conversion using HTONS() or htons() is necessary.
- *
- \code
- uip_unlisten(HTONS(80));
+ * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
+ *
+ \code
+ uip_unlisten(UIP_HTONS(80));
  \endcode
  *
@@ -472,5 +479,5 @@
  *
  * This function is used to start a new connection to the specified
- * port on the specied host. It allocates a new connection identifier,
+ * port on the specified host. It allocates a new connection identifier,
  * sets the connection to the SYN_SENT state and sets the
  * retransmission timer to 0. This will cause a TCP SYN segment to be
@@ -479,9 +486,9 @@
  * uip_connect().
  *
- * \note This function is avaliable only if support for active open
+ * \note This function is available only if support for active open
  * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
  *
  * \note Since this function requires the port number to be in network
- * byte order, a conversion using HTONS() or htons() is necessary.
+ * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary.
  *
  \code
@@ -489,8 +496,8 @@
 
  uip_ipaddr(&ipaddr, 192,168,1,2);
- uip_connect(&ipaddr, HTONS(80));
- \endcode
- *
- * \param ripaddr The IP address of the remote hot.
+ uip_connect(&ipaddr, UIP_HTONS(80));
+ \endcode
+ *
+ * \param ripaddr The IP address of the remote host.
  *
  * \param port A 16-bit port number in network byte order.
@@ -523,5 +530,5 @@
  *
  * The amount of data that actually is sent out after a call to this
- * funcion is determined by the maximum amount of data TCP allows. uIP
+ * function is determined by the maximum amount of data TCP allows. uIP
  * will automatically crop the data so that only the appropriate
  * amount of data is sent. The function uip_mss() can be used to query
@@ -543,5 +550,5 @@
 
 /**
- * The length of any incoming data that is currently avaliable (if avaliable)
+ * The length of any incoming data that is currently available (if available)
  * in the uip_appdata buffer.
  *
@@ -578,5 +585,5 @@
  *
  * This function will abort (reset) the current connection, and is
- * usually used when an error has occured that prevents using the
+ * usually used when an error has occurred that prevents using the
  * uip_close() function.
  *
@@ -635,5 +642,5 @@
  * Will reduce to non-zero if there is new data for the application
  * present at the uip_appdata pointer. The size of the data is
- * avaliable through the uip_len variable.
+ * available through the uip_len variable.
  *
  * \hideinitializer
@@ -721,5 +728,5 @@
 
 /**
- * Get the initial maxium segment size (MSS) of the current
+ * Get the initial maximum segment size (MSS) of the current
  * connection.
  *
@@ -729,8 +736,8 @@
 
 /**
- * Get the current maxium segment size that can be sent on the current
+ * Get the current maximum segment size that can be sent on the current
  * connection.
  *
- * The current maxiumum segment size that can be sent on the
+ * The current maximum segment size that can be sent on the
  * connection is computed from the receiver's window and the MSS of
  * the connection (which also is available by calling
@@ -756,7 +763,7 @@
 
  uip_ipaddr(&addr, 192,168,2,1);
- c = uip_udp_new(&addr, HTONS(12345));
+ c = uip_udp_new(&addr, UIP_HTONS(12345));
  if(c != NULL) {
-   uip_udp_bind(c, HTONS(12344));
+   uip_udp_bind(c, UIP_HTONS(12344));
  }
  \endcode
@@ -768,5 +775,5 @@
  * if no connection could be allocated.
  */
-struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, uint16_t rport);
+struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport);
 
 /**
@@ -829,5 +836,5 @@
 
  uip_ipaddr(&ipaddr, 192,168,1,2);
- c = uip_connect(&ipaddr, HTONS(80));
+ c = uip_connect(&ipaddr, UIP_HTONS(80));
  \endcode
  *
@@ -842,7 +849,9 @@
  * \hideinitializer
  */
-#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
-                     ((uint16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \
-                     ((uint16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \
+#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do {  \
+    (addr)->u8[0] = addr0;                              \
+    (addr)->u8[1] = addr1;                              \
+    (addr)->u8[2] = addr2;                              \
+    (addr)->u8[3] = addr3;                              \
                   } while(0)
 
@@ -855,12 +864,12 @@
  */
 #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
-                     ((uint16_t *)(addr))[0] = HTONS((addr0)); \
-                     ((uint16_t *)(addr))[1] = HTONS((addr1)); \
-                     ((uint16_t *)(addr))[2] = HTONS((addr2)); \
-                     ((uint16_t *)(addr))[3] = HTONS((addr3)); \
-                     ((uint16_t *)(addr))[4] = HTONS((addr4)); \
-                     ((uint16_t *)(addr))[5] = HTONS((addr5)); \
-                     ((uint16_t *)(addr))[6] = HTONS((addr6)); \
-                     ((uint16_t *)(addr))[7] = HTONS((addr7)); \
+    (addr)->u16[0] = UIP_HTONS(addr0);                                      \
+    (addr)->u16[1] = UIP_HTONS(addr1);                                      \
+    (addr)->u16[2] = UIP_HTONS(addr2);                                      \
+    (addr)->u16[3] = UIP_HTONS(addr3);                                      \
+    (addr)->u16[4] = UIP_HTONS(addr4);                                      \
+    (addr)->u16[5] = UIP_HTONS(addr5);                                      \
+    (addr)->u16[6] = UIP_HTONS(addr6);                                      \
+    (addr)->u16[7] = UIP_HTONS(addr7);                                      \
                   } while(0)
 
@@ -883,12 +892,7 @@
  * \hideinitializer
  */
-#if !UIP_CONF_IPV6
-#define uip_ipaddr_copy(dest, src) do { \
-                     ((uint16_t *)dest)[0] = ((uint16_t *)src)[0]; \
-                     ((uint16_t *)dest)[1] = ((uint16_t *)src)[1]; \
-                  } while(0)
-#else /* !UIP_CONF_IPV6 */
-#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t))
-#endif /* !UIP_CONF_IPV6 */
+#ifndef uip_ipaddr_copy
+#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
+#endif
 
 /**
@@ -913,6 +917,6 @@
  */
 #if !UIP_CONF_IPV6
-#define uip_ipaddr_cmp(addr1, addr2) (((uint16_t *)addr1)[0] == ((uint16_t *)addr2)[0] && \
-                                      ((uint16_t *)addr1)[1] == ((uint16_t *)addr2)[1])
+#define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
+                                      (addr1)->u16[1] == (addr2)->u16[1])
 #else /* !UIP_CONF_IPV6 */
 #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
@@ -997,5 +1001,5 @@
  * \hideinitializer
  */
-#define uip_ipaddr1(addr) (htons(((uint16_t *)(addr))[0]) >> 8)
+#define uip_ipaddr1(addr) ((addr)->u8[0])
 
 /**
@@ -1017,5 +1021,5 @@
  * \hideinitializer
  */
-#define uip_ipaddr2(addr) (htons(((uint16_t *)(addr))[0]) & 0xff)
+#define uip_ipaddr2(addr) ((addr)->u8[1])
 
 /**
@@ -1037,5 +1041,5 @@
  * \hideinitializer
  */
-#define uip_ipaddr3(addr) (htons(((uint16_t *)(addr))[1]) >> 8)
+#define uip_ipaddr3(addr) ((addr)->u8[2])
 
 /**
@@ -1057,5 +1061,5 @@
  * \hideinitializer
  */
-#define uip_ipaddr4(addr) (htons(((uint16_t *)(addr))[1]) & 0xff)
+#define uip_ipaddr4(addr) ((addr)->u8[3])
 
 /**
@@ -1064,17 +1068,19 @@
  * This macro is primarily used for converting constants from host
  * byte order to network byte order. For converting variables to
- * network byte order, use the htons() function instead.
- *
- * \hideinitializer
- */
-#ifndef HTONS
+ * network byte order, use the uip_htons() function instead.
+ *
+ * \hideinitializer
+ */
+#ifndef UIP_HTONS
 #   if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
-#      define HTONS(n) (n)
+#      define UIP_HTONS(n) (n)
+#      define UIP_HTONL(n) (n)
 #   else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
-#      define HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8))
+#      define UIP_HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8))
+#      define UIP_HTONL(n) (((uint32_t)UIP_HTONS(n) << 16) | UIP_HTONS((uint32_t)(n) >> 16))
 #   endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
 #else
-#error "HTONS already defined!"
-#endif /* HTONS */
+#error "UIP_HTONS already defined!"
+#endif /* UIP_HTONS */
 
 /**
@@ -1083,11 +1089,11 @@
  * This function is primarily used for converting variables from host
  * byte order to network byte order. For converting constants to
- * network byte order, use the HTONS() macro instead.
- */
-#ifndef htons
-uint16_t htons(uint16_t val);
-#endif /* htons */
-#ifndef ntohs
-#define ntohs htons
+ * network byte order, use the UIP_HTONS() macro instead.
+ */
+#ifndef uip_htons
+uint16_t uip_htons(uint16_t val);
+#endif /* uip_htons */
+#ifndef uip_ntohs
+#define uip_ntohs uip_htons
 #endif
 
@@ -1150,5 +1156,5 @@
  * The uip_conn structure is used for identifying a connection. All
  * but one field in the structure are to be considered read-only by an
- * application. The only exception is the appstate field whos purpose
+ * application. The only exception is the appstate field whose purpose
  * is to let the application store application-specific state (e.g.,
  * file pointers) for the connection. The type of this field is
@@ -1192,4 +1198,5 @@
  * connection.
  */
+
 extern struct uip_conn *uip_conn;
 /* The array containing all uIP connections. */
@@ -1204,5 +1211,4 @@
  */
 extern uint8_t uip_acc32[4];
-
 /** @} */
 
@@ -1236,9 +1242,9 @@
 struct uip_stats {
   struct {
-    uip_stats_t drop;     /**< Number of dropped packets at the IP
-                             layer. */
     uip_stats_t recv;     /**< Number of received packets at the IP
                              layer. */
     uip_stats_t sent;     /**< Number of sent packets at the IP
+                             layer. */
+    uip_stats_t drop;     /**< Number of dropped packets at the IP
                              layer. */
     uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
@@ -1256,14 +1262,14 @@
   } ip;                   /**< IP statistics. */
   struct {
-    uip_stats_t drop;     /**< Number of dropped ICMP packets. */
     uip_stats_t recv;     /**< Number of received ICMP packets. */
     uip_stats_t sent;     /**< Number of sent ICMP packets. */
+    uip_stats_t drop;     /**< Number of dropped ICMP packets. */
     uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
                              type. */
   } icmp;                 /**< ICMP statistics. */
   struct {
-    uip_stats_t drop;     /**< Number of dropped TCP segments. */
     uip_stats_t recv;     /**< Number of recived TCP segments. */
     uip_stats_t sent;     /**< Number of sent TCP segments. */
+    uip_stats_t drop;     /**< Number of dropped TCP segments. */
     uip_stats_t chkerr;   /**< Number of TCP segments with a bad
                              checksum. */
@@ -1273,5 +1279,5 @@
     uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
     uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few
-                             connections was avaliable. */
+                             connections was available. */
     uip_stats_t synrst;   /**< Number of SYNs for closed ports,
                              triggering a RST. */
@@ -1301,9 +1307,12 @@
  */
 /*---------------------------------------------------------------------------*/
+
+
+
 /* uint8_t uip_flags:
  *
  * When the application is called, uip_flags will contain the flags
  * that are defined in this file. Please read below for more
- * infomation.
+ * information.
  */
 extern uint8_t uip_flags;
@@ -1312,5 +1321,5 @@
    before calling the application callback. The UIP_ACKDATA,
    UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
-   whereas the others are mutualy exclusive. Note that these flags
+   whereas the others are mutually exclusive. Note that these flags
    should *NOT* be accessed directly, but only through the uIP
    functions/macros. */
@@ -1356,5 +1365,5 @@
    incoming data that should be processed, or because the periodic
    timer has fired. These values are never used directly, but only in
-   the macrose defined in this file. */
+   the macros defined in this file. */
 
 #define UIP_DATA          1     /* Tells uIP that there is incoming
@@ -1413,6 +1422,5 @@
     proto;
   uint16_t ipchksum;
-  uint16_t srcipaddr[2],
-    destipaddr[2];
+  uip_ipaddr_t srcipaddr, destipaddr;
 #endif /* UIP_CONF_IPV6 */
 
@@ -1450,14 +1458,12 @@
     proto;
   uint16_t ipchksum;
-  uint16_t srcipaddr[2],
-    destipaddr[2];
+  uip_ipaddr_t srcipaddr, destipaddr;
 #endif /* UIP_CONF_IPV6 */
 
-  /* ICMP (echo) header. */
+  /* ICMP header. */
   uint8_t type, icode;
   uint16_t icmpchksum;
 #if !UIP_CONF_IPV6
   uint16_t id, seqno;
-#else /* !UIP_CONF_IPV6 */
   uint8_t flags, reserved1, reserved2, reserved3;
   uint8_t icmp6data[16];
@@ -1487,6 +1493,5 @@
     proto;
   uint16_t ipchksum;
-  uint16_t srcipaddr[2],
-    destipaddr[2];
+  uip_ipaddr_t srcipaddr, destipaddr;
 #endif /* UIP_CONF_IPV6 */
 
@@ -1548,4 +1553,6 @@
 extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
 #endif /* UIP_FIXEDADDR */
+extern const uip_ipaddr_t uip_broadcast_addr;
+extern const uip_ipaddr_t uip_all_zeroes_addr;
 
 
Index: uKadecot/trunk/uip/net/ip/uiplib.c
===================================================================
--- uKadecot/trunk/uip/net/ip/uiplib.c	(revision 158)
+++ uKadecot/trunk/uip/net/ip/uiplib.c	(revision 262)
@@ -40,6 +40,6 @@
 
 /*-----------------------------------------------------------------------------------*/
-unsigned char
-uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
+int
+uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *ipaddr)
 {
   unsigned char tmp;
@@ -58,6 +58,5 @@
       }
       if(c == '.' || c == 0) {
-        *ipaddr = tmp;
-        ++ipaddr;
+        ipaddr->u8[i] = tmp;
         tmp = 0;
       } else if(c >= '0' && c <= '9') {
Index: uKadecot/trunk/uip/net/ip/uiplib.h
===================================================================
--- uKadecot/trunk/uip/net/ip/uiplib.h	(revision 158)
+++ uKadecot/trunk/uip/net/ip/uiplib.h	(revision 262)
@@ -53,11 +53,12 @@
  *
  * This function takes a textual representation of an IP address in
- * the form a.b.c.d and converts it into a 4-byte array that can be
- * used by other uIP functions.
+ * the form a.b.c.d for IPv4 or a:b:c:d:e:f:g:h for IPv6 and converts
+ * it into a numeric IP address representation that can be used by
+ * other uIP functions.
  *
  * \param addrstr A pointer to a string containing the IP address in
  * textual form.
  *
- * \param addr A pointer to a 4-byte array that will be filled in with
+ * \param addr A pointer to a uip_ipaddr_t that will be filled in with
  * the numerical representation of the address.
  *
@@ -65,5 +66,5 @@
  * \retval Non-zero If the IP address was parsed.
  */
-unsigned char uiplib_ipaddrconv(char *addrstr, unsigned char *addr);
+int uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *addr);
 
 /** @} */
Index: uKadecot/trunk/uip/net/ipv4/uip-fw.c
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip-fw.c	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip-fw.c	(revision 262)
@@ -86,6 +86,5 @@
     proto;
   uint16_t ipchksum;
-  uint16_t srcipaddr[2],
-    destipaddr[2];
+  uip_ipaddr_t srcipaddr, destipaddr;
   
   /* TCP header. */
@@ -112,6 +111,5 @@
     proto;
   uint16_t ipchksum;
-  uint16_t srcipaddr[2],
-    destipaddr[2];
+  uip_ipaddr_t srcipaddr, destipaddr;
   /* ICMP (echo) header. */
   uint8_t type, icode;
@@ -144,6 +142,6 @@
   uint16_t timer;
   
-  uint16_t srcipaddr[2];
-  uint16_t destipaddr[2];
+  uip_ipaddr_t srcipaddr;
+  uip_ipaddr_t destipaddr;
   uint16_t ipid;
   uint8_t proto;
@@ -217,8 +215,10 @@
 /*------------------------------------------------------------------------------*/
 static unsigned char
-ipaddr_maskcmp(uint16_t *ipaddr, uint16_t *netipaddr, uint16_t *netmask)
-{
-  return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) &&
-    (ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]);
+ipaddr_maskcmp(uip_ipaddr_t *ipaddr,
+               uip_ipaddr_t *netipaddr,
+               uip_ipaddr_t *netmask)
+{
+  return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) &&
+    (ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]);
 }
 /*------------------------------------------------------------------------------*/
@@ -254,14 +254,8 @@
   /* Set the IP destination address to be the source address of the
      original packet. */
-  tmp16= BUF->destipaddr[0];
-  BUF->destipaddr[0] = BUF->srcipaddr[0];
-  BUF->srcipaddr[0] = tmp16;
-  tmp16 = BUF->destipaddr[1];
-  BUF->destipaddr[1] = BUF->srcipaddr[1];
-  BUF->srcipaddr[1] = tmp16;
+  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
 
   /* Set our IP address as the source address. */
-  BUF->srcipaddr[0] = uip_hostaddr[0];
-  BUF->srcipaddr[1] = uip_hostaddr[1];
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
 
   /* The size of the ICMP time exceeded packet is 36 + the size of the
@@ -269,5 +263,5 @@
   uip_len = 56;
   ICMPBUF->len[0] = 0;
-  ICMPBUF->len[1] = uip_len;
+  ICMPBUF->len[1] = (uint8_t)uip_len;
 
   /* Fill in the other fields in the IP header. */
@@ -313,8 +307,6 @@
   fw->timer = FW_TIME;
   fw->ipid = BUF->ipid;
-  fw->srcipaddr[0] = BUF->srcipaddr[0];
-  fw->srcipaddr[1] = BUF->srcipaddr[1];
-  fw->destipaddr[0] = BUF->destipaddr[0];
-  fw->destipaddr[1] = BUF->destipaddr[1];
+  uip_ipaddr_copy(&fw->srcipaddr, &BUF->srcipaddr);
+  uip_ipaddr_copy(&fw->destipaddr, &BUF->destipaddr);
   fw->proto = BUF->proto;
 #if notdef
@@ -340,6 +332,6 @@
   /* Walk through every network interface to check for a match. */
   for(netif = netifs; netif != NULL; netif = netif->next) {
-    if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
-                      netif->netmask)) {
+    if(ipaddr_maskcmp(&BUF->destipaddr, &netif->ipaddr,
+                      &netif->netmask)) {
       /* If there was a match, we break the loop. */
       return netif;
@@ -371,4 +363,7 @@
 {
   struct uip_fw_netif *netif;
+#if UIP_BROADCAST
+  const struct uip_udpip_hdr *udp = (void *)BUF;
+#endif /* UIP_BROADCAST */
 
   if(uip_len == 0) {
@@ -380,7 +375,5 @@
 #if UIP_BROADCAST
   /* Link local broadcasts go out on all interfaces. */
-  if(/*BUF->proto == UIP_PROTO_UDP &&*/
-     BUF->destipaddr[0] == 0xffff &&
-     BUF->destipaddr[1] == 0xffff) {
+  if(uip_ipaddr_cmp(&udp->destipaddr, &uip_broadcast_addr)) {
     if(defaultnetif != NULL) {
       defaultnetif->output();
@@ -422,6 +415,5 @@
   /* First check if the packet is destined for ourselves and return 0
      to indicate that the packet should be processed locally. */
-  if(BUF->destipaddr[0] == uip_hostaddr[0] &&
-     BUF->destipaddr[1] == uip_hostaddr[1]) {
+  if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
     return UIP_FW_LOCAL;
   }
@@ -430,5 +422,5 @@
      not yet configured, we should intercept all ICMP echo packets. */
 #if UIP_PINGADDRCONF
-  if((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
+  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) &&
      BUF->proto == UIP_PROTO_ICMP &&
      ICMPBUF->type == ICMP_ECHO) {
@@ -447,8 +439,6 @@
 #endif
        fw->ipid == BUF->ipid &&
-       fw->srcipaddr[0] == BUF->srcipaddr[0] &&
-       fw->srcipaddr[1] == BUF->srcipaddr[1] &&
-       fw->destipaddr[0] == BUF->destipaddr[0] &&
-       fw->destipaddr[1] == BUF->destipaddr[1] &&
+       uip_ipaddr_cmp(&fw->srcipaddr, &BUF->srcipaddr) &&
+       uip_ipaddr_cmp(&fw->destipaddr, &BUF->destipaddr) &&
 #if notdef
        fw->payload[0] == BUF->srcport &&
@@ -464,7 +454,8 @@
      in the uip_buf buffer and forward that packet back to the sender
      of the packet. */
+
   if(BUF->ttl <= 1) {
     /* No time exceeded for broadcasts and multicasts! */
-    if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
+    if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
       return UIP_FW_LOCAL;
     }
@@ -476,8 +467,8 @@
   
   /* Update the IP checksum. */
-  if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {
-    BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;
+  if(BUF->ipchksum >= UIP_HTONS(0xffff - 0x0100)) {
+    BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100) + 1;
   } else {
-    BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);
+    BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100);
   }
 
@@ -488,5 +479,5 @@
 
 #if UIP_BROADCAST
-  if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
+  if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
     return UIP_FW_LOCAL;
   }
Index: uKadecot/trunk/uip/net/ipv4/uip-fw.h
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip-fw.h	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip-fw.h	(revision 262)
@@ -55,6 +55,6 @@
   struct uip_fw_netif *next;  /**< Pointer to the next interface when
                                  linked in a list. */
-  uint16_t ipaddr[2];            /**< The IP address of this interface. */
-  uint16_t netmask[2];           /**< The netmask of the interface. */
+  uip_ipaddr_t ipaddr;            /**< The IP address of this interface. */
+  uip_ipaddr_t netmask;           /**< The netmask of the interface. */
   uint8_t (* output)(void);
                               /**< A pointer to the function that
@@ -63,5 +63,5 @@
 
 /**
- * Intantiating macro for a uIP network interface.
+ * Instantiating macro for a uIP network interface.
  *
  * Example:
@@ -80,6 +80,6 @@
 #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
         NULL, \
-        {HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
-        {HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
+        { {ip1, ip2, ip3, ip4} }, \
+        { {nm1, nm2, nm3, nm4} }, \
         outputfunc
 
Index: uKadecot/trunk/uip/net/ipv4/uip-neighbor.c
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip-neighbor.c	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip-neighbor.c	(revision 262)
@@ -83,5 +83,5 @@
 /*---------------------------------------------------------------------------*/
 void
-uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
+uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr)
 {
   int i, oldest;
@@ -100,5 +100,5 @@
       break;
     }
-    if(uip_ipaddr_cmp(entries[i].ipaddr, addr)) {
+    if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) {
       oldest = i;
       break;
@@ -113,15 +113,15 @@
      "oldest" variable). */
   entries[oldest].time = 0;
-  uip_ipaddr_copy(entries[oldest].ipaddr, ipaddr);
+  uip_ipaddr_copy(&entries[oldest].ipaddr, ipaddr);
   memcpy(&entries[oldest].addr, addr, sizeof(struct uip_neighbor_addr));
 }
 /*---------------------------------------------------------------------------*/
 static struct neighbor_entry *
-find_entry(uip_ipaddr_t ipaddr)
+find_entry(uip_ipaddr_t *ipaddr)
 {
   int i;
   
   for(i = 0; i < ENTRIES; ++i) {
-    if(uip_ipaddr_cmp(entries[i].ipaddr, ipaddr)) {
+    if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) {
       return &entries[i];
     }
@@ -131,5 +131,5 @@
 /*---------------------------------------------------------------------------*/
 void
-uip_neighbor_update(uip_ipaddr_t ipaddr)
+uip_neighbor_update(uip_ipaddr_t *ipaddr)
 {
   struct neighbor_entry *e;
@@ -142,5 +142,5 @@
 /*---------------------------------------------------------------------------*/
 struct uip_neighbor_addr *
-uip_neighbor_lookup(uip_ipaddr_t ipaddr)
+uip_neighbor_lookup(uip_ipaddr_t *ipaddr)
 {
   struct neighbor_entry *e;
Index: uKadecot/trunk/uip/net/ipv4/uip-neighbor.h
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip-neighbor.h	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip-neighbor.h	(revision 262)
@@ -54,7 +54,7 @@
 
 void uip_neighbor_init(void);
-void uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr);
-void uip_neighbor_update(uip_ipaddr_t ipaddr);
-struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t ipaddr);
+void uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr);
+void uip_neighbor_update(uip_ipaddr_t *ipaddr);
+struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t *ipaddr);
 void uip_neighbor_periodic(void);
 
Index: uKadecot/trunk/uip/net/ipv4/uip.c
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip.c	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip.c	(revision 262)
@@ -99,32 +99,24 @@
 #if UIP_FIXEDADDR > 0
 const uip_ipaddr_t uip_hostaddr =
-  {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
-   HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
+  { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
 const uip_ipaddr_t uip_draddr =
-  {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
-   HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
+  { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
 const uip_ipaddr_t uip_netmask =
-  {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
-   HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
+  { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
 #else
 uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
 #endif /* UIP_FIXEDADDR */
 
-static const uip_ipaddr_t all_ones_addr =
+const uip_ipaddr_t uip_broadcast_addr =
 #if UIP_CONF_IPV6
-  {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
+  { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+      0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
 #else /* UIP_CONF_IPV6 */
-  {0xffff,0xffff};
+  { { 0xff, 0xff, 0xff, 0xff } };
 #endif /* UIP_CONF_IPV6 */
-static const uip_ipaddr_t all_zeroes_addr =
-#if UIP_CONF_IPV6
-  {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
-#else /* UIP_CONF_IPV6 */
-  {0x0000,0x0000};
-#endif /* UIP_CONF_IPV6 */
-
+const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
 
 #if UIP_FIXEDETHADDR
-const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
+const struct uip_eth_addr uip_lladdr = {{UIP_ETHADDR0,
                                           UIP_ETHADDR1,
                                           UIP_ETHADDR2,
@@ -133,5 +125,5 @@
                                           UIP_ETHADDR5}};
 #else
-struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
+struct uip_eth_addr uip_lladdr = {{0,0,0,0,0,0}};
 #endif
 
@@ -311,5 +303,5 @@
 uip_chksum(uint16_t *data, uint16_t len)
 {
-  return htons(chksum(0, (uint8_t *)data, len));
+  return uip_htons(chksum(0, (uint8_t *)data, len));
 }
 /*---------------------------------------------------------------------------*/
@@ -322,5 +314,5 @@
   sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
   DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
-  return (sum == 0) ? 0xffff : htons(sum);
+  return (sum == 0) ? 0xffff : uip_htons(sum);
 }
 #endif
@@ -343,5 +335,5 @@
   sum = upper_layer_len + proto;
   /* Sum IP source and destination addresses. */
-  sum = chksum(sum, (uint8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t));
+  sum = chksum(sum, (uint8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
 
   /* Sum TCP header and data. */
@@ -349,5 +341,5 @@
                upper_layer_len);
 
-  return (sum == 0) ? 0xffff : htons(sum);
+  return (sum == 0) ? 0xffff : uip_htons(sum);
 }
 /*---------------------------------------------------------------------------*/
@@ -375,15 +367,4 @@
 #endif /* UIP_UDP_CHECKSUMS */
 #endif /* UIP_ARCH_CHKSUM */
-uint8_t
-uip_ismulticast(uip_ipaddr_t ipaddr)
-{
-#if UIP_CONF_IPV6
-  return 0;
-#else
-  static const uint16_t multicast_ipaddr[2] = { 0x00e0, 0x0000 };
-  static const uint16_t multicast_mask[2] = { 0x00f0, 0x0000 };
-  return uip_ipaddr_maskcmp(ipaddr, multicast_ipaddr, multicast_mask);
-#endif
-}
 /*---------------------------------------------------------------------------*/
 void
@@ -433,5 +414,5 @@
     conn = &uip_conns[c];
     if(conn->tcpstateflags != UIP_CLOSED &&
-       conn->lport == htons(lastport)) {
+       conn->lport == uip_htons(lastport)) {
       goto again;
     }
@@ -472,5 +453,5 @@
   conn->sa = 0;
   conn->sv = 16;   /* Initial value of the RTT variance. */
-  conn->lport = htons(lastport);
+  conn->lport = uip_htons(lastport);
   conn->rport = rport;
   uip_ipaddr_copy(&conn->ripaddr, ripaddr);
@@ -482,5 +463,5 @@
 #if UIP_UDP
 struct uip_udp_conn *
-uip_udp_new(uip_ipaddr_t *ripaddr, uint16_t rport)
+uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
 {
   register struct uip_udp_conn *conn;
@@ -495,5 +476,5 @@
 
   for(c = 0; c < UIP_UDP_CONNS; ++c) {
-    if(uip_udp_conns[c].lport == htons(lastport)) {
+    if(uip_udp_conns[c].lport == uip_htons(lastport)) {
       goto again;
     }
@@ -513,8 +494,8 @@
   }
 
-  conn->lport = HTONS(lastport);
+  conn->lport = UIP_HTONS(lastport);
   conn->rport = rport;
   if(ripaddr == NULL) {
-    memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t));
+    memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t));
   } else {
     uip_ipaddr_copy(&conn->ripaddr, ripaddr);
@@ -748,4 +729,5 @@
          connection's timer and see if it has reached the RTO value
          in which case we retransmit. */
+
       if(uip_outstanding(uip_connr)) {
         if(uip_connr->timer-- == 0) {
@@ -901,5 +883,5 @@
 #endif /* UIP_CONF_IPV6 */
 
-  if(uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr)) {
+  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
     /* If we are configured to use ping IP address configuration and
        hasn't been assigned an IP address yet, we accept all ICMP
@@ -921,8 +903,14 @@
     DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());
     if(BUF->proto == UIP_PROTO_UDP &&
-       (uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr) ||
-       uip_ismulticast(BUF->destipaddr))
-       /*&&
-         uip_ipchksum() == 0xffff*/) {
+       (uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) ||
+        (BUF->destipaddr.u8[0] & 224) == 224)) {  /* XXX this is a
+                                                     hack to be able
+                                                     to receive UDP
+                                                     multicast
+                                                     packets. We check
+                                                     for the bit
+                                                     pattern of the
+                                                     multicast
+                                                     prefix. */
       goto udp_input;
     }
@@ -931,5 +919,5 @@
     /* Check if the packet is destined for our IP address. */
 #if !UIP_CONF_IPV6
-    if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {
+    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
       UIP_STAT(++uip_stat.ip.drop);
       goto drop;
@@ -941,6 +929,6 @@
        address) as well. However, we will cheat here and accept all
        multicast packets that are sent to the ff02::/16 addresses. */
-    if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) &&
-       BUF->destipaddr[0] != HTONS(0xff02)) {
+    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) &&
+       BUF->destipaddr.u16[0] != UIP_HTONS(0xff02)) {
       UIP_STAT(++uip_stat.ip.drop);
       goto drop;
@@ -1000,7 +988,6 @@
      ourself. */
 #if UIP_PINGADDRCONF
-  if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
-    uip_hostaddr[0] = BUF->destipaddr[0];
-    uip_hostaddr[1] = BUF->destipaddr[1];
+  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
+    uip_hostaddr = BUF->destipaddr;
   }
 #endif /* UIP_PINGADDRCONF */
@@ -1008,16 +995,17 @@
   ICMPBUF->type = ICMP_ECHO_REPLY;
 
-  if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
-    ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
+  if(ICMPBUF->icmpchksum >= UIP_HTONS(0xffff - (ICMP_ECHO << 8))) {
+    ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8) + 1;
   } else {
-    ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
+    ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8);
   }
 
   /* Swap IP addresses. */
-  uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
-  uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
+  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
 
   UIP_STAT(++uip_stat.icmp.sent);
-  goto send;
+  BUF->ttl = UIP_TTL;
+  goto ip_send_nolen;
 
   /* End of IPv4 input header processing code. */
@@ -1040,9 +1028,9 @@
      a neighbor advertisement message back. */
   if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
-    if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
+    if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) {
 
       if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
         /* Save the sender's address in our neighbor list. */
-        uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
+        uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
       }
 
@@ -1054,11 +1042,12 @@
       ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
 
-      uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
-      uip_ipaddr_copy(ICMPBUF->srcipaddr, uip_hostaddr);
+      uip_ipaddr_copy(&ICMPBUF->destipaddr, &ICMPBUF->srcipaddr);
+      uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);
       ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
       ICMPBUF->options[1] = 1;  /* Options length, 1 = 8 bytes. */
-      memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));
+      memcpy(&(ICMPBUF->options[2]), &uip_lladdr, sizeof(uip_lladdr));
       ICMPBUF->icmpchksum = 0;
       ICMPBUF->icmpchksum = ~uip_icmp6chksum();
+
       goto send;
 
@@ -1072,6 +1061,6 @@
     ICMPBUF->type = ICMP6_ECHO_REPLY;
 
-    uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
-    uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
+    uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
+    uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
     ICMPBUF->icmpchksum = 0;
     ICMPBUF->icmpchksum = ~uip_icmp6chksum();
@@ -1110,4 +1099,10 @@
   uip_len = uip_len - UIP_IPUDPH_LEN;
 #endif /* UIP_UDP_CHECKSUMS */
+
+  /* Make sure that the UDP destination port number is not zero. */
+  if(UDPBUF->destport == 0) {
+    UIP_LOG("udp: zero port.");
+    goto drop;
+  }
 
   /* Demultiplex this UDP packet between the UDP "connections". */
@@ -1126,7 +1121,7 @@
        (uip_udp_conn->rport == 0 ||
         UDPBUF->srcport == uip_udp_conn->rport) &&
-       (uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) ||
-        uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||
-        uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {
+       (uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||
+        uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||
+        uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr))) {
       goto udp_found;
     }
@@ -1141,4 +1136,5 @@
   uip_slen = 0;
   UIP_UDP_APPCALL();
+
  udp_send:
   if(uip_slen == 0) {
@@ -1160,5 +1156,5 @@
   BUF->proto = UIP_PROTO_UDP;
 
-  UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);
+  UDPBUF->udplen = UIP_HTONS(uip_slen + UIP_UDPH_LEN);
   UDPBUF->udpchksum = 0;
 
@@ -1166,6 +1162,6 @@
   BUF->destport = uip_udp_conn->rport;
 
-  uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
-  uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
+  uip_ipaddr_copy(&BUF->destipaddr, &uip_udp_conn->ripaddr);
 
   uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
@@ -1196,4 +1192,9 @@
   }
 
+  /* Make sure that the TCP port number is not zero. */
+  if(BUF->destport == 0 || BUF->srcport == 0) {
+    UIP_LOG("tcp: zero port.");
+    goto drop;
+  }
 
   /* Demultiplex this segment. */
@@ -1204,5 +1205,5 @@
        BUF->destport == uip_connr->lport &&
        BUF->srcport == uip_connr->rport &&
-       uip_ipaddr_cmp(BUF->srcipaddr, uip_connr->ripaddr)) {
+       uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) {
       goto found;
     }
@@ -1220,12 +1221,13 @@
   /* Next, check listening connections. */
   for(c = 0; c < UIP_LISTENPORTS; ++c) {
-    if(tmp16 == uip_listenports[c])
+    if(tmp16 == uip_listenports[c]) {
       goto found_listen;
+    }
   }
 
   /* No matching connection found, so we send a RST packet. */
   UIP_STAT(++uip_stat.tcp.synrst);
+
  reset:
-
   /* We do not send resets in response to resets. */
   if(BUF->flags & TCP_RST) {
@@ -1273,6 +1275,6 @@
 
   /* Swap IP addresses. */
-  uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
-  uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
+  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
 
   /* And send out the RST packet! */
@@ -1283,5 +1285,5 @@
      connection and send a SYNACK in return. */
  found_listen:
-  /* First we check if there are any connections avaliable. Unused
+  /* First we check if there are any connections available. Unused
      connections are kept in the same table as used connections, but
      unused ones have the tcpstate set to CLOSED. Also, connections in
@@ -1320,5 +1322,5 @@
   uip_connr->lport = BUF->destport;
   uip_connr->rport = BUF->srcport;
-  uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);
+  uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr);
   uip_connr->tcpstateflags = UIP_SYN_RCVD;
 
@@ -1406,5 +1408,5 @@
     goto drop;
   }
-  /* Calculated the length of the data, if the application has sent
+  /* Calculate the length of the data, if the application has sent
      any data to us. */
   c = (BUF->tcpoffset >> 4) << 2;
@@ -1416,7 +1418,11 @@
   /* First, check if the sequence number of the incoming packet is
      what we're expecting next. If not, we send out an ACK with the
-     correct numbers in. */
-  if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
-       ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
+     correct numbers in, unless we are in the SYN_RCVD state and
+     receive a SYN, in which case we should retransmit our SYNACK
+     (which is done futher down). */
+  if(!((((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
+        ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ||
+       (((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) &&
+        ((BUF->flags & TCP_CTL) == TCP_SYN)))) {
     if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
        (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
@@ -1444,5 +1450,4 @@
       uip_connr->snd_nxt[2] = uip_acc32[2];
       uip_connr->snd_nxt[3] = uip_acc32[3];
-
 
       /* Do RTT estimation, unless we have done retransmissions. */
@@ -1495,4 +1500,8 @@
       goto appsend;
     }
+    /* We need to retransmit the SYNACK */
+    if((BUF->flags & TCP_CTL) == TCP_SYN) {
+      goto tcp_send_synack;
+    }
     goto drop;
 #if UIP_ACTIVE_OPEN
@@ -1798,18 +1807,20 @@
   goto drop;
 
-
   /* We jump here when we are ready to send the packet, and just want
      to set the appropriate TCP sequence numbers in the TCP header. */
  tcp_send_ack:
   BUF->flags = TCP_ACK;
+
  tcp_send_nodata:
   uip_len = UIP_IPTCPH_LEN;
+
  tcp_send_noopts:
   BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
- tcp_send:
+
   /* We're done with the input processing. We are now ready to send a
      reply. Our job is to fill in all the fields of the TCP and IP
      headers before calculating the checksum and finally send the
      packet. */
+ tcp_send:
   BUF->ackno[0] = uip_connr->rcv_nxt[0];
   BUF->ackno[1] = uip_connr->rcv_nxt[1];
@@ -1827,6 +1838,6 @@
   BUF->destport = uip_connr->rport;
 
-  uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
-  uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr);
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
+  uip_ipaddr_copy(&BUF->destipaddr, &uip_connr->ripaddr);
 
   if(uip_connr->tcpstateflags & UIP_STOPPED) {
@@ -1858,5 +1869,4 @@
 
  ip_send_nolen:
-
 #if UIP_CONF_IPV6
   BUF->vtc = 0x60;
@@ -1875,7 +1885,8 @@
   DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());
 #endif /* UIP_CONF_IPV6 */
-
   UIP_STAT(++uip_stat.tcp.sent);
+#if UIP_CONF_IPV6
  send:
+#endif /* UIP_CONF_IPV6 */
   DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
                (BUF->len[0] << 8) | BUF->len[1]);
@@ -1885,4 +1896,5 @@
   uip_flags = 0;
   return;
+
  drop:
   uip_len = 0;
@@ -1892,7 +1904,7 @@
 /*---------------------------------------------------------------------------*/
 uint16_t
-htons(uint16_t val)
+uip_htons(uint16_t val)
 {
-  return HTONS(val);
+  return UIP_HTONS(val);
 }
 /*---------------------------------------------------------------------------*/
Index: uKadecot/trunk/uip/net/ipv4/uip_arp.c
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip_arp.c	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip_arp.c	(revision 262)
@@ -78,7 +78,7 @@
   uint16_t opcode;
   struct uip_eth_addr shwaddr;
-  uint16_t sipaddr[2];
+  uip_ipaddr_t sipaddr;
   struct uip_eth_addr dhwaddr;
-  uint16_t dipaddr[2];
+  uip_ipaddr_t dipaddr;
 };
 
@@ -94,6 +94,5 @@
     proto;
   uint16_t ipchksum;
-  uint16_t srcipaddr[2],
-    destipaddr[2];
+  uip_ipaddr_t srcipaddr, destipaddr;
 };
 
@@ -110,5 +109,5 @@
 
 struct arp_entry {
-  uint16_t ipaddr[2];
+  uip_ipaddr_t ipaddr;
   struct uip_eth_addr ethaddr;
   uint8_t time;
@@ -118,9 +117,7 @@
   {{0xff,0xff,0xff,0xff,0xff,0xff}};
 static const uint16_t broadcast_ipaddr[2] = {0xffff,0xffff};
-static const uint16_t multicast_ipaddr[2] = { 0x00e0, 0x0000 };
-static const uint16_t multicast_mask[2] = { 0x00f0, 0x0000 };
 
 static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
-static uint16_t ipaddr[2];
+static uip_ipaddr_t ipaddr;
 static uint8_t i, c;
 
@@ -140,5 +137,5 @@
 {
   for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-    memset(arp_table[i].ipaddr, 0, 4);
+    memset(&arp_table[i].ipaddr, 0, 4);
   }
 }
@@ -161,30 +158,30 @@
   for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
     tabptr = &arp_table[i];
-    if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
+    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) &&
        arptime - tabptr->time >= UIP_ARP_MAXAGE) {
-      memset(tabptr->ipaddr, 0, 4);
-    }
-  }
-
-}
+      memset(&tabptr->ipaddr, 0, 4);
+    }
+  }
+
+}
+
 /*-----------------------------------------------------------------------------------*/
 static void
-uip_arp_update(uint16_t *ipaddr, struct uip_eth_addr *ethaddr)
-{
-  register struct arp_entry *tabptr = NULL;
+uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr)
+{
+  register struct arp_entry *tabptr = arp_table;
+
   /* Walk through the ARP mapping table and try to find an entry to
      update. If none is found, the IP -> MAC address mapping is
      inserted in the ARP table. */
   for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-
     tabptr = &arp_table[i];
+
     /* Only check those entries that are actually in use. */
-    if(tabptr->ipaddr[0] != 0 &&
-       tabptr->ipaddr[1] != 0) {
+    if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
 
       /* Check if the source IP address of the incoming packet matches
          the IP address in this ARP table entry. */
-      if(ipaddr[0] == tabptr->ipaddr[0] &&
-         ipaddr[1] == tabptr->ipaddr[1]) {
+      if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {
 
         /* An old entry found, update this and return. */
@@ -203,6 +200,5 @@
   for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
     tabptr = &arp_table[i];
-    if(tabptr->ipaddr[0] == 0 &&
-       tabptr->ipaddr[1] == 0) {
+    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
       break;
     }
@@ -227,5 +223,5 @@
   /* Now, i is the ARP table entry which we will fill with the new
      information. */
-  memcpy(tabptr->ipaddr, ipaddr, 4);
+  uip_ipaddr_copy(&tabptr->ipaddr, ipaddr);
   memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
   tabptr->time = arptime;
@@ -300,35 +296,33 @@
 
   switch(BUF->opcode) {
-  case HTONS(ARP_REQUEST):
+  case UIP_HTONS(ARP_REQUEST):
     /* ARP request. If it asked for our address, we send out a
        reply. */
-    if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
+    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
       /* First, we register the one who made the request in our ARP
          table, since it is likely that we will do more communication
          with this host in the future. */
-      uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
+      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
 
       /* The reply opcode is 2. */
-      BUF->opcode = HTONS(2);
+      BUF->opcode = UIP_HTONS(2);
 
       memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
-      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
-      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
+      memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
+      memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
       memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
 
-      BUF->dipaddr[0] = BUF->sipaddr[0];
-      BUF->dipaddr[1] = BUF->sipaddr[1];
-      BUF->sipaddr[0] = uip_hostaddr[0];
-      BUF->sipaddr[1] = uip_hostaddr[1];
-
-      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
+      uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
+      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
+
+      BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
       uip_len = sizeof(struct arp_hdr);
     }
     break;
-  case HTONS(ARP_REPLY):
+  case UIP_HTONS(ARP_REPLY):
     /* ARP reply. We insert or update the ARP table if it was meant
        for us. */
-    if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
-      uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
+    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
+      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
     }
     break;
@@ -378,29 +372,28 @@
 
   /* First check if destination is a local broadcast. */
-  if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {
+  if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) {
     memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
-  }
-  else if(uip_ipaddr_maskcmp(IPBUF->destipaddr, multicast_ipaddr, multicast_mask)) {
+  } else if(IPBUF->destipaddr.u8[0] == 224) {
+    /* Multicast. */
     IPBUF->ethhdr.dest.addr[0] = 0x01;
     IPBUF->ethhdr.dest.addr[1] = 0x00;
-    IPBUF->ethhdr.dest.addr[2] = 0x5E;
-    IPBUF->ethhdr.dest.addr[3] = uip_ipaddr2(IPBUF->destipaddr) & 0x7F;
-    IPBUF->ethhdr.dest.addr[4] = uip_ipaddr3(IPBUF->destipaddr);
-    IPBUF->ethhdr.dest.addr[5] = uip_ipaddr4(IPBUF->destipaddr);
+    IPBUF->ethhdr.dest.addr[2] = 0x5e;
+    IPBUF->ethhdr.dest.addr[3] = IPBUF->destipaddr.u8[1];
+    IPBUF->ethhdr.dest.addr[4] = IPBUF->destipaddr.u8[2];
+    IPBUF->ethhdr.dest.addr[5] = IPBUF->destipaddr.u8[3];
   } else {
     /* Check if the destination address is on the local network. */
-    if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
+    if(!uip_ipaddr_maskcmp(&IPBUF->destipaddr, &uip_hostaddr, &uip_netmask)) {
       /* Destination address was not on the local network, so we need to
          use the default router's IP address instead of the destination
          address when determining the MAC address. */
-      uip_ipaddr_copy(ipaddr, uip_draddr);
+      uip_ipaddr_copy(&ipaddr, &uip_draddr);
     } else {
       /* Else, we use the destination IP address. */
-      uip_ipaddr_copy(ipaddr, IPBUF->destipaddr);
-    }
-
+      uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr);
+    }
     for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
       tabptr = &arp_table[i];
-      if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
+      if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
         break;
       }
@@ -413,15 +406,15 @@
       memset(BUF->ethhdr.dest.addr, 0xff, 6);
       memset(BUF->dhwaddr.addr, 0x00, 6);
-      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
-      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
-
-      uip_ipaddr_copy(BUF->dipaddr, ipaddr);
-      uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr);
-      BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
-      BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
-      BUF->protocol = HTONS(UIP_ETHTYPE_IP);
+      memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
+      memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
+
+      uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
+      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
+      BUF->opcode = UIP_HTONS(ARP_REQUEST); /* ARP request. */
+      BUF->hwtype = UIP_HTONS(ARP_HWTYPE_ETH);
+      BUF->protocol = UIP_HTONS(UIP_ETHTYPE_IP);
       BUF->hwlen = 6;
       BUF->protolen = 4;
-      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
+      BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
 
       uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
@@ -434,7 +427,7 @@
     memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
   }
-  memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
-
-  IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
+  memcpy(IPBUF->ethhdr.src.addr, uip_lladdr.addr, 6);
+
+  IPBUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP);
 
   uip_len += sizeof(struct uip_eth_hdr);
@@ -444,2 +437,3 @@
 /** @} */
 /** @} */
+
Index: uKadecot/trunk/uip/net/ipv4/uip_arp.h
===================================================================
--- uKadecot/trunk/uip/net/ipv4/uip_arp.h	(revision 158)
+++ uKadecot/trunk/uip/net/ipv4/uip_arp.h	(revision 262)
@@ -61,5 +61,5 @@
 #endif
 
-extern struct uip_eth_addr uip_ethaddr;
+extern struct uip_eth_addr uip_lladdr;
 
 /**
@@ -143,13 +143,14 @@
  * \hideinitializer
  */
-#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \
-                              uip_ethaddr.addr[1] = eaddr.addr[1];\
-                              uip_ethaddr.addr[2] = eaddr.addr[2];\
-                              uip_ethaddr.addr[3] = eaddr.addr[3];\
-                              uip_ethaddr.addr[4] = eaddr.addr[4];\
-                              uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)
+#define uip_setethaddr(eaddr) do {uip_lladdr.addr[0] = eaddr.addr[0]; \
+                              uip_lladdr.addr[1] = eaddr.addr[1];\
+                              uip_lladdr.addr[2] = eaddr.addr[2];\
+                              uip_lladdr.addr[3] = eaddr.addr[3];\
+                              uip_lladdr.addr[4] = eaddr.addr[4];\
+                              uip_lladdr.addr[5] = eaddr.addr[5];} while(0)
 
 /** @} */
-/** @} */
+
 
 #endif /* __UIP_ARP_H__ */
+/** @} */
