From f420599ae8febfb4584ed57296aefc8ecfd95375 Mon Sep 17 00:00:00 2001 From: Sachin Agrawal Date: Tue, 4 Nov 2014 14:37:19 -0800 Subject: [PATCH] Fix wrong return value from OCInitUDP API Call to setsocketopt method was hiding the return value from bind method call (in case bind API fails). Modified code to use the return value from bind call for API return value. Change-Id: I7ab39b22444ba5db8a0b25524d4e5f9791c5ccf8 Signed-off-by: Sachin Agrawal --- csdk/ocsocket/src/ocsocket.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/csdk/ocsocket/src/ocsocket.c b/csdk/ocsocket/src/ocsocket.c index 68519fe..5fce889 100644 --- a/csdk/ocsocket/src/ocsocket.c +++ b/csdk/ocsocket/src/ocsocket.c @@ -189,24 +189,24 @@ int32_t OCInitUDP(OCDevAddr* ipAddr, int32_t *sockfd) goto exit; } - if ((ret = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char*) &set_option_on, - sizeof(set_option_on))) < 0) { - OC_LOG(FATAL, MOD_NAME, "setsockopt API failed"); + if (ret = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char*) &set_option_on, + sizeof(set_option_on)) < 0) { + OC_LOG_V(FATAL, MOD_NAME, "setsockopt API failed with errno %s", + strerror(errno)); goto exit; } - if (bind(sfd, (struct sockaddr*)ipAddr->addr, ipAddr->size) < 0) { + if (ret = bind(sfd, (struct sockaddr*)ipAddr->addr, ipAddr->size) < 0) { OC_LOG_V(FATAL, MOD_NAME, "bind API failed with errno %s", strerror(errno)); goto exit; } + *sockfd = sfd; ret = ERR_SUCCESS; exit: if ((ret != ERR_SUCCESS) && (sfd >= 0)) { close(sfd); - } else { - *sockfd = sfd; } OC_LOG_V(DEBUG, MOD_NAME, "%s End", __func__ ); -- 2.7.4