void *data;
uint32_t dataLen;
bool isMulticast;
-} CAIPData;
+} CAIPData_t;
/**
* Queue handle for Send Data.
static void CAIPSendDataThread(void *threadData);
-static CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint,
- const void *data, uint32_t dataLength,
- bool isMulticast);
-void CAFreeIPData(CAIPData *ipData);
+static CAIPData_t *CACreateIPData(const CAEndpoint_t *remoteEndpoint,
+ const void *data, uint32_t dataLength,
+ bool isMulticast);
+
+void CAFreeIPData(CAIPData_t *ipData);
static void CADataDestroyer(void *data, uint32_t size);
CAResult_t CAStartIPDiscoveryServer()
{
- OIC_LOG(DEBUG, TAG, "IN");
return CAStartIPListeningServer();
}
static int32_t CAQueueIPData(bool isMulticast, const CAEndpoint_t *endpoint,
- const void *data, uint32_t dataLength)
+ const void *data, uint32_t dataLength)
{
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_RET(g_sendQueueHandle, TAG, "sendQueueHandle", -1);
// Create IPData to add to queue
- CAIPData *ipData = CACreateIPData(endpoint, data, dataLength, isMulticast);
+ CAIPData_t *ipData = CACreateIPData(endpoint, data, dataLength, isMulticast);
if (!ipData)
{
OIC_LOG(ERROR, TAG, "Failed to create ipData!");
return -1;
}
// Add message to send queue
- CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
+ CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData_t));
#endif // SINGLE_THREAD
{
OIC_LOG(DEBUG, TAG, "IN");
- CAIPData *ipData = (CAIPData *) threadData;
+ CAIPData_t *ipData = (CAIPData_t *) threadData;
if (!ipData)
{
OIC_LOG(DEBUG, TAG, "Invalid ip data!");
{
//Processing for sending unicast
#ifdef __WITH_DTLS__
- if (ipData->remoteEndpoint->flags & CA_SECURE)
+ if (ipData->remoteEndpoint && ipData->remoteEndpoint->flags & CA_SECURE)
{
OIC_LOG(DEBUG, TAG, "CAAdapterNetDtlsEncrypt called!");
CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
#ifndef SINGLE_THREAD
-CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLength, bool isMulticast)
+CAIPData_t *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
+ uint32_t dataLength, bool isMulticast)
{
VERIFY_NON_NULL_RET(data, TAG, "IPData is NULL", NULL);
- CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
+ CAIPData_t *ipData = (CAIPData_t *) OICMalloc(sizeof(*ipData));
if (!ipData)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed!");
return ipData;
}
-void CAFreeIPData(CAIPData *ipData)
+void CAFreeIPData(CAIPData_t *ipData)
{
VERIFY_NON_NULL_VOID(ipData, TAG, "ipData is NULL");
void CADataDestroyer(void *data, uint32_t size)
{
- if (size < sizeof(CAIPData))
+ if (size < sizeof(CAIPData_t))
{
OIC_LOG_V(ERROR, TAG, "Destroy data too small %p %d", data, size);
}
- CAIPData *etdata = (CAIPData *) data;
+ CAIPData_t *etdata = (CAIPData_t *) data;
CAFreeIPData(etdata);
}
#include "oic_malloc.h"
#include "oic_string.h"
-/**
- * @def TAG
- * @brief Logging tag for module name
+/*
+ * Logging tag for module name
*/
#define TAG "IP_SERVER"
static int CACreateSocket(int family, uint16_t *port)
{
int socktype = SOCK_DGRAM;
- #ifdef SOCK_CLOEXEC
+#ifdef SOCK_CLOEXEC
socktype |= SOCK_CLOEXEC;
- #endif
+#endif
int fd = socket(family, socktype, IPPROTO_UDP);
if (-1 == fd)
{
return -1;
}
- #ifndef SOCK_CLOEXEC
+#ifndef SOCK_CLOEXEC
int fl = fcntl(fd, F_GETFD);
if (-1 == fl || -1 == fcntl(fd, F_SETFD, fl|FD_CLOEXEC))
{
close(fd);
return -1;
}
- #endif
+#endif
struct sockaddr_storage sa = { .ss_family = family };
socklen_t socklen;
static void applyMulticast6(int fd, struct in6_addr *addr, uint32_t interface)
{
- struct ipv6_mreq mreq;
- mreq.ipv6mr_multiaddr = *addr;
- mreq.ipv6mr_interface = interface;
+ struct ipv6_mreq mreq = {.ipv6mr_multiaddr = *addr, .ipv6mr_interface = interface};
+
if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof (mreq)))
{
if (EADDRINUSE != errno)
static void CAProcessNewInterface(CAInterface_t *ifitem)
{
+ if (!ifitem)
+ {
+ OIC_LOG(DEBUG, TAG, "ifitem is null");
+ return;
+ }
+
applyMulticastToInterface6(ifitem->index);
- struct in_addr inaddr;
- inaddr.s_addr = ifitem->ipv4addr;
+ struct in_addr inaddr = { .s_addr = ifitem->ipv4addr };
applyMulticastToInterface4(inaddr);
}
static void CAHandleNetlink()
{
OIC_LOG(DEBUG, TAG, "IN");
+ if (!endpoint)
+ {
+ OIC_LOG(DEBUG, TAG, "endpoint is null");
+ return;
+ }
+
char *secure = (endpoint->flags & CA_SECURE) ? "secure " : "";
(void)secure; // eliminates release warning
struct sockaddr_storage sock;
CAEndpoint_t *endpoint,
const void *data, uint32_t datalen)
{
+ if (!endpoint)
+ {
+ OIC_LOG(DEBUG, TAG, "endpoint is null");
+ return;
+ }
+
int scope = endpoint->flags & CA_SCOPE_MASK;
char *ipv6mcname = ipv6mcnames[scope];
if (!ipv6mcname)
CAEndpoint_t *endpoint,
const void *data, uint32_t datalen)
{
+ VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL");
+
struct ip_mreqn mreq = { .imr_multiaddr = IPv4MulticastAddress,
.imr_ifindex = 0 };
OICStrcpy(endpoint->addr, sizeof(endpoint->addr), IPv4_MULTICAST);
}
void CAIPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen,
- bool isMulticast)
+ bool isMulticast)
{
VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL");
VERIFY_NON_NULL_VOID(data, TAG, "data is NULL");
if (caglobals.ip.ipv6enabled && (endpoint->flags & CA_IPV6))
{
fd = isSecure ? caglobals.ip.u6s.fd : caglobals.ip.u6.fd;
- #ifndef __WITH_DTLS__
+#ifndef __WITH_DTLS__
fd = caglobals.ip.u6.fd;
- #endif
+#endif
sendData(fd, endpoint, data, datalen, "unicast", "ipv6");
}
if (caglobals.ip.ipv4enabled && (endpoint->flags & CA_IPV4))
{
fd = isSecure ? caglobals.ip.u4s.fd : caglobals.ip.u4.fd;
- #ifndef __WITH_DTLS__
+#ifndef __WITH_DTLS__
fd = caglobals.ip.u4.fd;
- #endif
+#endif
sendData(fd, endpoint, data, datalen, "unicast", "ipv4");
}
}