Set socklen explicitly to make IOS happy
authorJohn Light <john.j.light@intel.com>
Thu, 30 Jul 2015 05:10:51 +0000 (22:10 -0700)
committerErich Keane <erich.keane@intel.com>
Thu, 6 Aug 2015 17:34:32 +0000 (17:34 +0000)
Change-Id: I61a30d0c81c0607d127277b53fa0bef7240e0551
Signed-off-by: John Light <john.j.light@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2127
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Sakari Poussa <sakari.poussa@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/connectivity/src/ip_adapter/caipserver.c

index 710d69d..5b33152 100644 (file)
@@ -290,6 +290,8 @@ static int CACreateSocket(int family, uint16_t *port)
     #endif
 
     struct sockaddr_storage sa = { .ss_family = family };
+    socklen_t socklen;
+
     if (family == AF_INET6)
     {
         int on = 1;
@@ -298,10 +300,12 @@ static int CACreateSocket(int family, uint16_t *port)
             OIC_LOG_V(ERROR, TAG, "IPV6_V6ONLY failed: %s", strerror(errno));
         }
         ((struct sockaddr_in6 *)&sa)->sin6_port = htons(*port);
+        socklen = sizeof (struct sockaddr_in6);
     }
     else
     {
         ((struct sockaddr_in *)&sa)->sin_port = htons(*port);
+        socklen = sizeof (struct sockaddr_in);
     }
 
     if (*port)  // use the given port
@@ -315,7 +319,7 @@ static int CACreateSocket(int family, uint16_t *port)
         }
     }
 
-    if (-1 == bind(fd, (struct sockaddr *)&sa, sizeof(sa)))
+    if (-1 == bind(fd, (struct sockaddr *)&sa, socklen))
     {
         OIC_LOG_V(ERROR, TAG, "bind socket failed: %s", strerror(errno));
         close(fd);
@@ -324,8 +328,6 @@ static int CACreateSocket(int family, uint16_t *port)
 
     if (!*port)  // return the assigned port
     {
-        struct sockaddr_storage sa;
-        socklen_t socklen = sizeof (sa);
         if (-1 == getsockname(fd, (struct sockaddr *)&sa, &socklen))
         {
             OIC_LOG_V(ERROR, TAG, "getsockname failed: %s", strerror(errno));