#endif
#include <sys/types.h>
+#if !defined(__msys_nt__)
#include <sys/socket.h>
+#endif
+
+#if defined(__msys_nt__)
+#include <winsock2.h>
+#include <ws2def.h>
+#include <mswsock.h>
+#include <ws2tcpip.h>
+#endif
+
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
+#if !defined(__msys_nt__)
#include <sys/select.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <net/if.h>
+#endif
#include <errno.h>
#ifdef __linux__
#include <linux/netlink.h>
NULL
};
+#if defined (__msys_nt__)
+ char* _caips_get_error(){
+ static char buffer[32];
+ snprintf(buffer, 32, "%i", WSAGetLastError());
+ return buffer;
+ }
+ #define CAIPS_GET_ERROR \
+ _caips_get_error()
+#else
+ #define CAIPS_GET_ERROR \
+ strerror(errno)
+#endif
static CAIPExceptionCallback g_exceptionCallback;
static CAIPPacketReceivedCallback g_packetReceivedCallback;
SET(m6s, &readFds)
SET(m4, &readFds)
SET(m4s, &readFds)
+
+#if !defined(__msys_nt__)
if (caglobals.ip.shutdownFds[0] != -1)
{
FD_SET(caglobals.ip.shutdownFds[0], &readFds);
{
FD_SET(caglobals.ip.netlinkFd, &readFds);
}
-
+#endif
int ret = select(caglobals.ip.maxfd + 1, &readFds, NULL, NULL, tv);
if (caglobals.ip.terminate)
OIC_LOG_V(DEBUG, TAG, "Packet receiver Stop request received.");
return;
}
+
if (ret <= 0)
{
if (ret < 0)
{
- OIC_LOG_V(FATAL, TAG, "select error %s", strerror(errno));
+ OIC_LOG_V(FATAL, TAG, "select error %s", CAIPS_GET_ERROR);
}
return;
}
else ISSET(m6s, readFds, CA_MULTICAST | CA_IPV6 | CA_SECURE)
else ISSET(m4, readFds, CA_MULTICAST | CA_IPV4)
else ISSET(m4s, readFds, CA_MULTICAST | CA_IPV4 | CA_SECURE)
+#if !defined(__msys_nt__)
else if (FD_ISSET(caglobals.ip.netlinkFd, readFds))
{
CAInterface_t *ifchanged = CAFindInterfaceChange();
{
break;
}
-
+#else
+ else
+ {
+ break;
+ }
+#endif
(void)CAReceiveMessage(fd, flags);
FD_CLR(fd, readFds);
}
int level, type, namelen;
struct sockaddr_storage srcAddr;
unsigned char *pktinfo = NULL;
+#if !defined(__msys_nt__)
struct cmsghdr *cmp = NULL;
struct iovec iov = { recvBuffer, sizeof (recvBuffer) };
union control
}
}
}
+#else // if defined(__msys_nt__)
+#endif // !defined(__msys_nt__)
CASecureEndpoint_t sep = {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = flags}};
if (flags & CA_IPV6)
}
}
}
-
+#if !defined(__msys_nt__)
CAConvertAddrToName(&srcAddr, msg.msg_namelen, sep.endpoint.addr, &sep.endpoint.port);
+#else
+#endif
if (flags & CA_SECURE)
{
#ifdef __WITH_DTLS__
}
return CA_STATUS_OK;
+
+
}
void CAIPPullData()
static int CACreateSocket(int family, uint16_t *port)
{
+#if !defined(__msys_nt__)
int socktype = SOCK_DGRAM;
#ifdef SOCK_CLOEXEC
socktype |= SOCK_CLOEXEC;
return -1;
}
#endif
+#else // defined(__msys_nt__)
+#endif
struct sockaddr_storage sa = { .ss_family = family };
socklen_t socklen;
if (*port) // only do this for multicast ports
{
+#if !defined(__msys_nt__)
if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof (on)))
+#else
+
+#endif
{
- OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s",CAIPS_GET_ERROR);
}
}
int on = 1;
if (-1 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &on, sizeof (on)))
{
- OIC_LOG_V(ERROR, TAG, "IP_PKTINFO failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "IP_PKTINFO failed: %s", CAIPS_GET_ERROR);
}
}
int on = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on)))
{
- OIC_LOG_V(ERROR, TAG, "SO_REUSEADDR failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "SO_REUSEADDR failed: %s", CAIPS_GET_ERROR);
close(fd);
return -1;
}
if (-1 == bind(fd, (struct sockaddr *)&sa, socklen))
{
- OIC_LOG_V(ERROR, TAG, "bind socket failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "bind socket failed: %s", CAIPS_GET_ERROR);
close(fd);
return -1;
}
{
if (-1 == getsockname(fd, (struct sockaddr *)&sa, &socklen))
{
- OIC_LOG_V(ERROR, TAG, "getsockname failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "getsockname failed: %s", CAIPS_GET_ERROR);
close(fd);
return -1;
}
static void CAInitializePipe()
{
+#if !defined(__msys_nt__)
caglobals.ip.selectTimeout = -1;
#ifdef HAVE_PIPE2
int ret = pipe2(caglobals.ip.shutdownFds, O_CLOEXEC);
OIC_LOG_V(ERROR, TAG, "pipe failed: %s", strerror(errno));
caglobals.ip.selectTimeout = SELECT_TIMEOUT; //poll needed for shutdown
}
+#else
+ //msys stuff here
+#endif
}
CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
{
caglobals.ip.started = false;
caglobals.ip.terminate = true;
+#if !defined(__msys_nt__)
if (caglobals.ip.shutdownFds[1] != -1)
{
{
// receive thread will stop in SELECT_TIMEOUT seconds.
}
+#else
+ //msys stuff here
+#endif
}
void CAWakeUpForChange()
{
+#if !defined(__msys_nt__)
if (caglobals.ip.shutdownFds[1] != -1)
{
ssize_t len = 0;
OIC_LOG_V(DEBUG, TAG, "write failed: %s", strerror(errno));
}
}
+#else
+ //msys stuff here
+#endif
}
static void applyMulticastToInterface4(struct in_addr inaddr)
{
if (EADDRINUSE != errno)
{
- OIC_LOG_V(ERROR, TAG, "IPv4 IP_ADD_MEMBERSHIP failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "IPv4 IP_ADD_MEMBERSHIP failed: %s", CAIPS_GET_ERROR);
}
}
if (setsockopt(caglobals.ip.m4s.fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof (mreq)))
{
if (EADDRINUSE != errno)
{
- OIC_LOG_V(ERROR, TAG, "secure IPv4 IP_ADD_MEMBERSHIP failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "secure IPv4 IP_ADD_MEMBERSHIP failed: %s", CAIPS_GET_ERROR);
}
}
}
{
if (EADDRINUSE != errno)
{
- OIC_LOG_V(ERROR, TAG, "IPv6 IP_ADD_MEMBERSHIP failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "IPv6 IP_ADD_MEMBERSHIP failed: %s", CAIPS_GET_ERROR);
}
}
}
{
continue;
}
+#if !defined(__msys_nt__)
if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+#else
+ //IFF_RUNNING is not on msys or win32
+#endif
{
continue;
}
{
continue;
}
-
+#if !defined(__msys_nt__)
if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+#else
+ //IFF_RUNNING is not on msys or win32
+#endif
{
continue;
}
{
socklen = sizeof(struct sockaddr_in);
}
-
+#if !defined(__msys_nt__)
ssize_t len = sendto(fd, data, dlen, 0, (struct sockaddr *)&sock, socklen);
if (-1 == len)
{
// If logging is not defined/enabled.
- (void)cast;
- (void)fam;
+ (void)cast;
+ (void)fam;
OIC_LOG_V(ERROR, TAG, "%s%s %s sendTo failed: %s", secure, cast, fam, strerror(errno));
}
else
{
OIC_LOG_V(INFO, TAG, "%s%s %s sendTo is successful: %zd bytes", secure, cast, fam, len);
}
+#else
+
+#endif
}
static void sendMulticastData6(const u_arraylist_t *iflist,
{
continue;
}
+#if !defined(__msys_nt__)
if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+#else
+
+#endif
{
continue;
}
int index = ifitem->index;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &index, sizeof (index)))
{
- OIC_LOG_V(ERROR, TAG, "setsockopt6 failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "setsockopt6 failed: %s", CAIPS_GET_ERROR);
+
return;
}
sendData(fd, endpoint, data, datalen, "multicast", "ipv6");
{
continue;
}
+#if !defined(__msys_nt__)
if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+#else
+
+#endif
{
continue;
}
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &mreq, sizeof (mreq)))
{
OIC_LOG_V(ERROR, TAG, "send IP_MULTICAST_IF failed: %s (using defualt)",
- strerror(errno));
+ CAIPS_GET_ERROR);
}
sendData(fd, endpoint, data, datalen, "multicast", "ipv4");
}