close(caglobals.ip.m4s.fd);
caglobals.ip.m4s.fd = -1;
}
+
+ if (caglobals.ip.netlinkFd != -1)
+ {
+ close(caglobals.ip.netlinkFd);
+ caglobals.ip.netlinkFd = -1;
+ }
}
static void CAReceiveHandler(void *data)
else ISSET(m4s, readFds, CA_MULTICAST | CA_IPV4 | CA_SECURE)
else if (FD_ISSET(caglobals.ip.netlinkFd, readFds))
{
- CAHandleNetlink();
+ CAInterface_t *ifchanged = CAFindInterfaceChange();
+ if (ifchanged)
+ {
+ CAProcessNewInterface(ifchanged);
+ OICFree(ifchanged);
+ }
break;
}
else if (FD_ISSET(caglobals.ip.shutdownFds[0], readFds))
{
continue;
}
-
- CAInterface_t *ifchanged = CAFindInterfaceChange();
- if (ifchanged)
- {
- CAProcessNewInterface(ifchanged);
- OICFree(ifchanged);
- }
break;
}
else
OIC_LOG(DEBUG, TAG, "ifitem is null");
return;
}
-
- applyMulticastToInterface6(ifitem->index);
- struct in_addr inaddr = { .s_addr = ifitem->ipv4addr };
- applyMulticastToInterface4(inaddr);
-}
-static void CAHandleNetlink()
-{
-#ifdef __linux__
- char buf[4096];
- struct nlmsghdr *nh;
- struct sockaddr_nl sa;
- struct iovec iov = { buf, sizeof (buf) };
- struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 };
-
- size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
-
- for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
+ if (ifitem->family == AF_INET6)
{
- if (nh != NULL && nh->nlmsg_type != RTM_NEWLINK)
- {
- continue;
- }
-
- struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh);
- if (!ifi || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING))
- {
- continue;
- }
-
- int newIndex = ifi->ifi_index;
-
- u_arraylist_t *iflist = CAIPGetInterfaceInformation(newIndex);
- if (!iflist)
- {
- OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
- return;
- }
-
- uint32_t listLength = u_arraylist_length(iflist);
- for (uint32_t i = 0; i < listLength; i++)
- {
- CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
- if (!ifitem)
- {
- continue;
- }
-
- if ((int)ifitem->index != newIndex)
- {
- continue;
- }
-
- CAProcessNewInterface(ifitem);
- break; // we found the one we were looking for
- }
- u_arraylist_destroy(iflist);
+ applyMulticastToInterface6(ifitem->index);
+ }
+ if (ifitem->family == AF_INET)
+ {
+ struct in_addr inaddr = { .s_addr = ifitem->ipv4addr };
+ applyMulticastToInterface4(inaddr);
}
-#endif // __linux__
}
void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback)
g_exceptionCallback = callback;
}
+void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback)
+{
+ CAIPSetNetworkMonitorCallback(callback);
+}
+
static void sendData(int fd, const CAEndpoint_t *endpoint,
const void *data, uint32_t dlen,
const char *cast, const char *fam)