bool client; /**< client mode */
bool server; /**< server mode */
+ CAPorts_t ports;
+
struct sockets
{
- void *threadpool; /**< threadpool between Initialize and Start */
- CASocket_t u6; /**< unicast IPv6 */
- CASocket_t u6s; /**< unicast IPv6 secure */
- CASocket_t u4; /**< unicast IPv4 */
- CASocket_t u4s; /**< unicast IPv4 secure */
- CASocket_t m6; /**< multicast IPv6 */
- CASocket_t m6s; /**< multicast IPv6 secure */
- CASocket_t m4; /**< multicast IPv4 */
- CASocket_t m4s; /**< multicast IPv4 secure */
- int netlinkFd; /**< netlink */
- int shutdownFds[2]; /**< shutdown pipe */
- int selectTimeout; /**< in seconds */
- int maxfd; /**< highest fd (for select) */
- bool started; /**< the IP adapter has started */
- bool terminate; /**< the IP adapter needs to stop */
- bool ipv6enabled; /**< IPv6 enabled by OCInit flags */
- bool ipv4enabled; /**< IPv4 enabled by OCInit flags */
- bool dualstack; /**< IPv6 and IPv4 enabled */
+ void *threadpool; /**< threadpool between Initialize and Start */
+ CASocket_t u6; /**< unicast IPv6 */
+ CASocket_t u6s; /**< unicast IPv6 secure */
+ CASocket_t u4; /**< unicast IPv4 */
+ CASocket_t u4s; /**< unicast IPv4 secure */
+ CASocket_t m6; /**< multicast IPv6 */
+ CASocket_t m6s; /**< multicast IPv6 secure */
+ CASocket_t m4; /**< multicast IPv4 */
+ CASocket_t m4s; /**< multicast IPv4 secure */
+ int netlinkFd; /**< netlink */
+#if defined(_WIN32)
+ WSAEVENT shutdownEvent; /**< Event used to signal threads to stop */
+#else
+ int shutdownFds[2]; /**< fds used to signal threads to stop */
+#endif
+ int selectTimeout; /**< in seconds */
+ int maxfd; /**< highest fd (for select) */
+ bool started; /**< the IP adapter has started */
+ bool terminate; /**< the IP adapter needs to stop */
+ bool ipv6enabled; /**< IPv6 enabled by OCInit flags */
+ bool ipv4enabled; /**< IPv4 enabled by OCInit flags */
+ bool dualstack; /**< IPv6 and IPv4 enabled */
+#if defined (_WIN32)
+ LPFN_WSARECVMSG wsaRecvMsg; /**< Win32 function pointer to WSARecvMsg() */
+#endif
struct networkmonitors
{
NULL
};
-static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL;
+#if defined (_WIN32)
+#define IFF_UP_RUNNING_FLAGS (IFF_UP)
+ char* caips_get_error(){
+ static char buffer[32];
+ snprintf(buffer, 32, "%i", WSAGetLastError());
+ return buffer;
+ }
+#define CAIPS_GET_ERROR \
+ caips_get_error()
+#else
+#define IFF_UP_RUNNING_FLAGS (IFF_UP|IFF_RUNNING)
+
+#define CAIPS_GET_ERROR \
+ strerror(errno)
+#endif
static CAIPErrorHandleCallback g_ipErrorHandler = NULL;
- static void CAHandleNetlink();
+static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL;
+
static void CAFindReadyMessage();
+#if !defined(WSA_WAIT_EVENT_0)
static void CASelectReturned(fd_set *readFds, int ret);
+#else
+static void CAEventReturned(HANDLE);
+#endif
static void CAProcessNewInterface(CAInterface_t *ifchanged);
static CAResult_t CAReceiveMessage(int fd, CATransportFlags_t flags);
{
int on = 1;
- if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
+ if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&on), sizeof (on)))
{
- OIC_LOG_V(ERROR, TAG, "IPV6_V6ONLY failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "IPV6_V6ONLY failed: %s", CAIPS_GET_ERROR);
}
- if (*port) // only do this for multicast ports
- if (isMulticast && *port) // only do this for multicast ports
++ if (isMulticast && *port) // only do this for multicast ports
{
+#if defined(IPV6_RECVPKTINFO)
if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof (on)))
+#else
+ if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, OPTVAL_T(&on), sizeof (on)))
+#endif
{
- OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s", strerror(errno));
+ OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s",CAIPS_GET_ERROR);
}
}
}
else
{
- if (*port) // only do this for multicast ports
- if (isMulticast && *port) // only do this for multicast ports
++ if (isMulticast && *port) // only do this for multicast ports
{
int on = 1;
- if (-1 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &on, sizeof (on)))
+ if (-1 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, OPTVAL_T(&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);
}
}
socklen = sizeof (struct sockaddr_in);
}
- if (*port) // use the given port
- if (isMulticast && *port) // use the given port
++ if (isMulticast && *port) // use the given port
{
int on = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on)))
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&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);
+#ifdef _WIN32
+ closesocket(fd);
+#else
close(fd);
+#endif
return -1;
}
}