]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/net/lwip_tcpip/v2_0/src/api/sockets.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / net / lwip_tcpip / v2_0 / src / api / sockets.c
index 7c636c64d3b1e5a0b95bed16e7576ec8bb6e453d..eeb0b03cbcd0e6600bc2eb5b310a4b1d14b9f46b 100644 (file)
  *
  */
 
+#include <string.h>
+#include <errno.h>
+
 #include "lwip/opt.h"
 #include "lwip/api.h"
 #include "lwip/arch.h"
 #include "lwip/sys.h"
 
-#define LWIP_TIMEVAL_PRIVATE
 #include "lwip/sockets.h"
 
 #define NUM_SOCKETS MEMP_NUM_NETCONN
@@ -85,9 +87,12 @@ static int err_to_errno_table[11] = {
     EADDRINUSE    /* ERR_USE  -10     Address in use.          */
 };
 
+#define ERR_TO_ERRNO_TABLE_SIZE \
+  (sizeof(err_to_errno_table)/sizeof(err_to_errno_table[0]))
+
 #define err_to_errno(err) \
-  ((err) < (sizeof(err_to_errno_table)/sizeof(int))) ? \
-    err_to_errno_table[-(err)] : EIO
+  (-(err) >= 0 && -(err) < ERR_TO_ERRNO_TABLE_SIZE ? \
+    err_to_errno_table[-(err)] : EIO)
 
 #ifdef ERRNO
 #define set_errno(err) errno = (err)
@@ -416,7 +421,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
     ip_addr_debug_print(SOCKETS_DEBUG, addr);
     LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, copylen));
   } else {
-#if SOCKETS_DEBUG > 0
+#if SOCKETS_DEBUG
     addr = netbuf_fromaddr(buf);
     port = netbuf_fromport(buf);
 
@@ -460,7 +465,6 @@ int
 lwip_send(int s, void *data, int size, unsigned int flags)
 {
   struct lwip_socket *sock;
-  struct netbuf *buf;
   err_t err;
 
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags));
@@ -472,10 +476,15 @@ lwip_send(int s, void *data, int size, unsigned int flags)
   }
 
   switch (netconn_type(sock->conn)) {
+#if LWIP_RAW
   case NETCONN_RAW:
+#endif
+#if LWIP_UDP
   case NETCONN_UDP:
   case NETCONN_UDPLITE:
   case NETCONN_UDPNOCHKSUM:
+  {
+    struct netbuf *buf;
     /* create a buffer */
     buf = netbuf_new();
 
@@ -494,10 +503,14 @@ lwip_send(int s, void *data, int size, unsigned int flags)
 
     /* deallocated the buffer */
     netbuf_delete(buf);
-    break;
+  }
+  break;
+#endif
+#if LWIP_TCP
   case NETCONN_TCP:
     err = netconn_write(sock->conn, data, size, NETCONN_COPY);
     break;
+#endif
   default:
     err = ERR_ARG;
     break;
@@ -559,18 +572,24 @@ lwip_socket(int domain, int type, int protocol)
 
   /* create a netconn */
   switch (type) {
+#if LWIP_RAW
   case SOCK_RAW:
     conn = netconn_new_with_proto_and_callback(NETCONN_RAW, protocol, event_callback);
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
     break;
+#endif
+#if LWIP_UDP
   case SOCK_DGRAM:
     conn = netconn_new_with_callback(NETCONN_UDP, event_callback);
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
     break;
+#endif
+#if LWIP_TCP
   case SOCK_STREAM:
     conn = netconn_new_with_callback(NETCONN_TCP, event_callback);
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
     break;
+#endif
   default:
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", domain, type, protocol));
     set_errno(EINVAL);
@@ -1091,17 +1110,23 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
 
     case SO_TYPE:
       switch (sock->conn->type) {
+#if LWIP_RAW
       case NETCONN_RAW:
         *(int*)optval = SOCK_RAW;
         break;
+#endif
+#if LWIP_TCP
       case NETCONN_TCP:
         *(int*)optval = SOCK_STREAM;
         break;
+#endif
+#if LWIP_UDP
       case NETCONN_UDP:
       case NETCONN_UDPLITE:
       case NETCONN_UDPNOCHKSUM:
         *(int*)optval = SOCK_DGRAM;
         break;
+#endif
       default: /* unrecognized socket type */
         *(int*)optval = sock->conn->type;
         LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n", s, *(int *)optval));
@@ -1139,7 +1164,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n", s, (*(int*)optval)?"on":"off") );
       break;
     case TCP_KEEPALIVE:
-      *(int*)optval = sock->conn->pcb.tcp->keepalive;
+      *(int*)optval = (int)sock->conn->pcb.tcp->keepalive;
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPALIVE) = %d\n", s, *(int *)optval));
       break;
     }  /* switch */
@@ -1307,7 +1332,7 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
       break;
     case TCP_KEEPALIVE:
       sock->conn->pcb.tcp->keepalive = (u32_t)(*(int*)optval);
-      LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %u\n", s, sock->conn->pcb.tcp->keepalive));
+      LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n", s, sock->conn->pcb.tcp->keepalive));
       break;
     }  /* switch */
     break;