Index: CHANGELOG
===================================================================
RCS file: /sources/lwip/lwip/CHANGELOG,v
retrieving revision 1.145
diff -u -3 -p -r1.145 CHANGELOG
--- CHANGELOG	22 May 2007 20:51:34 -0000	1.145
+++ CHANGELOG	22 May 2007 20:56:18 -0000
@@ -19,6 +19,10 @@ HISTORY
 
   ++ New features:
 
+  2007-05-22 Frédéric Bernon
+  * api.h, api_lib.c, api_msg.c, sockets.c: group the different NETCONN_UDPxxx
+    code in only one part...
+
   2007-05-18 Simon Goldschmidt
   * opt.h, memp.h, memp.c: Added option MEMP_OVERFLOW_CHECK to check for memp
     elements to overflow. This is achieved by adding some bytes before and after


Index: src/api/api_lib.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/api_lib.c,v
retrieving revision 1.43
diff -u -3 -p -r1.43 api_lib.c
--- src/api/api_lib.c	22 May 2007 20:51:34 -0000	1.43
+++ src/api/api_lib.c	22 May 2007 20:58:01 -0000
@@ -304,12 +304,10 @@ netconn_type(struct netconn *conn)
 err_t
 netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
 {
-  switch (conn->type) {
+  switch (NETCONNTYPE_GROUP(conn->type)) {
   case NETCONN_RAW:
     /* return an error as connecting is only a helper for upper layers */
     return ERR_CONN;
-  case NETCONN_UDPLITE:
-  case NETCONN_UDPNOCHKSUM:
   case NETCONN_UDP:
     if (conn->pcb.udp == NULL ||
   ((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0))
@@ -330,13 +328,11 @@ netconn_peer(struct netconn *conn, struc
 err_t
 netconn_addr(struct netconn *conn, struct ip_addr **addr, u16_t *port)
 {
-  switch (conn->type) {
+  switch (NETCONNTYPE_GROUP(conn->type)) {
   case NETCONN_RAW:
     *addr = &(conn->pcb.raw->local_ip);
     *port = conn->pcb.raw->protocol;
     break;
-  case NETCONN_UDPLITE:
-  case NETCONN_UDPNOCHKSUM:
   case NETCONN_UDP:
     *addr = &(conn->pcb.udp->local_ip);
     *port = conn->pcb.udp->local_port;


Index: src/api/api_msg.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/api_msg.c,v
retrieving revision 1.44
diff -u -3 -p -r1.44 api_msg.c
--- src/api/api_msg.c	22 May 2007 09:54:00 -0000	1.44
+++ src/api/api_msg.c	22 May 2007 20:59:47 -0000
@@ -290,7 +290,7 @@ pcb_new(struct api_msg_msg *msg)
    msg->conn->err = ERR_OK;
 
    /* Allocate a PCB for this connection */
-   switch(msg->conn->type) {
+   switch(NETCONNTYPE_GROUP(msg->conn->type)) {
 #if LWIP_RAW
    case NETCONN_RAW:
      msg->conn->pcb.raw = raw_new(msg->msg.n.proto);
@@ -302,30 +302,14 @@ pcb_new(struct api_msg_msg *msg)
      break;
 #endif /* LWIP_RAW */
 #if LWIP_UDP
-   case NETCONN_UDPLITE:
-     msg->conn->pcb.udp = udp_new();
-     if(msg->conn->pcb.udp == NULL) {
-       msg->conn->err = ERR_MEM;
-       break;
-     }
-     udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
-     udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
-     break;
-   case NETCONN_UDPNOCHKSUM:
-     msg->conn->pcb.udp = udp_new();
-     if(msg->conn->pcb.udp == NULL) {
-       msg->conn->err = ERR_MEM;
-       break;
-     }
-     udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM);
-     udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
-     break;
    case NETCONN_UDP:
      msg->conn->pcb.udp = udp_new();
      if(msg->conn->pcb.udp == NULL) {
        msg->conn->err = ERR_MEM;
        break;
      }
+     if (msg->conn->type==NETCONN_UDPLITE)     udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
+     if (msg->conn->type==NETCONN_UDPNOCHKSUM) udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM);
      udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
      break;
 #endif /* LWIP_UDP */
@@ -363,15 +347,13 @@ void
 do_delconn(struct api_msg_msg *msg)
 {
   if (msg->conn->pcb.tcp != NULL) {
-    switch (msg->conn->type) {
+    switch (NETCONNTYPE_GROUP(msg->conn->type)) {
 #if LWIP_RAW
     case NETCONN_RAW:
       raw_remove(msg->conn->pcb.raw);
       break;
 #endif /* LWIP_RAW */
 #if LWIP_UDP
-    case NETCONN_UDPLITE:
-    case NETCONN_UDPNOCHKSUM:
     case NETCONN_UDP:
       msg->conn->pcb.udp->recv_arg = NULL;
       udp_remove(msg->conn->pcb.udp);
@@ -419,15 +401,13 @@ do_bind(struct api_msg_msg *msg)
     }
 
     if (msg->conn->pcb.tcp != NULL) {
-      switch (msg->conn->type) {
+      switch (NETCONNTYPE_GROUP(msg->conn->type)) {
 #if LWIP_RAW
       case NETCONN_RAW:
         msg->conn->err = raw_bind(msg->conn->pcb.raw,msg->msg.bc.ipaddr);
         break;
 #endif /* LWIP_RAW */
 #if LWIP_UDP
-      case NETCONN_UDPLITE:
-      case NETCONN_UDPNOCHKSUM:
       case NETCONN_UDP:
         msg->conn->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
         break;
@@ -479,7 +459,7 @@ do_connect(struct api_msg_msg *msg)
     }
   }
 
-  switch (msg->conn->type) {
+  switch (NETCONNTYPE_GROUP(msg->conn->type)) {
 #if LWIP_RAW
   case NETCONN_RAW:
     msg->conn->err = raw_connect(msg->conn->pcb.raw, msg->msg.bc.ipaddr);
@@ -487,8 +467,6 @@ do_connect(struct api_msg_msg *msg)
     break;
 #endif /* LWIP_RAW */
 #if LWIP_UDP
-  case NETCONN_UDPLITE:
-  case NETCONN_UDPNOCHKSUM:
   case NETCONN_UDP:
     msg->conn->err = udp_connect(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
     sys_mbox_post(msg->conn->mbox, NULL);
@@ -510,19 +488,11 @@ do_connect(struct api_msg_msg *msg)
 void
 do_disconnect(struct api_msg_msg *msg)
 {
-  switch (msg->conn->type) {
 #if LWIP_UDP
-  case NETCONN_UDPLITE:
-  case NETCONN_UDPNOCHKSUM:
-  case NETCONN_UDP:
+  if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) {
     udp_disconnect(msg->conn->pcb.udp);
-    break;
-#endif /* LWIP_UDP */
-  case NETCONN_TCP:
-  case NETCONN_RAW:
-    /* nothing to do */
-    break;
   }
+#endif /* LWIP_UDP */
   sys_mbox_post(msg->conn->mbox, NULL);
 }
 
@@ -559,7 +529,7 @@ do_send(struct api_msg_msg *msg)
 {
   if (msg->conn->err == ERR_OK) {
     if (msg->conn->pcb.tcp != NULL) {
-      switch (msg->conn->type) {
+      switch (NETCONNTYPE_GROUP(msg->conn->type)) {
 #if LWIP_RAW
       case NETCONN_RAW:
         if (msg->msg.b->addr == NULL) {
@@ -570,8 +540,6 @@ do_send(struct api_msg_msg *msg)
         break;
 #endif
 #if LWIP_UDP
-      case NETCONN_UDPLITE:
-      case NETCONN_UDPNOCHKSUM:
       case NETCONN_UDP:
         if (msg->msg.b->addr == NULL) {
           msg->conn->err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
@@ -664,20 +632,16 @@ do_join_leave_group(struct api_msg_msg *
 { 
   if (msg->conn->err == ERR_OK) {
     if (msg->conn->pcb.tcp != NULL) {
-      switch (msg->conn->type) {
+      if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) {
 #if LWIP_UDP
-      case NETCONN_UDPLITE:
-      case NETCONN_UDPNOCHKSUM:
-      case NETCONN_UDP:
         if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
           msg->conn->err = igmp_joingroup ( netif_default, msg->msg.jl.multiaddr);
         } else {
           msg->conn->err = igmp_leavegroup( netif_default, msg->msg.jl.multiaddr);
         }
-        break;
 #endif /* LWIP_UDP */
 #if (LWIP_TCP || LWIP_RAW)
-      default:
+      } else {
         msg->conn->err = ERR_VAL;
 #endif /* (LWIP_TCP || LWIP_RAW) */
       }


Index: src/api/sockets.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/sockets.c,v
retrieving revision 1.51
diff -u -3 -p -r1.51 sockets.c
--- src/api/sockets.c	22 May 2007 20:32:22 -0000	1.51
+++ src/api/sockets.c	22 May 2007 20:57:27 -0000
@@ -1081,7 +1081,7 @@ int lwip_getsockopt(int s, int level, in
       break;
 
     case SO_TYPE:
-      switch (sock->conn->type) {
+      switch (NETCONNTYPE_GROUP(sock->conn->type)) {
       case NETCONN_RAW:
         *(int*)optval = SOCK_RAW;
         break;
@@ -1089,8 +1089,6 @@ int lwip_getsockopt(int s, int level, in
         *(int*)optval = SOCK_STREAM;
         break;
       case NETCONN_UDP:
-      case NETCONN_UDPLITE:
-      case NETCONN_UDPNOCHKSUM:
         *(int*)optval = SOCK_DGRAM;
         break;
       default: /* unrecognized socket type */


Index: src/include/lwip/api.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/api.h,v
retrieving revision 1.20
diff -u -3 -p -r1.20 api.h
--- src/include/lwip/api.h	22 May 2007 09:54:00 -0000	1.20
+++ src/include/lwip/api.h	22 May 2007 20:55:57 -0000
@@ -55,12 +55,19 @@ extern "C" {
 #define NETCONN_NOCOPY 0x00
 #define NETCONN_COPY   0x01
 
+/* Helpers to process several netconn_types by the same code */
+#define NETCONNTYPE_GROUP(t)    (t&0xF0)
+#define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
+
 enum netconn_type {
-  NETCONN_TCP,
-  NETCONN_UDP,
-  NETCONN_UDPLITE,
-  NETCONN_UDPNOCHKSUM,
-  NETCONN_RAW
+  /* NETCONN_TCP Group */
+  NETCONN_TCP        = 0x10,
+  /* NETCONN_UDP Group */
+  NETCONN_UDP        = 0x20,
+  NETCONN_UDPLITE    = 0x21,
+  NETCONN_UDPNOCHKSUM= 0x22,
+  /* NETCONN_RAW Group */
+  NETCONN_RAW        = 0x40
 };
 
 enum netconn_state {
