#include <linux/rtnetlink.h>
#include <arpa/inet.h>
#include <netinet/in.h>
-#include <wifi.h>
#include <net_connection.h>
#include "caipinterface.h"
#include <coap/utlist.h>
#define TAG "OIC_CA_IP_MONITOR"
-
+#define MAX_INTERFACE_INFO_LENGTH (1024)
#define NETLINK_MESSAGE_LENGTH (4096)
#define IFC_LABEL_LOOP "lo"
#define IFC_ADDR_LOOP_IPV4 "127.0.0.1"
for (struct nlmsghdr *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 || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING)))
+ struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh);
+ if (!ifi)
{
continue;
}
- int ifiIndex = ifi->ifi_index;
+ if (RTM_DELADDR == nh->nlmsg_type)
+ {
+ CloseMulticastSocket();
+ }
+ int ifiIndex = ifi->ifi_index;
iflist = CAIPGetInterfaceInformation(ifiIndex);
-
if (!iflist)
{
OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
return NULL;
}
+ CreateMulticastSocket();
}
return iflist;
}
CAResult_t CAIPStartNetworkMonitor(CAIPAdapterStateChangeCallback callback,
CATransportAdapter_t adapter)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!g_adapterCallbackList)
{
- // Initialize Wifi service.
- if (WIFI_ERROR_NONE != wifi_initialize())
- {
- OIC_LOG(ERROR, TAG, "wifi_initialize failed");
- }
-
// Initialize Connections.
connection_error_e ret = connection_create(&connection);
if (CONNECTION_ERROR_NONE != ret)
}
}
+ OIC_LOG(DEBUG, TAG, "Initialize network monitoring successfully");
return CAIPSetNetworkMonitorCallback(callback, adapter);
}
CAIPUnSetNetworkMonitorCallback(adapter);
if (!g_adapterCallbackList)
{
- // Deinitialize Wifi service.
- if (WIFI_ERROR_NONE != wifi_deinitialize())
- {
- OIC_LOG(ERROR, TAG, "wifi_deinitialize failed");
- }
-
// Reset callback for receiving state changes.
if (connection)
{
}
}
+ OIC_LOG(DEBUG, TAG, "Network monitoring terminated successfully");
return CA_STATUS_OK;
}
void CAIPConnectionStateChangedCb(connection_type_e type, void* userData)
{
+ (void)userData;
+
switch (type)
{
case CONNECTION_TYPE_DISCONNECTED: