From 7c2070bc830d326716ff4fabcbb74a1ea001f09f Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Sun, 2 Aug 2009 16:31:50 +0000
Subject: [PATCH] Fix accept() -- it wanted parts of return address initialized

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2008 42af7a65-404d-4744-a932-0658087f49c3
---
 TODO                       |  7 ++++++-
 net/accept.c               | 18 +++++++++++++-----
 netutils/thttpd/libhttpd.c |  4 ++--
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO
index 90bc128479..b129aea6d8 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated June 26, 2009)
+NuttX TODO List (Last updated August 3, 2009)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
   (5)  Task/Scheduler (sched/)
@@ -234,6 +234,11 @@ o Network (net/, netutils/)
   Status:      Open, depends on UDP read-ahead support
   Priority:    Medium
 
+  Description: sockets do not support any modes except for O_NONBLOCK (that
+               that is not implemented in a very general way at present)
+  Status:      Open
+  Priority:    Low.
+
 o USB (drivers/usbdev)
   ^^^^^^^^^^^^^^^^^^^^
 
diff --git a/net/accept.c b/net/accept.c
index c2e64153c6..81ac8dbfff 100644
--- a/net/accept.c
+++ b/net/accept.c
@@ -1,7 +1,7 @@
 /****************************************************************************
  * net/accept.c
  *
- *   Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -102,10 +102,17 @@ struct accept_s
 #ifdef CONFIG_NET_IPv6
 static inline void accept_tcpsender(FAR struct uip_conn *conn,
                                     FAR struct sockaddr_in6 *addr)
+{
+  if (addr)
+    {
+      addr->sin_family = AF_INET6;
+      addr->sin_port   = conn->rport;
+      uip_ipaddr_copy(addr->sin_addr.s_addr, conn->ripaddr);
+    }
+}
 #else
 static inline void accept_tcpsender(FAR struct uip_conn *conn,
                                     FAR struct sockaddr_in *addr)
-#endif
 {
   if (addr)
     {
@@ -114,7 +121,8 @@ static inline void accept_tcpsender(FAR struct uip_conn *conn,
       uip_ipaddr_copy(addr->sin_addr.s_addr, conn->ripaddr);
     }
 }
-#endif
+#endif /* CONFIG_NET_IPv6 */
+#endif /* CONFIG_NET_TCP */
 
 /****************************************************************************
  * Function: accept_interrupt
@@ -304,9 +312,9 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
   if (addr)
     {
 #ifdef CONFIG_NET_IPv6
-      if (addr->sa_family != AF_INET6 || *addrlen < sizeof(struct sockaddr_in6))
+      if (*addrlen < sizeof(struct sockaddr_in6))
 #else
-      if (addr->sa_family != AF_INET || *addrlen < sizeof(struct sockaddr_in))
+      if (*addrlen < sizeof(struct sockaddr_in))
 #endif
         {
           err = EBADF;
diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c
index ad5091c1b7..fa294f3925 100644
--- a/netutils/thttpd/libhttpd.c
+++ b/netutils/thttpd/libhttpd.c
@@ -3551,7 +3551,7 @@ char *httpd_method_str(int method)
     }
 }
 
-int httpd_get_conn(httpd_server * hs, int listen_fd, httpd_conn *hc)
+int httpd_get_conn(httpd_server *hs, int listen_fd, httpd_conn *hc)
 {
   httpd_sockaddr sa;
   socklen_t sz;
@@ -3596,7 +3596,7 @@ int httpd_get_conn(httpd_server * hs, int listen_fd, httpd_conn *hc)
           return GC_NO_MORE;
         }
 
-      ndbg("accept: %d\n", errno);
+      ndbg("accept failed: %d\n", errno);
       return GC_FAIL;
     }
 
-- 
GitLab