1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #ifndef __APPLE_USE_RFC_3542
22 #define __APPLE_USE_RFC_3542 // for PKTINFO
25 #define _GNU_SOURCE // for in6_pktinfo
28 #include <sys/types.h>
30 #include <sys/socket.h>
42 #if !defined(_MSC_VER)
44 #endif //!defined(_MSC_VER)
45 #include <sys/types.h>
48 #include <sys/select.h>
49 #include <arpa/inet.h>
50 #include <netinet/in.h>
55 #include <linux/netlink.h>
56 #include <linux/rtnetlink.h>
60 #include "caipinterface.h"
61 #include "caadapterutils.h"
63 #include "caadapternetdtls.h"
66 #include "oic_malloc.h"
67 #include "oic_string.h"
68 #include "platform_features.h"
76 * Logging tag for module name
78 #define TAG "OIC_CA_IP_SERVER"
80 #define SELECT_TIMEOUT 1 // select() seconds (and termination latency)
82 #define IPv4_MULTICAST "224.0.1.187"
83 static struct in_addr IPv4MulticastAddress = { 0 };
85 #define IPv6_DOMAINS 16
86 #define IPv6_MULTICAST_INT "ff01::fd"
87 static struct in6_addr IPv6MulticastAddressInt;
88 #define IPv6_MULTICAST_LNK "ff02::fd"
89 static struct in6_addr IPv6MulticastAddressLnk;
90 #define IPv6_MULTICAST_RLM "ff03::fd"
91 static struct in6_addr IPv6MulticastAddressRlm;
92 #define IPv6_MULTICAST_ADM "ff04::fd"
93 static struct in6_addr IPv6MulticastAddressAdm;
94 #define IPv6_MULTICAST_SIT "ff05::fd"
95 static struct in6_addr IPv6MulticastAddressSit;
96 #define IPv6_MULTICAST_ORG "ff08::fd"
97 static struct in6_addr IPv6MulticastAddressOrg;
98 #define IPv6_MULTICAST_GLB "ff0e::fd"
99 static struct in6_addr IPv6MulticastAddressGlb;
101 static char *ipv6mcnames[IPv6_DOMAINS] = {
121 #define IFF_UP_RUNNING_FLAGS (IFF_UP)
123 char* caips_get_error(){
124 static char buffer[32];
125 snprintf(buffer, 32, "%i", WSAGetLastError());
128 #define CAIPS_GET_ERROR \
131 #define IFF_UP_RUNNING_FLAGS (IFF_UP|IFF_RUNNING)
133 #define CAIPS_GET_ERROR \
136 static CAIPErrorHandleCallback g_ipErrorHandler = NULL;
138 static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL;
140 static void CAFindReadyMessage();
141 #if !defined(WSA_WAIT_EVENT_0)
142 static void CASelectReturned(fd_set *readFds, int ret);
144 static void CAEventReturned(CASocketFd_t socket);
146 static void CAProcessNewInterface(CAInterface_t *ifchanged);
147 static CAResult_t CAReceiveMessage(CASocketFd_t fd, CATransportFlags_t flags);
149 static void CAReceiveHandler(void *data)
153 while (!caglobals.ip.terminate)
155 CAFindReadyMessage();
159 #if !defined(WSA_WAIT_EVENT_0)
161 #define CLOSE_SOCKET(TYPE) \
162 if (caglobals.ip.TYPE.fd != OC_INVALID_SOCKET) \
164 close(caglobals.ip.TYPE.fd); \
165 caglobals.ip.TYPE.fd = OC_INVALID_SOCKET; \
168 #define SET(TYPE, FDS) \
169 if (caglobals.ip.TYPE.fd != OC_INVALID_SOCKET) \
171 FD_SET(caglobals.ip.TYPE.fd, FDS); \
174 #define ISSET(TYPE, FDS, FLAGS) \
175 if (caglobals.ip.TYPE.fd != OC_INVALID_SOCKET && FD_ISSET(caglobals.ip.TYPE.fd, FDS)) \
177 fd = caglobals.ip.TYPE.fd; \
182 static void CAFindReadyMessage()
185 struct timeval timeout;
187 timeout.tv_sec = caglobals.ip.selectTimeout;
189 struct timeval *tv = caglobals.ip.selectTimeout == -1 ? NULL : &timeout;
201 if (caglobals.ip.shutdownFds[0] != -1)
203 FD_SET(caglobals.ip.shutdownFds[0], &readFds);
205 if (caglobals.ip.netlinkFd != OC_INVALID_SOCKET)
207 FD_SET(caglobals.ip.netlinkFd, &readFds);
210 int ret = select(caglobals.ip.maxfd + 1, &readFds, NULL, NULL, tv);
212 if (caglobals.ip.terminate)
214 OIC_LOG_V(DEBUG, TAG, "Packet receiver Stop request received.");
222 OIC_LOG_V(FATAL, TAG, "select error %s", CAIPS_GET_ERROR);
227 CASelectReturned(&readFds, ret);
230 static void CASelectReturned(fd_set *readFds, int ret)
233 CASocketFd_t fd = OC_INVALID_SOCKET;
234 CATransportFlags_t flags = CA_DEFAULT_FLAGS;
236 while (!caglobals.ip.terminate)
238 ISSET(u6, readFds, CA_IPV6)
239 else ISSET(u6s, readFds, CA_IPV6 | CA_SECURE)
240 else ISSET(u4, readFds, CA_IPV4)
241 else ISSET(u4s, readFds, CA_IPV4 | CA_SECURE)
242 else ISSET(m6, readFds, CA_MULTICAST | CA_IPV6)
243 else ISSET(m6s, readFds, CA_MULTICAST | CA_IPV6 | CA_SECURE)
244 else ISSET(m4, readFds, CA_MULTICAST | CA_IPV4)
245 else ISSET(m4s, readFds, CA_MULTICAST | CA_IPV4 | CA_SECURE)
246 else if ((caglobals.ip.netlinkFd != OC_INVALID_SOCKET) && FD_ISSET(caglobals.ip.netlinkFd, readFds))
248 CAInterface_t *ifchanged = CAFindInterfaceChange();
251 CAProcessNewInterface(ifchanged);
256 else if (FD_ISSET(caglobals.ip.shutdownFds[0], readFds))
259 ssize_t len = read(caglobals.ip.shutdownFds[0], buf, sizeof (buf));
270 (void)CAReceiveMessage(fd, flags);
275 #else // if defined(WSA_WAIT_EVENT_0)
277 #define CLOSE_SOCKET(TYPE) \
278 if (caglobals.ip.TYPE.fd != OC_INVALID_SOCKET) \
280 closesocket(caglobals.ip.TYPE.fd); \
281 caglobals.ip.TYPE.fd = OC_INVALID_SOCKET; \
284 #define PUSH_HANDLE(HANDLE, ARRAY, INDEX) \
286 ARRAY[INDEX] = HANDLE; \
290 // Turn handle into WSAEvent and push to ARRAY
291 #define PUSH_SOCKET(SOCKET, ARRAY, INDEX) \
292 if (SOCKET != OC_INVALID_SOCKET) \
295 NewEvent = WSACreateEvent(); \
296 if (WSA_INVALID_EVENT != NewEvent) \
298 if (0 != WSAEventSelect(SOCKET, NewEvent, FD_READ)) \
300 OIC_LOG_V(ERROR, TAG, "WSAEventSelect failed 0x%08x ", WSAGetLastError()); \
301 if (!WSACloseEvent(NewEvent)) \
303 OIC_LOG_V(ERROR, TAG, "WSACloseEvent(NewEvent) failed 0x%08x", WSAGetLastError()); \
308 PUSH_HANDLE(NewEvent, ARRAY, INDEX); \
313 OIC_LOG_V(ERROR, TAG, "WSACreateEvent(NewEvent) failed 0x%08x", WSAGetLastError()); \
317 #define INSERT_SOCKET(FD, ARRAY, INDEX) \
319 if (OC_INVALID_SOCKET != FD) \
326 // Inserts the socket into the SOCKET_ARRAY and pushes the socket event into EVENT_ARRAY
327 #define PUSH_IP_SOCKET(TYPE, EVENT_ARRAY, SOCKET_ARRAY, INDEX) \
329 if (OC_INVALID_SOCKET != caglobals.ip.TYPE.fd) \
331 INSERT_SOCKET(caglobals.ip.TYPE.fd, SOCKET_ARRAY, INDEX); \
332 PUSH_SOCKET(caglobals.ip.TYPE.fd, EVENT_ARRAY, INDEX); \
336 #define IS_MATCHING_IP_SOCKET(TYPE, SOCKET, FLAGS) \
337 if ((caglobals.ip.TYPE.fd != OC_INVALID_SOCKET) && (caglobals.ip.TYPE.fd == SOCKET)) \
339 fd = caglobals.ip.TYPE.fd; \
343 #define EVENT_ARRAY_SIZE 10
345 static void CAFindReadyMessage()
347 CASocketFd_t socketArray[EVENT_ARRAY_SIZE];
348 HANDLE eventArray[EVENT_ARRAY_SIZE];
352 // socketArray and eventArray should have same number of elements
353 OC_STATIC_ASSERT(_countof(socketArray) == _countof(eventArray), "Arrays should have same number of elements");
355 PUSH_IP_SOCKET(u6, eventArray, socketArray, arraySize);
356 PUSH_IP_SOCKET(u6s, eventArray, socketArray, arraySize);
357 PUSH_IP_SOCKET(u4, eventArray, socketArray, arraySize);
358 PUSH_IP_SOCKET(u4s, eventArray, socketArray, arraySize);
359 PUSH_IP_SOCKET(m6, eventArray, socketArray, arraySize);
360 PUSH_IP_SOCKET(m6s, eventArray, socketArray, arraySize);
361 PUSH_IP_SOCKET(m4, eventArray, socketArray, arraySize);
362 PUSH_IP_SOCKET(m4s, eventArray, socketArray, arraySize);
364 if (-1 != caglobals.ip.shutdownEvent)
366 INSERT_SOCKET(OC_INVALID_SOCKET, socketArray, arraySize);
367 PUSH_HANDLE(caglobals.ip.shutdownEvent, eventArray, arraySize);
370 /** @todo Support netlink events */
372 // Should not have overflowed buffer
373 assert(arraySize <= (_countof(socketArray)));
375 // Timeout is unnecessary on Windows
376 assert(-1 == caglobals.ip.selectTimeout);
378 while (!caglobals.ip.terminate)
380 int ret = WSAWaitForMultipleEvents(arraySize, eventArray, FALSE, WSA_INFINITE, FALSE);
384 case WSA_WAIT_FAILED:
385 OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents returned WSA_WAIT_FAILED 0x%08x", WSAGetLastError());
387 case WSA_WAIT_IO_COMPLETION:
388 OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents returned WSA_WAIT_IO_COMPLETION 0x%08x", WSAGetLastError());
390 case WSA_WAIT_TIMEOUT:
391 OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents returned WSA_WAIT_TIMEOUT 0x%08x", WSAGetLastError());
394 eventIndex = ret - WSA_WAIT_EVENT_0;
395 if ((eventIndex >= 0) && (eventIndex < arraySize))
397 if (false == WSAResetEvent(eventArray[eventIndex]))
399 OIC_LOG_V(ERROR, TAG, "WSAResetEvent failed 0x%08x", WSAGetLastError());
402 // Break out if shutdownEvent is triggered
403 if ((caglobals.ip.shutdownEvent != -1) &&
404 (caglobals.ip.shutdownEvent == eventArray[eventIndex]))
408 CAEventReturned(socketArray[eventIndex]);
412 OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents failed 0x%08x", WSAGetLastError());
419 while (arraySize > 0)
422 if (!WSACloseEvent(eventArray[arraySize]))
424 OIC_LOG_V(ERROR, TAG, "WSACloseEvent (Index %i) failed 0x%08x", arraySize, WSAGetLastError());
428 if (caglobals.ip.terminate)
430 caglobals.ip.shutdownEvent = -1;
435 static void CAEventReturned(CASocketFd_t socket)
437 CASocketFd_t fd = OC_INVALID_SOCKET;
438 CATransportFlags_t flags = CA_DEFAULT_FLAGS;
440 while (!caglobals.ip.terminate)
442 IS_MATCHING_IP_SOCKET(u6, socket, CA_IPV6)
443 else IS_MATCHING_IP_SOCKET(u6s, socket, CA_IPV6 | CA_SECURE)
444 else IS_MATCHING_IP_SOCKET(u4, socket, CA_IPV4)
445 else IS_MATCHING_IP_SOCKET(u4s, socket, CA_IPV4 | CA_SECURE)
446 else IS_MATCHING_IP_SOCKET(m6, socket, CA_MULTICAST | CA_IPV6)
447 else IS_MATCHING_IP_SOCKET(m6s, socket, CA_MULTICAST | CA_IPV6 | CA_SECURE)
448 else IS_MATCHING_IP_SOCKET(m4, socket, CA_MULTICAST | CA_IPV4)
449 else IS_MATCHING_IP_SOCKET(m4s, socket, CA_MULTICAST | CA_IPV4 | CA_SECURE)
454 (void)CAReceiveMessage(socket, flags);
455 // We will never get more than one match per socket, so always break.
462 void CADeInitializeIPGlobals()
473 if (caglobals.ip.netlinkFd != OC_INVALID_SOCKET)
476 closesocket(caglobals.ip.netlinkFd);
478 close(caglobals.ip.netlinkFd);
480 caglobals.ip.netlinkFd = OC_INVALID_SOCKET;
484 static CAResult_t CAReceiveMessage(CASocketFd_t fd, CATransportFlags_t flags)
486 char recvBuffer[COAP_MAX_PDU_SIZE];
489 int level, type, namelen;
490 struct sockaddr_storage srcAddr;
491 unsigned char *pktinfo = NULL;
492 #if !defined(WSA_CMSG_DATA)
493 struct cmsghdr *cmp = NULL;
494 struct iovec iov = { .iov_base = recvBuffer, .iov_len = sizeof (recvBuffer) };
498 unsigned char data[CMSG_SPACE(sizeof (struct in6_pktinfo))];
503 namelen = sizeof (struct sockaddr_in6);
504 level = IPPROTO_IPV6;
506 len = sizeof (struct in6_pktinfo);
510 namelen = sizeof (struct sockaddr_in);
513 len = sizeof (struct in6_pktinfo);
516 struct msghdr msg = { .msg_name = &srcAddr,
517 .msg_namelen = namelen,
520 .msg_control = &cmsg,
521 .msg_controllen = CMSG_SPACE(len) };
523 ssize_t recvLen = recvmsg(fd, &msg, flags);
524 if (OC_SOCKET_ERROR == recvLen)
526 OIC_LOG_V(ERROR, TAG, "Recvfrom failed %s", strerror(errno));
527 return CA_STATUS_FAILED;
530 if (flags & CA_MULTICAST)
532 for (cmp = CMSG_FIRSTHDR(&msg); cmp != NULL; cmp = CMSG_NXTHDR(&msg, cmp))
534 if (cmp->cmsg_level == level && cmp->cmsg_type == type)
536 pktinfo = CMSG_DATA(cmp);
540 #else // if defined(WSA_CMSG_DATA)
544 uint8_t data[WSA_CMSG_SPACE(sizeof (IN6_PKTINFO))];
546 memset(&cmsg, 0, sizeof(cmsg));
550 namelen = sizeof (struct sockaddr_in6);
551 level = IPPROTO_IPV6;
556 namelen = sizeof (struct sockaddr_in);
561 WSABUF iov = {.len = sizeof (recvBuffer), .buf = recvBuffer};
562 WSAMSG msg = {.name = &srcAddr,
566 .Control = {.buf = cmsg.data, .len = sizeof (cmsg)}
569 uint32_t recvLen = 0;
570 uint32_t ret = caglobals.ip.wsaRecvMsg(fd, &msg, &recvLen, 0,0);
571 OIC_LOG_V(DEBUG, TAG, "WSARecvMsg recvd %u bytes", recvLen);
572 if (OC_SOCKET_ERROR == ret)
574 OIC_LOG_V(ERROR, TAG, "WSARecvMsg failed %i", WSAGetLastError());
577 if (flags & CA_MULTICAST)
579 for (WSACMSGHDR *cmp = WSA_CMSG_FIRSTHDR(&msg); cmp != NULL;
580 cmp = WSA_CMSG_NXTHDR(&msg, cmp))
582 if (cmp->cmsg_level == level && cmp->cmsg_type == type)
584 pktinfo = WSA_CMSG_DATA(cmp);
588 #endif // !defined(WSA_CMSG_DATA)
589 CASecureEndpoint_t sep = {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = flags}};
593 /** @todo figure out correct usage for ifindex, and sin6_scope_id.*/
594 if ((flags & CA_MULTICAST) && pktinfo)
596 struct in6_addr *addr = &(((struct in6_pktinfo *)pktinfo)->ipi6_addr);
597 unsigned char topbits = ((unsigned char *)addr)[0];
600 sep.endpoint.flags &= ~CA_MULTICAST;
606 if ((flags & CA_MULTICAST) && pktinfo)
608 struct in_addr *addr = &((struct in_pktinfo *)pktinfo)->ipi_addr;
609 uint32_t host = ntohl(addr->s_addr);
610 unsigned char topbits = ((unsigned char *)&host)[3];
611 if (topbits < 224 || topbits > 239)
613 sep.endpoint.flags &= ~CA_MULTICAST;
618 CAConvertAddrToName(&srcAddr, namelen, sep.endpoint.addr, &sep.endpoint.port);
620 if (flags & CA_SECURE)
623 int ret = CAAdapterNetDtlsDecrypt(&sep, (uint8_t *)recvBuffer, recvLen);
624 OIC_LOG_V(DEBUG, TAG, "CAAdapterNetDtlsDecrypt returns [%d]", ret);
626 OIC_LOG(ERROR, TAG, "Encrypted message but no DTLS");
631 if (g_packetReceivedCallback)
633 g_packetReceivedCallback(&sep, recvBuffer, recvLen);
643 OIC_LOG(DEBUG, TAG, "IN");
644 OIC_LOG(DEBUG, TAG, "OUT");
647 static CASocketFd_t CACreateSocket(int family, uint16_t *port, bool isMulticast)
649 int socktype = SOCK_DGRAM;
651 socktype |= SOCK_CLOEXEC;
653 CASocketFd_t fd = socket(family, socktype, IPPROTO_UDP);
654 if (OC_INVALID_SOCKET == fd)
656 OIC_LOG_V(ERROR, TAG, "create socket failed: %s", CAIPS_GET_ERROR);
657 return OC_INVALID_SOCKET;
660 #if !defined(SOCK_CLOEXEC) && defined(FD_CLOEXEC)
661 int fl = fcntl(fd, F_GETFD);
662 if (-1 == fl || -1 == fcntl(fd, F_SETFD, fl|FD_CLOEXEC))
664 OIC_LOG_V(ERROR, TAG, "set FD_CLOEXEC failed: %s", strerror(errno));
666 return OC_INVALID_SOCKET;
669 struct sockaddr_storage sa = { .ss_family = family };
672 if (family == AF_INET6)
676 if (OC_SOCKET_ERROR == setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&on), sizeof (on)))
678 OIC_LOG_V(ERROR, TAG, "IPV6_V6ONLY failed: %s", CAIPS_GET_ERROR);
681 if (isMulticast && *port) // only do this for multicast ports
683 #if defined(IPV6_RECVPKTINFO)
684 if (OC_SOCKET_ERROR == setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof (on)))
686 if (OC_SOCKET_ERROR == setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, OPTVAL_T(&on), sizeof (on)))
689 OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s",CAIPS_GET_ERROR);
693 ((struct sockaddr_in6 *)&sa)->sin6_port = htons(*port);
694 socklen = sizeof (struct sockaddr_in6);
698 if (isMulticast && *port) // only do this for multicast ports
701 if (OC_SOCKET_ERROR == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, OPTVAL_T(&on), sizeof (on)))
703 OIC_LOG_V(ERROR, TAG, "IP_PKTINFO failed: %s", CAIPS_GET_ERROR);
707 ((struct sockaddr_in *)&sa)->sin_port = htons(*port);
708 socklen = sizeof (struct sockaddr_in);
711 if (isMulticast && *port) // use the given port
714 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on), sizeof (on)))
716 OIC_LOG_V(ERROR, TAG, "SO_REUSEADDR failed: %s", CAIPS_GET_ERROR);
722 return OC_INVALID_SOCKET;
726 if (OC_SOCKET_ERROR == bind(fd, (struct sockaddr *)&sa, socklen))
728 OIC_LOG_V(ERROR, TAG, "bind socket failed: %s", CAIPS_GET_ERROR);
734 return OC_INVALID_SOCKET;
737 if (!*port) // return the assigned port
739 if (OC_SOCKET_ERROR == getsockname(fd, (struct sockaddr *)&sa, &socklen))
741 OIC_LOG_V(ERROR, TAG, "getsockname failed: %s", CAIPS_GET_ERROR);
747 return OC_INVALID_SOCKET;
749 *port = ntohs(family == AF_INET6 ?
750 ((struct sockaddr_in6 *)&sa)->sin6_port :
751 ((struct sockaddr_in *)&sa)->sin_port);
757 #define CHECKFD(FD) \
758 if (FD > caglobals.ip.maxfd) \
759 caglobals.ip.maxfd = FD;
760 #define NEWSOCKET(FAMILY, NAME, MULTICAST) \
761 caglobals.ip.NAME.fd = CACreateSocket(FAMILY, &caglobals.ip.NAME.port, MULTICAST); \
762 if (caglobals.ip.NAME.fd == OC_INVALID_SOCKET) \
764 caglobals.ip.NAME.port = 0; \
765 caglobals.ip.NAME.fd = CACreateSocket(FAMILY, &caglobals.ip.NAME.port, MULTICAST); \
767 CHECKFD(caglobals.ip.NAME.fd)
769 static void CAInitializeNetlink()
771 caglobals.ip.netlinkFd = OC_INVALID_SOCKET;
773 // create NETLINK fd for interface change notifications
774 struct sockaddr_nl sa = { AF_NETLINK, 0, 0, RTMGRP_LINK };
776 caglobals.ip.netlinkFd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE);
777 if (caglobals.ip.netlinkFd == OC_INVALID_SOCKET)
779 OIC_LOG_V(ERROR, TAG, "netlink socket failed: %s", strerror(errno));
783 int r = bind(caglobals.ip.netlinkFd, (struct sockaddr *)&sa, sizeof (sa));
786 OIC_LOG_V(ERROR, TAG, "netlink bind failed: %s", strerror(errno));
787 close(caglobals.ip.netlinkFd);
788 caglobals.ip.netlinkFd = OC_INVALID_SOCKET;
792 CHECKFD(caglobals.ip.netlinkFd);
798 static void CAInitializeFastShutdownMechanism()
800 caglobals.ip.selectTimeout = -1; // don't poll for shutdown
802 #if defined(WSA_WAIT_EVENT_0)
803 caglobals.ip.shutdownEvent = -1;
804 caglobals.ip.shutdownEvent = WSACreateEvent();
806 if (caglobals.ip.shutdownEvent == WSA_INVALID_EVENT)
808 caglobals.ip.shutdownEvent = -1;
814 #elif defined(HAVE_PIPE2)
815 ret = pipe2(caglobals.ip.shutdownFds, O_CLOEXEC);
816 CHECKFD(caglobals.ip.shutdownFds[0]);
817 CHECKFD(caglobals.ip.shutdownFds[1]);
819 ret = pipe(caglobals.ip.shutdownFds);
822 ret = fcntl(caglobals.ip.shutdownFds[0], F_GETFD);
825 ret = fcntl(caglobals.ip.shutdownFds[0], F_SETFD, ret|FD_CLOEXEC);
829 ret = fcntl(caglobals.ip.shutdownFds[1], F_GETFD);
833 ret = fcntl(caglobals.ip.shutdownFds[1], F_SETFD, ret|FD_CLOEXEC);
837 close(caglobals.ip.shutdownFds[1]);
838 close(caglobals.ip.shutdownFds[0]);
839 caglobals.ip.shutdownFds[0] = -1;
840 caglobals.ip.shutdownFds[1] = -1;
843 CHECKFD(caglobals.ip.shutdownFds[0]);
844 CHECKFD(caglobals.ip.shutdownFds[1]);
848 OIC_LOG_V(ERROR, TAG, "fast shutdown mechanism init failed: %s", CAIPS_GET_ERROR);
849 caglobals.ip.selectTimeout = SELECT_TIMEOUT; //poll needed for shutdown
853 CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
855 CAResult_t res = CA_STATUS_OK;
857 if (caglobals.ip.started)
862 WORD wVersionRequested = MAKEWORD(2, 2);
863 WSADATA wsaData ={.wVersion = 0};
864 int err = WSAStartup(wVersionRequested, &wsaData);
867 OIC_LOG_V(ERROR, TAG, "WSAStartup failed: %i", err);
868 return CA_STATUS_FAILED;
870 OIC_LOG(DEBUG, TAG, "WSAStartup Succeeded");
872 if (!IPv4MulticastAddress.s_addr)
874 (void)inet_pton(AF_INET, IPv4_MULTICAST, &IPv4MulticastAddress);
875 (void)inet_pton(AF_INET6, IPv6_MULTICAST_INT, &IPv6MulticastAddressInt);
876 (void)inet_pton(AF_INET6, IPv6_MULTICAST_LNK, &IPv6MulticastAddressLnk);
877 (void)inet_pton(AF_INET6, IPv6_MULTICAST_RLM, &IPv6MulticastAddressRlm);
878 (void)inet_pton(AF_INET6, IPv6_MULTICAST_ADM, &IPv6MulticastAddressAdm);
879 (void)inet_pton(AF_INET6, IPv6_MULTICAST_SIT, &IPv6MulticastAddressSit);
880 (void)inet_pton(AF_INET6, IPv6_MULTICAST_ORG, &IPv6MulticastAddressOrg);
881 (void)inet_pton(AF_INET6, IPv6_MULTICAST_GLB, &IPv6MulticastAddressGlb);
884 if (!caglobals.ip.ipv6enabled && !caglobals.ip.ipv4enabled)
886 caglobals.ip.ipv4enabled = true; // only needed to run CA tests
889 if (caglobals.ip.ipv6enabled)
891 NEWSOCKET(AF_INET6, u6, false)
892 NEWSOCKET(AF_INET6, u6s, false)
893 NEWSOCKET(AF_INET6, m6, true)
894 NEWSOCKET(AF_INET6, m6s, true)
895 OIC_LOG_V(INFO, TAG, "IPv6 unicast port: %u", caglobals.ip.u6.port);
897 if (caglobals.ip.ipv4enabled)
899 NEWSOCKET(AF_INET, u4, false)
900 NEWSOCKET(AF_INET, u4s, false)
901 NEWSOCKET(AF_INET, m4, true)
902 NEWSOCKET(AF_INET, m4s, true)
903 OIC_LOG_V(INFO, TAG, "IPv4 unicast port: %u", caglobals.ip.u4.port);
906 OIC_LOG_V(DEBUG, TAG,
907 "socket summary: u6=%d, u6s=%d, u4=%d, u4s=%d, m6=%d, m6s=%d, m4=%d, m4s=%d",
908 caglobals.ip.u6.fd, caglobals.ip.u6s.fd, caglobals.ip.u4.fd, caglobals.ip.u4s.fd,
909 caglobals.ip.m6.fd, caglobals.ip.m6s.fd, caglobals.ip.m4.fd, caglobals.ip.m4s.fd);
911 OIC_LOG_V(DEBUG, TAG,
912 "port summary: u6 port=%d, u6s port=%d, u4 port=%d, u4s port=%d, m6 port=%d,"
913 "m6s port=%d, m4 port=%d, m4s port=%d",
914 caglobals.ip.u6.port, caglobals.ip.u6s.port, caglobals.ip.u4.port,
915 caglobals.ip.u4s.port, caglobals.ip.m6.port, caglobals.ip.m6s.port,
916 caglobals.ip.m4.port, caglobals.ip.m4s.port);
917 #if defined (SIO_GET_EXTENSION_FUNCTION_POINTER)
918 caglobals.ip.wsaRecvMsg = NULL;
919 GUID GuidWSARecvMsg = WSAID_WSARECVMSG;
921 err = WSAIoctl(caglobals.ip.u4.fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidWSARecvMsg, sizeof(GuidWSARecvMsg), &(caglobals.ip.wsaRecvMsg), sizeof(caglobals.ip.wsaRecvMsg), &copied, 0, 0);
924 OIC_LOG_V(ERROR, TAG, "WSAIoctl failed %i", WSAGetLastError());
925 return CA_STATUS_FAILED;
928 // set up appropriate FD mechanism for fast shutdown
929 CAInitializeFastShutdownMechanism();
931 // create source of network interface change notifications
932 CAInitializeNetlink();
934 caglobals.ip.selectTimeout = CAGetPollingInterval(caglobals.ip.selectTimeout);
936 res = CAIPStartListenServer();
937 if (CA_STATUS_OK != res)
939 OIC_LOG_V(ERROR, TAG, "Failed to start listening server![%d]", res);
943 caglobals.ip.terminate = false;
944 res = ca_thread_pool_add_task(threadPool, CAReceiveHandler, NULL);
945 if (CA_STATUS_OK != res)
947 OIC_LOG(ERROR, TAG, "thread_pool_add_task failed");
950 OIC_LOG(DEBUG, TAG, "CAReceiveHandler thread started successfully.");
952 caglobals.ip.started = true;
956 void CAIPStopServer()
958 caglobals.ip.started = false;
959 caglobals.ip.terminate = true;
961 #if !defined(WSA_WAIT_EVENT_0)
962 if (caglobals.ip.shutdownFds[1] != -1)
964 close(caglobals.ip.shutdownFds[1]);
965 // receive thread will stop immediately
969 // receive thread will stop in SELECT_TIMEOUT seconds.
972 // receive thread will stop immediately.
973 if (!WSASetEvent(caglobals.ip.shutdownEvent))
975 OIC_LOG_V(DEBUG, TAG, "set shutdown event failed: %#08X", GetLastError());
980 void CAWakeUpForChange()
982 #if !defined(WSA_WAIT_EVENT_0)
983 if (caglobals.ip.shutdownFds[1] != -1)
988 len = write(caglobals.ip.shutdownFds[1], "w", 1);
989 } while ((len == -1) && (errno == EINTR));
990 if ((len == -1) && (errno != EINTR) && (errno != EPIPE))
992 OIC_LOG_V(DEBUG, TAG, "write failed: %s", strerror(errno));
996 if (!WSASetEvent(caglobals.ip.shutdownEvent))
998 OIC_LOG_V(DEBUG, TAG, "set shutdown event failed: %#08X", GetLastError());
1003 static void applyMulticastToInterface4(uint32_t ifindex)
1005 if (!caglobals.ip.ipv4enabled)
1010 #if defined(USE_IP_MREQN)
1011 struct ip_mreqn mreq = { .imr_multiaddr = IPv4MulticastAddress,
1012 .imr_address.s_addr = htonl(INADDR_ANY),
1013 .imr_ifindex = ifindex };
1015 struct ip_mreq mreq = { .imr_multiaddr = IPv4MulticastAddress,
1016 .imr_interface.s_addr = htonl(ifindex) };
1019 int ret = setsockopt(caglobals.ip.m4.fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, OPTVAL_T(&mreq), sizeof (mreq));
1020 if (OC_SOCKET_ERROR == ret)
1022 #if !defined(WSAEINVAL)
1023 if (EADDRINUSE != errno)
1025 if (WSAEINVAL != WSAGetLastError()) // Joining multicast group more than once (IPv4 Flavor)
1028 OIC_LOG_V(ERROR, TAG, " IPv4 IP_ADD_MEMBERSHIP failed: %s", CAIPS_GET_ERROR);
1031 ret = setsockopt(caglobals.ip.m4s.fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, OPTVAL_T(&mreq), sizeof (mreq));
1032 if (OC_SOCKET_ERROR == ret)
1034 #if !defined(WSAEINVAL)
1035 if (EADDRINUSE != errno)
1037 if (WSAEINVAL != WSAGetLastError()) // Joining multicast group more than once (IPv4 Flavor)
1040 OIC_LOG_V(ERROR, TAG, "SECURE IPv4 IP_ADD_MEMBERSHIP failed: %s", CAIPS_GET_ERROR);
1045 static void applyMulticast6(int fd, struct in6_addr *addr, uint32_t ifindex)
1047 struct ipv6_mreq mreq = {.ipv6mr_multiaddr = *addr,
1048 .ipv6mr_interface = ifindex };
1049 int ret = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, OPTVAL_T(&mreq), sizeof (mreq));
1050 if (OC_SOCKET_ERROR == ret)
1052 #if !defined(_WIN32)
1053 if (EADDRINUSE != errno)
1055 if (WSAEINVAL != WSAGetLastError()) // Joining multicast group more than once (IPv6 Flavor)
1058 OIC_LOG_V(ERROR, TAG, "IPv6 IPV6_JOIN_GROUP failed: %s", CAIPS_GET_ERROR);
1063 static void applyMulticastToInterface6(uint32_t ifindex)
1065 if (!caglobals.ip.ipv6enabled)
1069 //applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressInt, ifindex);
1070 applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressLnk, ifindex);
1071 //applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressRlm, ifindex);
1072 //applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressAdm, ifindex);
1073 //applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressSit, ifindex);
1074 //applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressOrg, ifindex);
1075 //applyMulticast6(caglobals.ip.m6.fd, &IPv6MulticastAddressGlb, ifindex);
1077 //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressInt, ifindex);
1078 applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressLnk, ifindex);
1079 //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressRlm, ifindex);
1080 //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressAdm, ifindex);
1081 //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressSit, ifindex);
1082 //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressOrg, ifindex);
1083 //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressGlb, ifindex);
1086 CAResult_t CAIPStartListenServer()
1088 u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
1091 OIC_LOG_V(ERROR, TAG, "CAIPGetInterfaceInformation() failed: %s", strerror(errno));
1092 return CA_STATUS_FAILED;
1095 uint32_t len = u_arraylist_length(iflist);
1096 OIC_LOG_V(DEBUG, TAG, "IP network interfaces found: %d", len);
1098 for (uint32_t i = 0; i < len; i++)
1100 CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
1106 if ((ifitem->flags & IFF_UP_RUNNING_FLAGS) != IFF_UP_RUNNING_FLAGS)
1110 if (ifitem->family == AF_INET)
1112 OIC_LOG_V(DEBUG, TAG, "Adding IPv4 interface %i to multicast group", ifitem->index);
1113 applyMulticastToInterface4(ifitem->index);
1115 if (ifitem->family == AF_INET6)
1117 OIC_LOG_V(DEBUG, TAG, "Adding IPv6 interface %i to multicast group", ifitem->index);
1118 applyMulticastToInterface6(ifitem->index);
1122 u_arraylist_destroy(iflist);
1123 return CA_STATUS_OK;
1126 CAResult_t CAIPStopListenServer()
1128 u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
1131 OIC_LOG_V(ERROR, TAG, "Get interface info failed: %s", strerror(errno));
1132 return CA_STATUS_FAILED;
1135 uint32_t len = u_arraylist_length(iflist);
1136 OIC_LOG_V(DEBUG, TAG, "IP network interfaces found: %d", len);
1138 for (uint32_t i = 0; i < len; i++)
1140 CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
1146 if ((ifitem->flags & IFF_UP_RUNNING_FLAGS) != IFF_UP_RUNNING_FLAGS)
1150 if (ifitem->family == AF_INET)
1154 OIC_LOG_V(DEBUG, TAG, "IPv4 network interface: %s cloed", ifitem->name);
1156 if (ifitem->family == AF_INET6)
1160 OIC_LOG_V(DEBUG, TAG, "IPv6 network interface: %s", ifitem->name);
1163 u_arraylist_destroy(iflist);
1164 return CA_STATUS_OK;
1167 static void CAProcessNewInterface(CAInterface_t *ifitem)
1171 OIC_LOG(DEBUG, TAG, "ifitem is null");
1175 if (ifitem->family == AF_INET6)
1177 applyMulticastToInterface6(ifitem->index);
1179 if (ifitem->family == AF_INET)
1181 applyMulticastToInterface4(ifitem->index);
1185 void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback)
1187 g_packetReceivedCallback = callback;
1190 void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback)
1192 CAIPSetNetworkMonitorCallback(callback);
1195 static void sendData(int fd, const CAEndpoint_t *endpoint,
1196 const void *data, uint32_t dlen,
1197 const char *cast, const char *fam)
1199 OIC_LOG(DEBUG, TAG, "IN");
1203 OIC_LOG(DEBUG, TAG, "endpoint is null");
1204 if (g_ipErrorHandler)
1206 g_ipErrorHandler(endpoint, data, dlen, CA_STATUS_INVALID_PARAM);
1211 char *secure = (endpoint->flags & CA_SECURE) ? "secure " : "";
1213 (void)cast; // eliminates release warning
1216 struct sockaddr_storage sock;
1217 CAConvertNameToAddr(endpoint->addr, endpoint->port, &sock);
1220 if (sock.ss_family == AF_INET6)
1222 /** @todo figure out correct usage for ifindex, and sin6_scope_id */
1223 socklen = sizeof(struct sockaddr_in6);
1227 socklen = sizeof(struct sockaddr_in);
1229 #if !defined(_WIN32)
1230 ssize_t len = sendto(fd, data, dlen, 0, (struct sockaddr *)&sock, socklen);
1231 if (OC_SOCKET_ERROR == len)
1233 // If logging is not defined/enabled.
1234 if (g_ipErrorHandler)
1236 g_ipErrorHandler(endpoint, data, dlen, CA_SEND_FAILED);
1238 OIC_LOG_V(ERROR, TAG, "%s%s %s sendTo failed: %s", secure, cast, fam, strerror(errno));
1242 OIC_LOG_V(INFO, TAG, "%s%s %s sendTo is successful: %zd bytes", secure, cast, fam, len);
1249 len = sendto(fd, ((char*)data) + sent, dlen - sent, 0, (struct sockaddr *)&sock, socklen);
1250 if (OC_SOCKET_ERROR == len)
1252 err = WSAGetLastError();
1253 if ((WSAEWOULDBLOCK != err) && (WSAENOBUFS != err))
1255 // If logging is not defined/enabled.
1256 if (g_ipErrorHandler)
1258 g_ipErrorHandler(endpoint, data, dlen, CA_SEND_FAILED);
1261 OIC_LOG_V(ERROR, TAG, "%s%s %s sendTo failed: %i", secure, cast, fam, err);
1269 OIC_LOG_V(DEBUG, TAG, "%s%s %s sendTo (Partial Send) is successful: "
1270 "currently sent: %ld bytes, "
1271 "total sent: %ld bytes, "
1272 "remaining: %ld bytes",
1273 secure, cast, fam, len, sent, dlen-sent);
1277 OIC_LOG_V(INFO, TAG, "%s%s %s sendTo is successful: %ld bytes",
1278 secure, cast, fam, len);
1281 } while ((OC_SOCKET_ERROR == len) && ((WSAEWOULDBLOCK == err) || (WSAENOBUFS == err)) || (sent < dlen));
1285 static void sendMulticastData6(const u_arraylist_t *iflist,
1286 CAEndpoint_t *endpoint,
1287 const void *data, uint32_t datalen)
1291 OIC_LOG(DEBUG, TAG, "endpoint is null");
1295 int scope = endpoint->flags & CA_SCOPE_MASK;
1296 char *ipv6mcname = ipv6mcnames[scope];
1299 OIC_LOG_V(INFO, TAG, "IPv6 multicast scope invalid: %d", scope);
1302 OICStrcpy(endpoint->addr, sizeof(endpoint->addr), ipv6mcname);
1303 int fd = caglobals.ip.u6.fd;
1305 uint32_t len = u_arraylist_length(iflist);
1306 for (uint32_t i = 0; i < len; i++)
1308 CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
1313 if ((ifitem->flags & IFF_UP_RUNNING_FLAGS) != IFF_UP_RUNNING_FLAGS)
1317 if (ifitem->family != AF_INET6)
1322 int index = ifitem->index;
1323 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, OPTVAL_T(&index), sizeof (index)))
1325 OIC_LOG_V(ERROR, TAG, "setsockopt6 failed: %s", CAIPS_GET_ERROR);
1328 sendData(fd, endpoint, data, datalen, "multicast", "ipv6");
1332 static void sendMulticastData4(const u_arraylist_t *iflist,
1333 CAEndpoint_t *endpoint,
1334 const void *data, uint32_t datalen)
1336 VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL");
1338 #if defined(USE_IP_MREQN)
1339 struct ip_mreqn mreq = { .imr_multiaddr = IPv4MulticastAddress,
1340 .imr_address.s_addr = htonl(INADDR_ANY),
1343 struct ip_mreq mreq = { .imr_multiaddr = IPv4MulticastAddress,
1344 .imr_interface = {0}};
1347 OICStrcpy(endpoint->addr, sizeof(endpoint->addr), IPv4_MULTICAST);
1348 int fd = caglobals.ip.u4.fd;
1350 uint32_t len = u_arraylist_length(iflist);
1351 for (uint32_t i = 0; i < len; i++)
1353 CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
1358 if ((ifitem->flags & IFF_UP_RUNNING_FLAGS) != IFF_UP_RUNNING_FLAGS)
1362 if (ifitem->family != AF_INET)
1366 #if defined(USE_IP_MREQN)
1367 mreq.imr_ifindex = ifitem->index;
1369 mreq.imr_interface.s_addr = htonl(ifitem->index);
1371 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, OPTVAL_T(&mreq), sizeof (mreq)))
1373 OIC_LOG_V(ERROR, TAG, "send IP_MULTICAST_IF failed: %s (using defualt)",
1376 sendData(fd, endpoint, data, datalen, "multicast", "ipv4");
1380 void CAIPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen,
1383 VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL");
1384 VERIFY_NON_NULL_VOID(data, TAG, "data is NULL");
1386 bool isSecure = (endpoint->flags & CA_SECURE) != 0;
1390 endpoint->port = isSecure ? CA_SECURE_COAP : CA_COAP;
1392 u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
1395 OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
1399 if ((endpoint->flags & CA_IPV6) && caglobals.ip.ipv6enabled)
1401 sendMulticastData6(iflist, endpoint, data, datalen);
1403 if ((endpoint->flags & CA_IPV4) && caglobals.ip.ipv4enabled)
1405 sendMulticastData4(iflist, endpoint, data, datalen);
1408 u_arraylist_destroy(iflist);
1412 if (!endpoint->port) // unicast discovery
1414 endpoint->port = isSecure ? CA_SECURE_COAP : CA_COAP;
1418 if (caglobals.ip.ipv6enabled && (endpoint->flags & CA_IPV6))
1420 fd = isSecure ? caglobals.ip.u6s.fd : caglobals.ip.u6.fd;
1421 #ifndef __WITH_DTLS__
1422 fd = caglobals.ip.u6.fd;
1424 sendData(fd, endpoint, data, datalen, "unicast", "ipv6");
1426 if (caglobals.ip.ipv4enabled && (endpoint->flags & CA_IPV4))
1428 fd = isSecure ? caglobals.ip.u4s.fd : caglobals.ip.u4.fd;
1429 #ifndef __WITH_DTLS__
1430 fd = caglobals.ip.u4.fd;
1432 sendData(fd, endpoint, data, datalen, "unicast", "ipv4");
1437 CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
1439 VERIFY_NON_NULL(info, TAG, "info is NULL");
1440 VERIFY_NON_NULL(size, TAG, "size is NULL");
1442 u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
1445 OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
1446 return CA_STATUS_FAILED;
1449 uint32_t len = u_arraylist_length(iflist);
1450 uint32_t length = len;
1452 #ifdef __WITH_DTLS__
1453 //If DTLS is supported, each interface can support secure port as well
1457 CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(length, sizeof (CAEndpoint_t));
1460 OIC_LOG(ERROR, TAG, "Malloc Failed");
1461 u_arraylist_destroy(iflist);
1462 return CA_MEMORY_ALLOC_FAILED;
1465 for (uint32_t i = 0, j = 0; i < len; i++)
1467 CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
1473 eps[j].adapter = CA_ADAPTER_IP;
1476 if (ifitem->family == AF_INET6)
1478 eps[j].flags = CA_IPV6;
1479 eps[j].port = caglobals.ip.u6.port;
1483 eps[j].flags = CA_IPV4;
1484 eps[j].port = caglobals.ip.u4.port;
1485 /** @todo eps[j].addr not populated with IPv4 address string.
1486 * it was using ifitem->ipv4addr to accomplish this.
1487 * Need to understand what ipv4addr means to whom*/
1490 #ifdef __WITH_DTLS__
1493 eps[j].adapter = CA_ADAPTER_IP;
1496 if (ifitem->family == AF_INET6)
1498 eps[j].flags = CA_IPV6 | CA_SECURE;
1499 eps[j].port = caglobals.ip.u6s.port;
1503 eps[j].flags = CA_IPV4 | CA_SECURE;
1504 eps[j].port = caglobals.ip.u4s.port;
1505 inet_ntop(AF_INET, &(ifitem->ipv4addr), eps[j].addr, MAX_ADDR_STR_SIZE_CA);
1514 u_arraylist_destroy(iflist);
1516 return CA_STATUS_OK;
1519 void CAIPSetErrorHandler(CAIPErrorHandleCallback errorHandleCallback)
1521 g_ipErrorHandler = errorHandleCallback;