#include <linux/rtnetlink.h>
#endif
-#include "camutex.h"
+#include "octhread.h"
#include "caipnwmonitor.h"
#include "caadapterutils.h"
#include "logger.h"
/**
* Mutex for synchronizing access to cached interface and IP address information.
*/
-static ca_mutex g_networkMonitorContextMutex = NULL;
+static oc_mutex g_networkMonitorContextMutex = NULL;
/**
* Used to storing network interface.
{
if (!g_networkMonitorContextMutex)
{
- g_networkMonitorContextMutex = ca_mutex_new();
+ g_networkMonitorContextMutex = oc_mutex_new();
if (!g_networkMonitorContextMutex)
{
- OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
+ OIC_LOG(ERROR, TAG, "oc_mutex_new has failed");
return CA_STATUS_FAILED;
}
}
if (g_networkMonitorContextMutex)
{
- ca_mutex_free(g_networkMonitorContextMutex);
+ oc_mutex_free(g_networkMonitorContextMutex);
g_networkMonitorContextMutex = NULL;
}
}
return false;
}
- ca_mutex_lock(g_networkMonitorContextMutex);
+ oc_mutex_lock(g_networkMonitorContextMutex);
uint32_t list_length = u_arraylist_length(g_netInterfaceList);
for (uint32_t list_index = 0; list_index < list_length; list_index++)
list_index);
if (currItem->index == ifiindex)
{
- ca_mutex_unlock(g_networkMonitorContextMutex);
+ oc_mutex_unlock(g_networkMonitorContextMutex);
return true;
}
}
- ca_mutex_unlock(g_networkMonitorContextMutex);
+ oc_mutex_unlock(g_networkMonitorContextMutex);
return false;
}
VERIFY_NON_NULL(g_netInterfaceList, TAG, "g_netInterfaceList is NULL");
VERIFY_NON_NULL(ifitem, TAG, "ifitem is NULL");
- ca_mutex_lock(g_networkMonitorContextMutex);
+ oc_mutex_lock(g_networkMonitorContextMutex);
bool result = u_arraylist_add(g_netInterfaceList, (void *) ifitem);
if (!result)
{
OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
- ca_mutex_unlock(g_networkMonitorContextMutex);
+ oc_mutex_unlock(g_networkMonitorContextMutex);
return CA_STATUS_FAILED;
}
- ca_mutex_unlock(g_networkMonitorContextMutex);
+ oc_mutex_unlock(g_networkMonitorContextMutex);
return CA_STATUS_OK;
}
{
VERIFY_NON_NULL_VOID(g_netInterfaceList, TAG, "g_netInterfaceList is NULL");
- ca_mutex_lock(g_networkMonitorContextMutex);
+ oc_mutex_lock(g_networkMonitorContextMutex);
uint32_t list_length = u_arraylist_length(g_netInterfaceList);
for (uint32_t list_index = 0; list_index < list_length; list_index++)
if (u_arraylist_remove(g_netInterfaceList, list_index))
{
OICFree(removedifitem);
- ca_mutex_unlock(g_networkMonitorContextMutex);
+ oc_mutex_unlock(g_networkMonitorContextMutex);
return;
}
continue;
}
}
- ca_mutex_unlock(g_networkMonitorContextMutex);
+ oc_mutex_unlock(g_networkMonitorContextMutex);
return;
}
if (cbitem && cbitem->adapter)
{
cbitem->callback(cbitem->adapter, status);
+ CALogAdapterStateInfo(cbitem->adapter, status);
}
}
}
.msg_iov = &iov,
.msg_iovlen = 1 };
- size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
+ ssize_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
{
- if (nh != NULL && nh->nlmsg_type != RTM_NEWLINK)
+ if (nh != NULL && (nh->nlmsg_type != RTM_DELADDR && nh->nlmsg_type != RTM_NEWADDR))
{
continue;
}
- struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh);
- if (!ifi)
- {
- OIC_LOG_V(ERROR, TAG, "ifi is NULL");
- return NULL;
- }
-
- int ifiIndex = ifi->ifi_index;
-
- if ((ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING))
+ if (RTM_DELADDR == nh->nlmsg_type)
{
+ struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA (nh);
+ int ifiIndex = ifa->ifa_index;
bool isFound = CACmpNetworkList(ifiIndex);
if (isFound)
{
continue;
}
- iflist = CAIPGetInterfaceInformation(ifiIndex);
+ // Netlink message type is RTM_NEWADDR.
+ struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA (nh);
+ int ifiIndex = ifa->ifa_index;
+ iflist = CAIPGetInterfaceInformation(ifiIndex);
if (!iflist)
{
OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
OIC_LOG_V(DEBUG, TAG, "Added interface: %s (%d)", ifitem->name, ifitem->family);
}
}
+#ifndef __TIZENRT__
freeifaddrs(ifp);
+#endif
return iflist;
exit:
+#ifndef __TIZENRT__
freeifaddrs(ifp);
+#endif
u_arraylist_destroy(iflist);
return NULL;
}