aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src
diff options
context:
space:
mode:
authorAngelo Mantellini <manangel@cisco.com>2019-01-31 18:20:48 +0100
committerAngelo Mantellini <manangel@cisco.com>2019-02-01 15:23:03 +0100
commitf5a0b8a5e24cede05e15ab696f0e15257a503525 (patch)
tree8cab87196baf7ea5468cebc4002da45175d91ae8 /hicn-light/src
parentbf29f9a52ffa3a1f32f700e4fd36ea53885d83aa (diff)
[HICN24] Windows compatibility for hicn-light
Change-Id: I8e19e52c9b4ec0fcbd7344c28765f5da1937569c Signed-off-by: Angelo Mantellini <manangel@cisco.com>
Diffstat (limited to 'hicn-light/src')
-rw-r--r--hicn-light/src/command_line/controller/hicnLightControl_main.c57
-rw-r--r--hicn-light/src/command_line/daemon/hicnLightDaemon_main.c56
-rw-r--r--hicn-light/src/config.h.in4
-rw-r--r--hicn-light/src/config/commandOps.c6
-rw-r--r--hicn-light/src/config/commandParser.c10
-rw-r--r--hicn-light/src/config/configuration.c9
-rw-r--r--hicn-light/src/config/configuration.h2
-rw-r--r--hicn-light/src/config/configurationFile.c15
-rw-r--r--hicn-light/src/config/configurationListeners.c22
-rw-r--r--hicn-light/src/config/controlAdd.c1
-rw-r--r--hicn-light/src/config/controlAddConnection.c1
-rw-r--r--hicn-light/src/config/controlAddListener.c1
-rw-r--r--hicn-light/src/config/controlAddPunting.c9
-rw-r--r--hicn-light/src/config/controlAddRoute.c9
-rw-r--r--hicn-light/src/config/controlCache.c1
-rw-r--r--hicn-light/src/config/controlCacheClear.c1
-rw-r--r--hicn-light/src/config/controlCacheServe.c1
-rw-r--r--hicn-light/src/config/controlCacheStore.c1
-rw-r--r--hicn-light/src/config/controlList.c1
-rw-r--r--hicn-light/src/config/controlListConnections.c1
-rw-r--r--hicn-light/src/config/controlListInterfaces.c1
-rw-r--r--hicn-light/src/config/controlListListeners.c1
-rw-r--r--hicn-light/src/config/controlListRoutes.c1
-rw-r--r--hicn-light/src/config/controlMapMe.c1
-rw-r--r--hicn-light/src/config/controlMapMeDiscovery.c1
-rw-r--r--hicn-light/src/config/controlMapMeEnable.c1
-rw-r--r--hicn-light/src/config/controlMapMeRetx.c1
-rw-r--r--hicn-light/src/config/controlMapMeTimescale.c1
-rw-r--r--hicn-light/src/config/controlQuit.c1
-rw-r--r--hicn-light/src/config/controlRemove.c1
-rw-r--r--hicn-light/src/config/controlRemoveConnection.c1
-rw-r--r--hicn-light/src/config/controlRemovePunting.c1
-rw-r--r--hicn-light/src/config/controlRemoveRoute.c10
-rw-r--r--hicn-light/src/config/controlRoot.c1
-rw-r--r--hicn-light/src/config/controlSet.c1
-rw-r--r--hicn-light/src/config/controlSetDebug.c1
-rw-r--r--hicn-light/src/config/controlSetStrategy.c9
-rw-r--r--hicn-light/src/config/controlSetWldr.c1
-rw-r--r--hicn-light/src/config/controlState.c7
-rw-r--r--hicn-light/src/config/controlUnset.c1
-rw-r--r--hicn-light/src/config/controlUnsetDebug.c1
-rw-r--r--hicn-light/src/content_store/contentStoreLRU.c4
-rw-r--r--hicn-light/src/content_store/listLRU.c4
-rw-r--r--hicn-light/src/core/connection.c10
-rw-r--r--hicn-light/src/core/connectionTable.c4
-rw-r--r--hicn-light/src/core/dispatcher.c49
-rw-r--r--hicn-light/src/core/dispatcher.h4
-rw-r--r--hicn-light/src/core/forwarder.c32
-rw-r--r--hicn-light/src/core/forwarder.h5
-rw-r--r--hicn-light/src/core/logger.c5
-rw-r--r--hicn-light/src/core/logger.h7
-rw-r--r--hicn-light/src/core/nameBitvector.c16
-rw-r--r--hicn-light/src/core/nameBitvector.h2
-rw-r--r--hicn-light/src/core/wldr.c8
-rw-r--r--hicn-light/src/io/hicnListener.c26
-rw-r--r--hicn-light/src/io/tcpListener.h3
-rw-r--r--hicn-light/src/io/udpListener.c44
-rw-r--r--hicn-light/src/io/udpListener.h3
-rw-r--r--hicn-light/src/platforms/CMakeLists.txt9
-rw-r--r--hicn-light/src/platforms/windows/system.c223
-rw-r--r--hicn-light/src/platforms/windows/win_portability.c50
-rw-r--r--hicn-light/src/platforms/windows/win_portability.h54
-rw-r--r--hicn-light/src/utils/address.c5
-rw-r--r--hicn-light/src/utils/address.h4
-rw-r--r--hicn-light/src/utils/commands.h6
-rw-r--r--hicn-light/src/utils/utils.c8
66 files changed, 674 insertions, 163 deletions
diff --git a/hicn-light/src/command_line/controller/hicnLightControl_main.c b/hicn-light/src/command_line/controller/hicnLightControl_main.c
index 4641bddf5..03f74692f 100644
--- a/hicn-light/src/command_line/controller/hicnLightControl_main.c
+++ b/hicn-light/src/command_line/controller/hicnLightControl_main.c
@@ -15,13 +15,18 @@
#include <src/config.h>
+#ifndef _WIN32
+#include <arpa/inet.h>
#include <getopt.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
#include <string.h>
@@ -71,22 +76,17 @@ static int payloadLengthController[LAST_COMMAND_VALUE] = {
sizeof(mapme_timing_command),
sizeof(mapme_timing_command)};
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
typedef struct controller_main_state {
ControlState *controlState;
} ControlMainState;
-static void _displayForwarderLogo(void){
- const char cli_banner [] =
- "\033[0;31m ____ ___ _ \033[0m __ _ __ _ __ __\n"
- "\033[0;31m / __// _ \\ (_)___ \033[0m / / (_)____ ___ ____/ /(_)___ _ / / / /_\n"
- "\033[0;31m / _/ / // /_ / // _ \\ \033[0m / _ \\ / // __// _ \\___/ // // _ `// _ \\/ __/\n"
- "\033[0;31m/_/ /____/(_)/_/ \\___/ \033[0m/_//_//_/ \\__//_//_/ /_//_/ \\_, //_//_/\\__/\n"
- " /___/ \n";
+static void _displayForwarderLogo(void) {
+ const char cli_banner[] =
+ "\033[0;31m ____ ___ _ \033[0m __ _ __ _ __ __\n"
+ "\033[0;31m / __// _ \\ (_)___ \033[0m / / (_)____ ___ ____/ /(_)___ _ / / / /_\n"
+ "\033[0;31m / _/ / // /_ / // _ \\ \033[0m / _ \\ / // __// _ \\___/ // // _ `// _ \\/ __/\n"
+ "\033[0;31m/_/ /____/(_)/_/ \\___/ \033[0m/_//_//_/ \\__//_//_/ /_//_/ \\_, //_//_/\\__/\n"
+ " /___/ \n";
printf("%s", cli_banner);
printf("\n");
}
@@ -165,15 +165,25 @@ struct iovec *_writeAndReadMessage(ControlState *state, struct iovec *msg) {
0) { // command with payload
// write header + payload (compatibility issue: two write needed instead of
// the writev)
- if (write(sockfd, msg[0].iov_base, msg[0].iov_len) < 0 ||
- write(sockfd, msg[1].iov_base, msg[1].iov_len) < 0) {
+#ifndef _WIN32
+ if (write(sockfd, msg[0].iov_base, (unsigned int)msg[0].iov_len) < 0 ||
+ write(sockfd, msg[1].iov_base, (unsigned int)msg[1].iov_len) < 0) {
+#else
+ if (send(sockfd, msg[0].iov_base, msg[0].iov_len, 0) == SOCKET_ERROR ||
+ send(sockfd, msg[1].iov_base, msg[1].iov_len, 0) == SOCKET_ERROR) {
+#endif
printf("\nError while sending the Message: cannot write on socket \n");
exit(EXIT_FAILURE);
}
parcMemory_Deallocate(&msg[1].iov_base);
} else { // command without payload, e.g. 'list'
- // write header only
+ // write header only
+#ifndef _WIN32
if (write(sockfd, msg[0].iov_base, msg[0].iov_len) < 0) {
+#else
+ int result = send(sockfd, msg[0].iov_base, msg[0].iov_len, 0);
+ if (result == SOCKET_ERROR) {
+#endif
printf("\nError while sending the Message: cannot write on socket \n");
exit(EXIT_FAILURE);
}
@@ -193,8 +203,12 @@ struct iovec *_writeAndReadMessage(ControlState *state, struct iovec *msg) {
if (headerResponse->messageType < RESPONSE_LIGHT ||
headerResponse->messageType >= LAST_MSG_TYPE_VALUE) {
char *checkFinMsg = parcMemory_Reallocate(headerResponse, 32);
+#ifndef _WIN32
if (recv(sockfd, checkFinMsg, sizeof(checkFinMsg),
MSG_PEEK | MSG_DONTWAIT) == 0) {
+#else
+ if (recv(sockfd, checkFinMsg, sizeof(checkFinMsg), MSG_PEEK) == 0) {
+#endif
// if recv returns zero, that means the connection has been closed:
close(sockfd);
printf("\nConnection terminated by the Daemon. Exiting... \n");
@@ -236,6 +250,11 @@ struct iovec *_writeAndReadMessage(ControlState *state, struct iovec *msg) {
int main(int argc, char *argv[]) {
_displayForwarderLogo();
+#ifdef _WIN32
+ WSADATA wsaData;
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
+
if (argc == 2 && strcmp("-h", argv[1]) == 0) {
_displayUsage(argv[0]);
exit(EXIT_SUCCESS);
@@ -279,6 +298,8 @@ int main(int argc, char *argv[]) {
parcList_Release(&commands);
controlState_Destroy(&mainState.controlState);
-
+#ifdef _WIN32
+ WSACleanup();
+#endif
return EXIT_SUCCESS;
}
diff --git a/hicn-light/src/command_line/daemon/hicnLightDaemon_main.c b/hicn-light/src/command_line/daemon/hicnLightDaemon_main.c
index 415e98d65..1b7e92e75 100644
--- a/hicn-light/src/command_line/daemon/hicnLightDaemon_main.c
+++ b/hicn-light/src/command_line/daemon/hicnLightDaemon_main.c
@@ -13,6 +13,9 @@
* limitations under the License.
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <src/config.h>
@@ -21,9 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
#include <sys/stat.h>
-#include <unistd.h>
#include <parc/algol/parc_FileOutputStream.h>
#include <parc/logging/parc_LogLevel.h>
@@ -35,21 +36,27 @@
#include <src/core/dispatcher.h>
#include <src/core/forwarder.h>
-static void _displayForwarderLogo(void){
- const char cli_banner [] =
- "\033[0;31m ____ ___ _ \033[0m __ _ __ _ __ __\n"
- "\033[0;31m / __// _ \\ (_)___ \033[0m / / (_)____ ___ ____/ /(_)___ _ / / / /_\n"
- "\033[0;31m / _/ / // /_ / // _ \\ \033[0m / _ \\ / // __// _ \\___/ // // _ `// _ \\/ __/\n"
- "\033[0;31m/_/ /____/(_)/_/ \\___/ \033[0m/_//_//_/ \\__//_//_/ /_//_/ \\_, //_//_/\\__/\n"
- " /___/ \n";
+static void _displayForwarderLogo(void) {
+ const char cli_banner[] =
+ "\033[0;31m ____ ___ _ \033[0m __ _ __ _ __ __\n"
+ "\033[0;31m / __// _ \\ (_)___ \033[0m / / (_)____ ___ ____/ /(_)___ _ / / / /_\n"
+ "\033[0;31m / _/ / // /_ / // _ \\ \033[0m / _ \\ / // __// _ \\___/ // // _ `// _ \\/ __/\n"
+ "\033[0;31m/_/ /____/(_)/_/ \\___/ \033[0m/_//_//_/ \\__//_//_/ /_//_/ \\_, //_//_/\\__/\n"
+ " /___/ \n";
printf("%s", cli_banner);
printf("\n");
}
static void _usage(int exitCode) {
+#ifndef _WIN32
+ printf(
+ "Usage: daemon [--port port] [--capacity objectStoreSize] "
+ "[--log facility=level] [--log-file filename] [--config file]\n");
+#else
printf(
"Usage: daemon [--port port] [--daemon] [--capacity objectStoreSize] "
"[--log facility=level] [--log-file filename] [--config file]\n");
+#endif
printf("\n");
printf(
"hicn-light run as a daemon is the program to launch the forwarder, "
@@ -79,7 +86,9 @@ static void _usage(int exitCode) {
printf("\n");
printf("Options:\n");
printf("--port = tcp port for in-bound connections\n");
+#ifndef _WIN32
printf("--daemon = start as daemon process\n");
+#endif
printf("--objectStoreSize = maximum number of content objects to cache\n");
printf(
"--log = sets a facility to a given log level. You can have "
@@ -122,9 +131,9 @@ static void _setLogLevel(int logLevelArray[LoggerFacility_END],
char *tofree = parcMemory_StringDuplicate(string, strlen(string));
char *p = tofree;
- char *facilityString = strsep(&p, "=");
+ char *facilityString = strtok(p, "=");
if (facilityString) {
- char *levelString = p;
+ char *levelString = strtok(NULL, "=");
if (strcasecmp(facilityString, "all") == 0) {
for (LoggerFacility facility = 0; facility < LoggerFacility_END;
@@ -151,6 +160,7 @@ static void _setLogLevel(int logLevelArray[LoggerFacility_END],
parcMemory_Deallocate((void **)&tofree);
}
+#ifndef _WIN32
static void _daemonize(void) {
if (getppid() == 1) {
// already a daemon
@@ -195,16 +205,24 @@ static void _daemonize(void) {
// forwarder will capture signals
}
+#endif
static Logger *_createLogfile(const char *logfile) {
+#ifndef _WIN32
int logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, S_IWUSR | S_IRUSR);
+#else
+ int logfd =
+ _open(logfile, _O_WRONLY | _O_APPEND | _O_CREAT, _S_IWRITE | _S_IREAD);
+#endif
if (logfd < 0) {
fprintf(stderr, "Error opening %s for writing: (%d) %s\n", logfile, errno,
strerror(errno));
exit(EXIT_FAILURE);
}
+#ifndef _WIN32
chmod(logfile, S_IRWXU);
+#endif
PARCFileOutputStream *fos = parcFileOutputStream_Create(logfd);
PARCOutputStream *pos = parcFileOutputStream_AsOutputStream(fos);
@@ -220,10 +238,15 @@ static Logger *_createLogfile(const char *logfile) {
int main(int argc, const char *argv[]) {
_displayForwarderLogo();
+#ifndef _WIN32
+ bool daemon = false;
+#else
+ WSADATA wsaData = {0};
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
uint16_t port = PORT_NUMBER;
uint16_t configurationPort = 2001;
- bool daemon = false;
int capacity = -1;
const char *configFileName = NULL;
@@ -246,8 +269,10 @@ int main(int argc, const char *argv[]) {
} else if (strcmp(argv[i], "--port") == 0) {
port = atoi(argv[i + 1]);
i++;
+#ifndef _WIN32
} else if (strcmp(argv[i], "--daemon") == 0) {
daemon = true;
+#endif
} else if (strcmp(argv[i], "--capacity") == 0 ||
strcmp(argv[i], "-c") == 0) {
capacity = atoi(argv[i + 1]);
@@ -273,6 +298,7 @@ int main(int argc, const char *argv[]) {
// set restrictive umask, in case we create any files
umask(027);
+#ifndef _WIN32
if (daemon && (logfile == NULL)) {
fprintf(stderr, "Must specify a logfile when running in daemon mode\n");
_usage(EXIT_FAILURE);
@@ -282,6 +308,7 @@ int main(int argc, const char *argv[]) {
// inside this call, parent will EXIT_SUCCESS and child will continue
_daemonize();
}
+#endif
Logger *logger = NULL;
if (logfile) {
@@ -329,7 +356,12 @@ int main(int argc, const char *argv[]) {
forwarder_Destroy(&forwarder);
+#ifndef _WIN32
sleep(2);
+#else
+ Sleep(2000);
+ WSACleanup();
+#endif
logger_Release(&logger);
return 0;
diff --git a/hicn-light/src/config.h.in b/hicn-light/src/config.h.in
index 16ec1ab3a..8b763df40 100644
--- a/hicn-light/src/config.h.in
+++ b/hicn-light/src/config.h.in
@@ -1,5 +1,9 @@
/* CPU Cache line size */
#define LEVEL1_DCACHE_LINESIZE @LEVEL1_DCACHE_LINESIZE@
+#ifndef _WIN32
#define _GNU_SOURCE
+#else
+#include <src/platforms/windows/win_portability.h>
+#endif
diff --git a/hicn-light/src/config/commandOps.c b/hicn-light/src/config/commandOps.c
index 027c86e0a..2f7ebe49d 100644
--- a/hicn-light/src/config/commandOps.c
+++ b/hicn-light/src/config/commandOps.c
@@ -14,14 +14,10 @@
*/
#include <src/config.h>
-
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
-
-#include <parc/assert/parc_Assert.h>
#include <string.h>
#ifndef __ANDROID__
@@ -33,7 +29,7 @@ extern int errno;
#endif
#include <parc/algol/parc_Memory.h>
-
+#include <parc/assert/parc_Assert.h>
#include <src/config/commandOps.h>
#include <src/config/commandParser.h>
diff --git a/hicn-light/src/config/commandParser.c b/hicn-light/src/config/commandParser.c
index 84d273c9d..9a947d8b7 100644
--- a/hicn-light/src/config/commandParser.c
+++ b/hicn-light/src/config/commandParser.c
@@ -15,13 +15,11 @@
#include <src/config.h>
+#include <parc/assert/parc_Assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
-
-#include <parc/assert/parc_Assert.h>
#include <string.h>
#include <parc/security/parc_Security.h>
@@ -124,11 +122,13 @@ static PARCList *parseStringIntoTokens(const char *originalString) {
char *tofree =
parcMemory_StringDuplicate(originalString, strlen(originalString) + 1);
char *string = tofree;
-
- while ((token = strsep(&string, " \t\n")) != NULL) {
+
+ token = strtok(string, " \t\n");
+ while (token != NULL) {
if (strlen(token) > 0) {
parcList_Add(list, strdup(token));
}
+ token = strtok(NULL, " \t\n");
}
parcMemory_Deallocate((void **)&tofree);
diff --git a/hicn-light/src/config/configuration.c b/hicn-light/src/config/configuration.c
index 737605932..71616cd78 100644
--- a/hicn-light/src/config/configuration.c
+++ b/hicn-light/src/config/configuration.c
@@ -20,14 +20,17 @@
* <#example#>
* @endcode
*/
+
+#ifndef _WIN32
#include <arpa/inet.h>
+#include <unistd.h>
+#endif
#include <ctype.h>
#include <parc/assert/parc_Assert.h>
#include <src/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <parc/algol/parc_HashMap.h>
#include <parc/algol/parc_Memory.h>
@@ -364,11 +367,11 @@ struct iovec *configuration_ProcessCreateTunnel(Configuration *config,
logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
__func__, "Unsupported tunnel protocol: GRE");
break;
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
case HICN_CONN:
ops = hicnTunnel_Create(config->forwarder, source, destination);
break;
-#endif /* __APPLE__ */
+#endif /* __APPLE__ _WIN32*/
default:
logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
__func__, "Unsupported tunnel protocol: %d",
diff --git a/hicn-light/src/config/configuration.h b/hicn-light/src/config/configuration.h
index 2bf66c0b1..4dfcb0d16 100644
--- a/hicn-light/src/config/configuration.h
+++ b/hicn-light/src/config/configuration.h
@@ -26,8 +26,8 @@
#ifndef configuration_h
#define configuration_h
-#include <src/utils/commands.h>
#include <src/core/logger.h>
+#include <src/utils/commands.h>
struct configuration;
typedef struct configuration Configuration;
diff --git a/hicn-light/src/config/configurationFile.c b/hicn-light/src/config/configurationFile.c
index eab8f9362..3facf5afe 100644
--- a/hicn-light/src/config/configurationFile.c
+++ b/hicn-light/src/config/configurationFile.c
@@ -13,12 +13,14 @@
* limitations under the License.
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include <ctype.h>
#include <errno.h>
#include <src/config.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
#include <parc/algol/parc_ArrayList.h>
#include <parc/algol/parc_List.h>
@@ -157,9 +159,16 @@ static PARCList *_parseArgs(char *str) {
const char delimiters[] = " \t";
char *token;
- while ((token = strsep(&str, delimiters)) != NULL) {
- parcList_Add(list, token);
+ token = strtok(str, delimiters);
+ while (token != NULL) {
+ if (strlen(token) > 0) {
+ parcList_Add(list, strdup(token));
+ }
+ token = strtok(NULL, delimiters);
}
+ // while ((token = strsep(&str, delimiters)) != NULL) {
+ // parcList_Add(list, token);
+ // }
return list;
}
diff --git a/hicn-light/src/config/configurationListeners.c b/hicn-light/src/config/configurationListeners.c
index 0982a2b13..01ab9a3e7 100644
--- a/hicn-light/src/config/configurationListeners.c
+++ b/hicn-light/src/config/configurationListeners.c
@@ -13,13 +13,15 @@
* limitations under the License.
*/
+#ifndef _WIN32
#include <arpa/inet.h>
+#include <unistd.h>
+#endif
#include <parc/assert/parc_Assert.h>
#include <src/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
@@ -40,7 +42,7 @@
static bool _setupHicnListenerOnInet4(Forwarder *forwarder,
const char *symbolic, Address *address) {
bool success = false;
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
ListenerOps *ops =
hicnListener_CreateInet(forwarder, (char *)symbolic, address);
if (ops != NULL) {
@@ -48,14 +50,14 @@ static bool _setupHicnListenerOnInet4(Forwarder *forwarder,
parcAssertTrue(success, "Failed to add Hicn listener %s to ListenerSet",
symbolic);
}
-#endif /* __APPLE__ */
+#endif /* __APPLE__ _WIN32*/
return success;
}
static bool _setupHicnListenerOnInet6(Forwarder *forwarder,
const char *symbolic, Address *address) {
bool success = false;
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
ListenerOps *ops =
hicnListener_CreateInet6(forwarder, (char *)symbolic, address);
if (ops != NULL) {
@@ -63,7 +65,7 @@ static bool _setupHicnListenerOnInet6(Forwarder *forwarder,
parcAssertTrue(success, "Failed to add Hicn listener %s to ListenerSet",
symbolic);
}
-#endif /* __APPLE__ */
+#endif /* __APPLE__ _WIN32 */
return success;
}
@@ -79,7 +81,7 @@ bool configurationListeners_Remove(const Configuration *config) {
bool _AddPuntingInet(const Configuration *config, Punting *punting,
unsigned ingressId) {
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
struct sockaddr *addr = parcNetwork_SockAddress("0.0.0.0", 1234);
if (addr == NULL) {
printf("Error creating address\n");
@@ -139,7 +141,7 @@ bool _AddPuntingInet(const Configuration *config, Punting *punting,
bool _AddPuntingInet6(const Configuration *config, Punting *punting,
unsigned ingressId) {
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
struct sockaddr *addr = parcNetwork_SockAddress("0::0", 1234);
if (addr == NULL) {
printf("Error creating address\n");
@@ -149,9 +151,9 @@ bool _AddPuntingInet6(const Configuration *config, Punting *punting,
Address *fakeAddr = addressCreateFromInet6((struct sockaddr_in6 *)addr);
// comments:
- // EncapType: I use the Hicn encap since the punting is available only for Hicn
- // listeners LocalAddress: The only listern for which we need punting rules is
- // the main one, which has no address
+ // EncapType: I use the Hicn encap since the punting is available only for
+ // Hicn listeners LocalAddress: The only listern for which we need punting
+ // rules is the main one, which has no address
// so I create a fake empty address. This need to be consistent
// with the address set at creation time
diff --git a/hicn-light/src/config/controlAdd.c b/hicn-light/src/config/controlAdd.c
index 72f8e9759..7feee98ad 100644
--- a/hicn-light/src/config/controlAdd.c
+++ b/hicn-light/src/config/controlAdd.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
diff --git a/hicn-light/src/config/controlAddConnection.c b/hicn-light/src/config/controlAddConnection.c
index 0603e37a5..7a95e5d91 100644
--- a/hicn-light/src/config/controlAddConnection.c
+++ b/hicn-light/src/config/controlAddConnection.c
@@ -21,7 +21,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
diff --git a/hicn-light/src/config/controlAddListener.c b/hicn-light/src/config/controlAddListener.c
index 8f687c3a6..2cabfd035 100644
--- a/hicn-light/src/config/controlAddListener.c
+++ b/hicn-light/src/config/controlAddListener.c
@@ -21,7 +21,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlAddPunting.c b/hicn-light/src/config/controlAddPunting.c
index bd87e517c..13d00b7e0 100644
--- a/hicn-light/src/config/controlAddPunting.c
+++ b/hicn-light/src/config/controlAddPunting.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
@@ -93,7 +92,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
}
const char *prefixStr = parcList_GetAtIndex(args, _indexPrefix);
- char addr[strlen(prefixStr) + 1];
+ char *addr = (char *)malloc((strlen(prefixStr) + 1) * sizeof(char));
// separate address and len
char *slash;
@@ -107,6 +106,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
if (len == 0) {
printf("ERROR: a prefix can not be of length 0\n");
+ free(addr);
return CommandReturn_Failure;
}
@@ -119,6 +119,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
if (len > 32) {
printf("ERROR: exceeded INET mask length, max=32\n");
parcMemory_Deallocate(&addPuntingCommand);
+ free(addr);
return CommandReturn_Failure;
}
addPuntingCommand->addressType = ADDR_INET;
@@ -126,15 +127,19 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
parcMemory_Deallocate(&addPuntingCommand);
+ free(addr);
return CommandReturn_Failure;
}
addPuntingCommand->addressType = ADDR_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&addPuntingCommand);
+ free(addr);
return CommandReturn_Failure;
}
+ free(addr);
+
// Fill remaining payload fields
addPuntingCommand->len = len;
strcpy(addPuntingCommand->symbolicOrConnid, symbolicOrConnid);
diff --git a/hicn-light/src/config/controlAddRoute.c b/hicn-light/src/config/controlAddRoute.c
index c5ddab523..27aae4019 100644
--- a/hicn-light/src/config/controlAddRoute.c
+++ b/hicn-light/src/config/controlAddRoute.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
@@ -97,7 +96,7 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
}
const char *prefixStr = parcList_GetAtIndex(args, 3);
- char addr[strlen(prefixStr) + 1];
+ char *addr = (char *)malloc((strlen(prefixStr) + 1) * sizeof(char));
// separate address and len
char *slash;
@@ -111,6 +110,7 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
if (len == 0) {
printf("ERROR: a prefix can not be of length 0\n");
+ free(addr);
return CommandReturn_Failure;
}
@@ -123,6 +123,7 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
if (len > 32) {
printf("ERROR: exceeded INET mask length, max=32\n");
parcMemory_Deallocate(&addRouteCommand);
+ free(addr);
return CommandReturn_Failure;
}
addRouteCommand->addressType = ADDR_INET;
@@ -130,15 +131,19 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
parcMemory_Deallocate(&addRouteCommand);
+ free(addr);
return CommandReturn_Failure;
}
addRouteCommand->addressType = ADDR_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&addRouteCommand);
+ free(addr);
return CommandReturn_Failure;
}
+ free(addr);
+
// Fill remaining payload fields
addRouteCommand->len = len;
addRouteCommand->cost = (uint16_t)cost;
diff --git a/hicn-light/src/config/controlCache.c b/hicn-light/src/config/controlCache.c
index d7afbfe7d..e8d19e828 100644
--- a/hicn-light/src/config/controlCache.c
+++ b/hicn-light/src/config/controlCache.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlCacheClear.c b/hicn-light/src/config/controlCacheClear.c
index c5a4e9fde..2679f368e 100644
--- a/hicn-light/src/config/controlCacheClear.c
+++ b/hicn-light/src/config/controlCacheClear.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlCacheServe.c b/hicn-light/src/config/controlCacheServe.c
index 85d598025..9181810dd 100644
--- a/hicn-light/src/config/controlCacheServe.c
+++ b/hicn-light/src/config/controlCacheServe.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlCacheStore.c b/hicn-light/src/config/controlCacheStore.c
index 3bbb34386..d586188fb 100644
--- a/hicn-light/src/config/controlCacheStore.c
+++ b/hicn-light/src/config/controlCacheStore.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlList.c b/hicn-light/src/config/controlList.c
index 8afaa60dc..7e4636b00 100644
--- a/hicn-light/src/config/controlList.c
+++ b/hicn-light/src/config/controlList.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlListConnections.c b/hicn-light/src/config/controlListConnections.c
index 474ddc45f..b7dda0bbe 100644
--- a/hicn-light/src/config/controlListConnections.c
+++ b/hicn-light/src/config/controlListConnections.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlListInterfaces.c b/hicn-light/src/config/controlListInterfaces.c
index 20338b553..914cc3552 100644
--- a/hicn-light/src/config/controlListInterfaces.c
+++ b/hicn-light/src/config/controlListInterfaces.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlListListeners.c b/hicn-light/src/config/controlListListeners.c
index a149051e2..e84912205 100644
--- a/hicn-light/src/config/controlListListeners.c
+++ b/hicn-light/src/config/controlListListeners.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlListRoutes.c b/hicn-light/src/config/controlListRoutes.c
index 4a21b5ef4..ba116ce76 100644
--- a/hicn-light/src/config/controlListRoutes.c
+++ b/hicn-light/src/config/controlListRoutes.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlMapMe.c b/hicn-light/src/config/controlMapMe.c
index 2253f52b6..a839a9173 100644
--- a/hicn-light/src/config/controlMapMe.c
+++ b/hicn-light/src/config/controlMapMe.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlMapMeDiscovery.c b/hicn-light/src/config/controlMapMeDiscovery.c
index f8f4bf082..fd10cf18e 100644
--- a/hicn-light/src/config/controlMapMeDiscovery.c
+++ b/hicn-light/src/config/controlMapMeDiscovery.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlMapMeEnable.c b/hicn-light/src/config/controlMapMeEnable.c
index db77450e5..587aa6eb6 100644
--- a/hicn-light/src/config/controlMapMeEnable.c
+++ b/hicn-light/src/config/controlMapMeEnable.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlMapMeRetx.c b/hicn-light/src/config/controlMapMeRetx.c
index bb16b8833..21541d837 100644
--- a/hicn-light/src/config/controlMapMeRetx.c
+++ b/hicn-light/src/config/controlMapMeRetx.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlMapMeTimescale.c b/hicn-light/src/config/controlMapMeTimescale.c
index 9303b4b0f..872a50abc 100644
--- a/hicn-light/src/config/controlMapMeTimescale.c
+++ b/hicn-light/src/config/controlMapMeTimescale.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlQuit.c b/hicn-light/src/config/controlQuit.c
index 635fe278f..6df163c49 100644
--- a/hicn-light/src/config/controlQuit.c
+++ b/hicn-light/src/config/controlQuit.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlRemove.c b/hicn-light/src/config/controlRemove.c
index ede075a1b..da4b69fd9 100644
--- a/hicn-light/src/config/controlRemove.c
+++ b/hicn-light/src/config/controlRemove.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlRemoveConnection.c b/hicn-light/src/config/controlRemoveConnection.c
index 93365ad17..c701fc77f 100644
--- a/hicn-light/src/config/controlRemoveConnection.c
+++ b/hicn-light/src/config/controlRemoveConnection.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlRemovePunting.c b/hicn-light/src/config/controlRemovePunting.c
index cf4c4fbd4..0ae80ec9b 100644
--- a/hicn-light/src/config/controlRemovePunting.c
+++ b/hicn-light/src/config/controlRemovePunting.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlRemoveRoute.c b/hicn-light/src/config/controlRemoveRoute.c
index b9b4ed1e4..f654718f8 100644
--- a/hicn-light/src/config/controlRemoveRoute.c
+++ b/hicn-light/src/config/controlRemoveRoute.c
@@ -20,10 +20,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
-
#include <parc/assert/parc_Assert.h>
-
#include <parc/algol/parc_List.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
@@ -90,7 +87,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
}
const char *prefixStr = parcList_GetAtIndex(args, 3);
- char addr[strlen(prefixStr) + 1];
+ char *addr = (char *)malloc(sizeof(char) * (strlen(prefixStr) + 1));
// separate address and len
char *slash;
@@ -104,6 +101,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
if (len == 0) {
printf("ERROR: a prefix can not be of length 0\n");
+ free(addr);
return CommandReturn_Failure;
}
@@ -116,6 +114,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
if (len > 32) {
printf("ERROR: exceeded INET mask length, max=32\n");
parcMemory_Deallocate(&removeRouteCommand);
+ free(addr);
return CommandReturn_Failure;
}
removeRouteCommand->addressType = ADDR_INET;
@@ -124,15 +123,18 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
parcMemory_Deallocate(&removeRouteCommand);
+ free(addr);
return CommandReturn_Failure;
}
removeRouteCommand->addressType = ADDR_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&removeRouteCommand);
+ free(addr);
return CommandReturn_Failure;
}
+ free(addr);
// Fill remaining payload fields
removeRouteCommand->len = len;
strcpy(removeRouteCommand->symbolicOrConnid, symbolicOrConnid);
diff --git a/hicn-light/src/config/controlRoot.c b/hicn-light/src/config/controlRoot.c
index 5d6c5f98e..49b613208 100644
--- a/hicn-light/src/config/controlRoot.c
+++ b/hicn-light/src/config/controlRoot.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlSet.c b/hicn-light/src/config/controlSet.c
index c6fd9aa3e..07ca7e6b0 100644
--- a/hicn-light/src/config/controlSet.c
+++ b/hicn-light/src/config/controlSet.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlSetDebug.c b/hicn-light/src/config/controlSetDebug.c
index ca432420e..1739e777a 100644
--- a/hicn-light/src/config/controlSetDebug.c
+++ b/hicn-light/src/config/controlSetDebug.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlSetStrategy.c b/hicn-light/src/config/controlSetStrategy.c
index 7b7c11762..579862eeb 100644
--- a/hicn-light/src/config/controlSetStrategy.c
+++ b/hicn-light/src/config/controlSetStrategy.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
@@ -109,7 +108,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
}
const char *prefixStr = parcList_GetAtIndex(args, 2);
- char addr[strlen(prefixStr) + 1];
+ char *addr = (char *)malloc(sizeof(char) * (strlen(prefixStr) + 1));
// separate address and len
char *slash;
uint32_t len = UINT32_MAX;
@@ -121,6 +120,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
}
if (len == 0) {
printf("ERROR: a prefix can not be of length 0\n");
+ free(addr);
return CommandReturn_Failure;
}
@@ -136,6 +136,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
} else if (len > 32) {
printf("ERROR: exceeded INET mask length, max=32\n");
parcMemory_Deallocate(&setStrategyCommand);
+ free(addr);
return CommandReturn_Failure;
}
setStrategyCommand->addressType = ADDR_INET;
@@ -147,6 +148,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
} else if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
parcMemory_Deallocate(&setStrategyCommand);
+ free(addr);
return CommandReturn_Failure;
}
setStrategyCommand->addressType = ADDR_INET6;
@@ -163,9 +165,12 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
printf("Error: invalid strategy \n");
parcMemory_Deallocate(&setStrategyCommand);
_controlSetStrategy_HelpExecute(parser, ops, args);
+ free(addr);
return CommandReturn_Failure;
}
+ free(addr);
+
// Fill remaining payload fields
setStrategyCommand->len = len;
setStrategyCommand->strategyType = strategy;
diff --git a/hicn-light/src/config/controlSetWldr.c b/hicn-light/src/config/controlSetWldr.c
index 9da404036..7bb055af8 100644
--- a/hicn-light/src/config/controlSetWldr.c
+++ b/hicn-light/src/config/controlSetWldr.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlState.c b/hicn-light/src/config/controlState.c
index d8260e8e8..96c0529ed 100644
--- a/hicn-light/src/config/controlState.c
+++ b/hicn-light/src/config/controlState.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
#include <string.h>
@@ -66,7 +65,7 @@ int controlState_connectToFwdDeamon() {
// Filling server information
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
- servaddr.sin_addr.s_addr = INADDR_ANY;
+ inet_pton(AF_INET, SRV_IP, &(servaddr.sin_addr.s_addr));
// Establish connection
if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
@@ -150,10 +149,12 @@ static PARCList *_controlState_ParseStringIntoTokens(
parcMemory_StringDuplicate(originalString, strlen(originalString) + 1);
char *string = tofree;
- while ((token = strsep(&string, " \t\n")) != NULL) {
+ token = strtok(string, " \t\n");
+ while (token != NULL) {
if (strlen(token) > 0) {
parcList_Add(list, strdup(token));
}
+ token = strtok(NULL, " \t\n");
}
parcMemory_Deallocate((void **)&tofree);
diff --git a/hicn-light/src/config/controlUnset.c b/hicn-light/src/config/controlUnset.c
index 2da6a6518..2742940fa 100644
--- a/hicn-light/src/config/controlUnset.c
+++ b/hicn-light/src/config/controlUnset.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/config/controlUnsetDebug.c b/hicn-light/src/config/controlUnsetDebug.c
index 4892bd513..bf3f6fe68 100644
--- a/hicn-light/src/config/controlUnsetDebug.c
+++ b/hicn-light/src/config/controlUnsetDebug.c
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/content_store/contentStoreLRU.c b/hicn-light/src/content_store/contentStoreLRU.c
index 9b69d51c0..2eb043d8e 100644
--- a/hicn-light/src/content_store/contentStoreLRU.c
+++ b/hicn-light/src/content_store/contentStoreLRU.c
@@ -13,9 +13,11 @@
* limitations under the License.
*/
+#ifndef _WIN32
+#include <sys/queue.h>
+#endif
#include <src/config.h>
#include <stdio.h>
-#include <sys/queue.h>
#include <parc/algol/parc_DisplayIndented.h>
#include <parc/algol/parc_HashCodeTable.h>
diff --git a/hicn-light/src/content_store/listLRU.c b/hicn-light/src/content_store/listLRU.c
index 42b491d7c..0a1631bab 100644
--- a/hicn-light/src/content_store/listLRU.c
+++ b/hicn-light/src/content_store/listLRU.c
@@ -13,10 +13,12 @@
* limitations under the License.
*/
+#ifndef _WIN32
+#include <sys/queue.h>
+#endif
#include <src/config.h>
#include <stdbool.h>
#include <stdio.h>
-#include <sys/queue.h>
#include <parc/algol/parc_Memory.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/core/connection.c b/hicn-light/src/core/connection.c
index 073b7260f..505bba081 100644
--- a/hicn-light/src/core/connection.c
+++ b/hicn-light/src/core/connection.c
@@ -193,11 +193,11 @@ bool connection_ReSend(const Connection *conn, Message *message,
// notification
// we need to recompiute the path lable since we always store a pointer to
- // the same message if this message will be sent again to someonelse, the new
- // path label must be computed starting from the orignal labelorignal label.
- // Notice that we heve the same problem in case of PIT aggregation. That case
- // is handled insied the MessageProcessor. This is specific to WLDR
- // retransmittions. This is done only for data packets
+ // the same message if this message will be sent again to someonelse, the
+ // new path label must be computed starting from the orignal labelorignal
+ // label. Notice that we heve the same problem in case of PIT aggregation.
+ // That case is handled insied the MessageProcessor. This is specific to
+ // WLDR retransmittions. This is done only for data packets
if (message_GetType(message) == MessagePacketType_ContentObject) {
uint8_t connectionId = (uint8_t)connection_GetConnectionId(conn);
diff --git a/hicn-light/src/core/connectionTable.c b/hicn-light/src/core/connectionTable.c
index ba0942ddb..8634ec825 100644
--- a/hicn-light/src/core/connectionTable.c
+++ b/hicn-light/src/core/connectionTable.c
@@ -20,11 +20,13 @@
*
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include <src/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/core/dispatcher.c b/hicn-light/src/core/dispatcher.c
index 078087c59..b6ef5e21f 100644
--- a/hicn-light/src/core/dispatcher.c
+++ b/hicn-light/src/core/dispatcher.c
@@ -22,9 +22,13 @@
* timers, and network events.
*/
+#ifndef _WIN32
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
-#include <pthread.h>
#include <signal.h>
#include <src/config.h>
#include <stdarg.h>
@@ -32,10 +36,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <unistd.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
#include <parc/algol/parc_EventQueue.h>
#include <parc/algol/parc_EventTimer.h>
@@ -44,6 +44,8 @@
#include <src/core/dispatcher.h>
+#include <pthread.h>
+
#ifndef INPORT_ANY
#define INPORT_ANY 0
#endif
@@ -298,6 +300,7 @@ static bool dispatcher_StreamBufferBindAndConnect(Dispatcher *dispatcher,
// we need to bind, then connect. Special operation, so we make our
// own fd then pass it off to the buffer event
+#ifndef _WIN32
int fd = socket(localSock->sa_family, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
@@ -333,6 +336,42 @@ static bool dispatcher_StreamBufferBindAndConnect(Dispatcher *dispatcher,
close(fd);
return false;
}
+#else
+ SOCKET fd = socket(localSock->sa_family, SOCK_STREAM, 0);
+ if (fd == INVALID_SOCKET) {
+ perror("socket");
+ return -1;
+ }
+
+ // Set non-blocking flag
+ u_long mode = 1;
+ int result = ioctlsocket(fd, FIONBIO, &mode);
+ if (result == NO_ERROR) {
+ perror("ioctlsocket error");
+ closesocket(fd);
+ WSACleanup();
+ return -1;
+ }
+
+ int failure = bind(fd, localSock, (int)localSockLength);
+ if (failure) {
+ perror("bind");
+ closesocket(fd);
+ WSACleanup();
+ return false;
+ }
+
+ parcEventQueue_SetFileDescriptor(buffer, (int)fd);
+
+ failure = parcEventQueue_ConnectSocket(buffer, remoteSock, remoteSockLength);
+ if (failure && (errno != EINPROGRESS)) {
+ perror("connect");
+ closesocket(fd);
+ WSACleanup();
+ return false;
+ }
+#endif
+
return true;
}
diff --git a/hicn-light/src/core/dispatcher.h b/hicn-light/src/core/dispatcher.h
index 35d804a00..96bceb451 100644
--- a/hicn-light/src/core/dispatcher.h
+++ b/hicn-light/src/core/dispatcher.h
@@ -28,8 +28,10 @@
#ifndef dispatcher_h
#define dispatcher_h
-#include <stdbool.h>
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
+#include <stdbool.h>
struct dispatcher;
typedef struct dispatcher Dispatcher;
diff --git a/hicn-light/src/core/forwarder.c b/hicn-light/src/core/forwarder.c
index e84351365..f3af85d6c 100644
--- a/hicn-light/src/core/forwarder.c
+++ b/hicn-light/src/core/forwarder.c
@@ -23,6 +23,11 @@
* the event scheduler
*/
+#ifndef _WIN32
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -32,10 +37,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <unistd.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
@@ -80,7 +81,9 @@ struct forwarder {
PARCEventSignal *signal_int;
PARCEventSignal *signal_term;
+#ifndef _WIN32
PARCEventSignal *signal_usr1;
+#endif
PARCEventTimer *keepalive_event;
// will skew the virtual clock forward. In normal operaiton, it is 0.
@@ -121,6 +124,7 @@ static void _keepalive_cb(int, PARCEventType, void *);
* Reseed our pseudo-random number generator.
*/
static void forwarder_Seed(Forwarder *forwarder) {
+#ifndef _WIN32
int fd;
ssize_t res;
@@ -139,6 +143,10 @@ static void forwarder_Seed(Forwarder *forwarder) {
* on other platforms.
*/
seed48(forwarder->seed);
+#else
+ forwarder->seed[1] = (unsigned short)getpid(); /* better than no entropy */
+ forwarder->seed[2] = (unsigned short)time(NULL);
+#endif
}
Logger *forwarder_GetLogger(const Forwarder *forwarder) {
@@ -183,22 +191,25 @@ Forwarder *forwarder_Create(Logger *logger) {
forwarder->signal_int = dispatcher_CreateSignalEvent(
forwarder->dispatcher, _signal_cb, forwarder, SIGINT);
dispatcher_StartSignalEvent(forwarder->dispatcher, forwarder->signal_int);
-
+#ifndef _WIN32
forwarder->signal_usr1 = dispatcher_CreateSignalEvent(
forwarder->dispatcher, _signal_cb, forwarder, SIGPIPE);
dispatcher_StartSignalEvent(forwarder->dispatcher, forwarder->signal_usr1);
+#endif
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
forwarder->hicnSocketHelper = hicn_create();
if (forwarder->hicnSocketHelper == NULL) return NULL;
#endif /* __APPLE__ */
- /* ignore child */
+ /* ignore child */
+#ifndef _WIN32
signal(SIGCHLD, SIG_IGN);
/* ignore tty signals */
signal(SIGTSTP, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
+#endif
// We no longer use this for ticks, but we need to have at least one event
// schedule to keep Libevent happy.
@@ -226,7 +237,7 @@ void forwarder_Destroy(Forwarder **ptr) {
parcAssertNotNull(ptr, "Parameter must be non-null double pointer");
parcAssertNotNull(*ptr, "Parameter must dereference to non-null pointer");
Forwarder *forwarder = *ptr;
-#if !defined(__APPLE__) && !defined(__ANDROID__)
+#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(_WIN32)
hicn_destroy();
#endif
parcEventTimer_Destroy(&(forwarder->keepalive_event));
@@ -244,8 +255,10 @@ void forwarder_Destroy(Forwarder **ptr) {
&(forwarder->signal_int));
dispatcher_DestroySignalEvent(forwarder->dispatcher,
&(forwarder->signal_term));
+#ifndef _WIN32
dispatcher_DestroySignalEvent(forwarder->dispatcher,
&(forwarder->signal_usr1));
+#endif
parcClock_Release(&forwarder->clock);
logger_Release(&forwarder->logger);
@@ -463,10 +476,11 @@ static void _signal_cb(int sig, PARCEventType events, void *user_data) {
__func__, "Caught an interrupt signal; exiting cleanly.");
dispatcher_Stop(forwarder->dispatcher);
break;
-
+#ifndef _WIN32
case SIGUSR1:
// dump stats
break;
+#endif
default:
break;
diff --git a/hicn-light/src/core/forwarder.h b/hicn-light/src/core/forwarder.h
index e044add3b..6bc823294 100644
--- a/hicn-light/src/core/forwarder.h
+++ b/hicn-light/src/core/forwarder.h
@@ -21,8 +21,10 @@
#ifndef forwarder_h
#define forwarder_h
-#include <stdlib.h>
+#ifndef _WIN32
#include <sys/time.h>
+#endif
+#include <stdlib.h>
#include <src/core/connectionTable.h>
#include <src/core/dispatcher.h>
@@ -56,7 +58,6 @@
struct forwarder;
typedef struct forwarder Forwarder;
-
/**
* @function forwarder_Create
* @abstract Create the forwarder and use the provided logger for diagnostic
diff --git a/hicn-light/src/core/logger.c b/hicn-light/src/core/logger.c
index cac3000e2..ebc8dc5a1 100644
--- a/hicn-light/src/core/logger.c
+++ b/hicn-light/src/core/logger.c
@@ -13,12 +13,15 @@
* limitations under the License.
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
#include <errno.h>
#include <src/config.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/core/logger.h b/hicn-light/src/core/logger.h
index e2ab7e147..c46a87097 100644
--- a/hicn-light/src/core/logger.h
+++ b/hicn-light/src/core/logger.h
@@ -25,13 +25,14 @@
#ifndef logger_h
#define logger_h
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
#include <parc/algol/parc_Buffer.h>
+#include <parc/algol/parc_Clock.h>
#include <parc/logging/parc_LogLevel.h>
#include <parc/logging/parc_LogReporter.h>
#include <stdarg.h>
-#include <sys/time.h>
-
-#include <parc/algol/parc_Clock.h>
struct logger;
typedef struct logger Logger;
diff --git a/hicn-light/src/core/nameBitvector.c b/hicn-light/src/core/nameBitvector.c
index 66f3eae20..c93f63292 100644
--- a/hicn-light/src/core/nameBitvector.c
+++ b/hicn-light/src/core/nameBitvector.c
@@ -49,7 +49,7 @@ struct name_bitvector {
uint8_t IPversion;
};
-NameBitvector *nameBitvector_CreateFromInAddr(uint32_t s_addr, uint8_t len) {
+NameBitvector *nameBitvector_CreateFromInAddr(uint32_t addr, uint8_t len) {
NameBitvector *bitvector = parcMemory_AllocateAndClear(sizeof(NameBitvector));
parcAssertNotNull(bitvector, "parcMemory_AllocateAndClear(%zu) returned NULL",
sizeof(NameBitvector));
@@ -57,10 +57,10 @@ NameBitvector *nameBitvector_CreateFromInAddr(uint32_t s_addr, uint8_t len) {
bitvector->bits[0] = 0;
bitvector->bits[1] = 0;
- uint8_t addr_1 = (s_addr & 0xff000000) >> 24;
- uint8_t addr_2 = (s_addr & 0x00ff0000) >> 16;
- uint8_t addr_3 = (s_addr & 0x0000ff00) >> 8;
- uint8_t addr_4 = (s_addr & 0x000000ff);
+ uint8_t addr_1 = (addr & 0xff000000) >> 24;
+ uint8_t addr_2 = (addr & 0x00ff0000) >> 16;
+ uint8_t addr_3 = (addr & 0x0000ff00) >> 8;
+ uint8_t addr_4 = (addr & 0x000000ff);
bitvector->bits[1] = (bitvector->bits[1] | addr_4) << 8;
bitvector->bits[1] = (bitvector->bits[1] | addr_3) << 8;
@@ -269,9 +269,9 @@ uint8_t nameBitvector_firstDiff(const NameBitvector *a,
// res is computed over the bitvector which is composed by 128 bit all the
// times however the prefixes may be diffrent just because the have different
// lengths example: prefix 1: 0::/30 prefix 2: 0::/20 at this point of the
- // function res would be 0 since both the bitvectors are composed by 0s but the
- // function will return 127-20, which is the position at which the two prefix
- // are different, since prefix 2 has only 20 bits
+ // function res would be 0 since both the bitvectors are composed by 0s but
+ // the function will return 127-20, which is the position at which the two
+ // prefix are different, since prefix 2 has only 20 bits
uint8_t len_diff;
if (a->len < b->len)
diff --git a/hicn-light/src/core/nameBitvector.h b/hicn-light/src/core/nameBitvector.h
index 28a31dc26..fb94f8f1a 100644
--- a/hicn-light/src/core/nameBitvector.h
+++ b/hicn-light/src/core/nameBitvector.h
@@ -25,7 +25,7 @@
struct name_bitvector;
typedef struct name_bitvector NameBitvector;
-NameBitvector *nameBitvector_CreateFromInAddr(uint32_t s_addr, uint8_t len);
+NameBitvector *nameBitvector_CreateFromInAddr(uint32_t addr, uint8_t len);
NameBitvector *nameBitvector_CreateFromIn6Addr(struct in6_addr *addr,
uint8_t len);
diff --git a/hicn-light/src/core/wldr.c b/hicn-light/src/core/wldr.c
index b94ae76e5..a3e8756dd 100644
--- a/hicn-light/src/core/wldr.c
+++ b/hicn-light/src/core/wldr.c
@@ -108,10 +108,10 @@ static void _wldr_SendWldrNotificaiton(Wldr *wldr, const Connection *conn,
// is identified by the src. if message is a data, we need to send the
// notification message with the content name has a source address in this way
// the message will be trapped by the pounting rules in the next hop We define
- // the notification as an interest message so that the NAT in the send function
- // will set the src address of the local connection. Notice that in this way
- // the notification packet will be dispaced to the right connection at the next
- // hop.
+ // the notification as an interest message so that the NAT in the send
+ // function will set the src address of the local connection. Notice that in
+ // this way the notification packet will be dispaced to the right connection
+ // at the next hop.
Message *notification =
message_CreateWldrNotification(message, expected_lbl, received_lbl);
diff --git a/hicn-light/src/io/hicnListener.c b/hicn-light/src/io/hicnListener.c
index 789face90..bcf4de6a3 100644
--- a/hicn-light/src/io/hicnListener.c
+++ b/hicn-light/src/io/hicnListener.c
@@ -55,22 +55,24 @@ struct hicn_listener {
PARCEvent *hicn_event;
int hicn_fd; // this is the file descriptor got from hicn library
- Address *localAddress; // this is the local address or 0::0 in case of the
- // main listener this is the address used inside
- // forwarder to identify the listener. Notice that this
- // address is the same as the fisical interfaces on
- // which we create the TUN. it is NOT the TUN address
- // which is given by libhicn after the bind operation
- // However the user alway uses this address since is
- // the only one available at configuration time
+ Address
+ *localAddress; // this is the local address or 0::0 in case of the
+ // main listener this is the address used inside
+ // forwarder to identify the listener. Notice that this
+ // address is the same as the fisical interfaces on
+ // which we create the TUN. it is NOT the TUN address
+ // which is given by libhicn after the bind operation
+ // However the user alway uses this address since is
+ // the only one available at configuration time
unsigned inetFamily;
int connection_id; // this is used only if the listener is used to receive
// data packets we assume that 1 connection is associated
- // to one listener in this case so we set the connection_id
- // we the connection is create. if this id is not set and a
- // data packet is received, the packet is dropped
+ // to one listener in this case so we set the
+ // connection_id we the connection is create. if this id
+ // is not set and a data packet is received, the packet is
+ // dropped
unsigned conn_id;
};
@@ -216,7 +218,7 @@ ListenerOps *hicnListener_CreateInet6(Forwarder *forwarder, char *symbolic,
// the call to libhicn is the same both for the main and the normal listeners
// in both cases we need to set only the identifier. In the case of normal
// listener (listener for data packet) we let the library select the right ip
- //address we just need to set the right type of packet
+ // address we just need to set the right type of packet
hicn_socket_helper_t *hicnSocketHelper =
forwarder_GetHicnSocketHelper(forwarder);
diff --git a/hicn-light/src/io/tcpListener.h b/hicn-light/src/io/tcpListener.h
index c5d1e33af..9664b32b0 100644
--- a/hicn-light/src/io/tcpListener.h
+++ b/hicn-light/src/io/tcpListener.h
@@ -25,7 +25,10 @@
#ifndef tcpListener_h
#define tcpListener_h
+#ifndef _WIN32
#include <netinet/in.h>
+#endif
+
#include <src/core/forwarder.h>
#include <src/io/listener.h>
#include <stdlib.h>
diff --git a/hicn-light/src/io/udpListener.c b/hicn-light/src/io/udpListener.c
index 31c0e673b..1a16d6161 100644
--- a/hicn-light/src/io/udpListener.c
+++ b/hicn-light/src/io/udpListener.c
@@ -13,14 +13,16 @@
* limitations under the License.
*/
+#ifndef _WIN32
#include <arpa/inet.h>
+#include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <src/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
#include <src/core/messageHandler.h>
@@ -83,13 +85,24 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
parcAssertFalse(udp->udp_socket < 0, "Error opening UDP socket: (%d) %s",
errno, strerror(errno));
+ int failure = 0;
+#ifndef _WIN32
// Set non-blocking flag
int flags = fcntl(udp->udp_socket, F_GETFL, NULL);
parcAssertTrue(flags != -1,
"fcntl failed to obtain file descriptor flags (%d)", errno);
- int failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK);
+ failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK);
parcAssertFalse(failure, "fcntl failed to set file descriptor flags (%d)",
errno);
+#else
+ // Set non-blocking flag
+ u_long mode = 1;
+ int result = ioctlsocket(udp->udp_socket, FIONBIO, &mode);
+ if (result != NO_ERROR) {
+ parcAssertTrue(result != NO_ERROR,
+ "ioctlsocket failed to set file descriptor");
+ }
+#endif
int one = 1;
// don't hang onto address after listener has closed
@@ -126,8 +139,11 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder,
myerrno, strerror(myerrno));
parcMemory_Deallocate((void **)&str);
}
-
+#ifndef _WIN32
close(udp->udp_socket);
+#else
+ closesocket(udp->udp_socket);
+#endif
addressDestroy(&udp->localAddress);
logger_Release(&udp->logger);
parcMemory_Deallocate((void **)&udp);
@@ -152,13 +168,23 @@ ListenerOps *udpListener_CreateInet(Forwarder *forwarder,
parcAssertFalse(udp->udp_socket < 0, "Error opening UDP socket: (%d) %s",
errno, strerror(errno));
+ int failure = 0;
+#ifndef _WIN32
// Set non-blocking flag
int flags = fcntl(udp->udp_socket, F_GETFL, NULL);
parcAssertTrue(flags != -1,
"fcntl failed to obtain file descriptor flags (%d)", errno);
- int failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK);
+ failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK);
parcAssertFalse(failure, "fcntl failed to set file descriptor flags (%d)",
errno);
+#else
+ u_long mode = 1;
+ int result = ioctlsocket(udp->udp_socket, FIONBIO, &mode);
+ if (result != NO_ERROR) {
+ parcAssertTrue(result != NO_ERROR,
+ "ioctlsocket failed to set file descriptor");
+ }
+#endif
int one = 1;
// don't hang onto address after listener has closed
@@ -217,7 +243,12 @@ static void udpListener_Destroy(UdpListener **listenerPtr) {
"UdpListener %p destroyed", (void *)udp);
}
+#ifndef _WIN32
close(udp->udp_socket);
+#else
+ closesocket(udp->udp_socket);
+#endif
+
addressDestroy(&udp->localAddress);
dispatcher_DestroyNetworkEvent(forwarder_GetDispatcher(udp->forwarder),
&udp->udp_event);
@@ -276,7 +307,8 @@ static size_t _peekMessageLength(UdpListener *udp, int fd,
size_t packetLength = 0;
- uint8_t fixedHeader[messageHandler_GetIPHeaderLength(IPv6)];
+ uint8_t *fixedHeader = (uint8_t *)malloc(
+ sizeof(uint8_t) * messageHandler_GetIPHeaderLength(IPv6));
// peek at the UDP packet and read in the fixed header.
// Also returns the socket information for the remote peer
@@ -294,6 +326,8 @@ static size_t _peekMessageLength(UdpListener *udp, int fd,
}
}
+ free(fixedHeader);
+
return packetLength;
}
diff --git a/hicn-light/src/io/udpListener.h b/hicn-light/src/io/udpListener.h
index 1cf3bd887..14c03fd52 100644
--- a/hicn-light/src/io/udpListener.h
+++ b/hicn-light/src/io/udpListener.h
@@ -16,7 +16,10 @@
#ifndef udpListener_h
#define udpListener_h
+#ifndef _WIN32
#include <netinet/in.h>
+#endif
+
#include <src/core/forwarder.h>
#include <src/io/listener.h>
#include <stdlib.h>
diff --git a/hicn-light/src/platforms/CMakeLists.txt b/hicn-light/src/platforms/CMakeLists.txt
index fcb4282ba..191a72213 100644
--- a/hicn-light/src/platforms/CMakeLists.txt
+++ b/hicn-light/src/platforms/CMakeLists.txt
@@ -25,6 +25,15 @@ elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/linux/system.c
)
+elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
+ list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/windows/system.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/windows/win_portability.c
+ )
+ list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/windows/win_portability.h
+ )
+
endif()
set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
diff --git a/hicn-light/src/platforms/windows/system.c b/hicn-light/src/platforms/windows/system.c
new file mode 100644
index 000000000..a23b7d95e
--- /dev/null
+++ b/hicn-light/src/platforms/windows/system.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <parc/assert/parc_Assert.h>
+#include <src/config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sys/types.h>
+
+#include <errno.h>
+#include <string.h>
+
+#define WORKING_BUFFER_SIZE 15000
+#define MAX_TRIES 3
+
+#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
+#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
+
+#include <src/core/forwarder.h>
+#include <src/utils/interfaceSet.h>
+
+#include <src/utils/addressList.h>
+
+/**
+ * Returns the MTU for a named interface
+ *
+ * On linux, we get the MTU by opening a socket and reading SIOCGIFMTU
+ *
+ * @param [in] ifname Interface name (e.g. "eth0")
+ *
+ * @retval number The MTU in bytes
+ *
+ * Example:
+ * @code
+ * <#example#>
+ * @endcode
+ */
+static int getMtu(const char *ifname) {
+ PIP_ADAPTER_ADDRESSES pAddresses = NULL;
+ PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
+ ULONG outBufLen = 0;
+ ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
+ ULONG family = AF_UNSPEC;
+
+ DWORD dwSize = 0;
+ DWORD dwRetVal = 0;
+ ULONG Iterations = 0;
+ do {
+ pAddresses = (IP_ADAPTER_ADDRESSES *)MALLOC(outBufLen);
+ if (pAddresses == NULL) {
+ printf("Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
+ exit(1);
+ }
+
+ dwRetVal =
+ GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
+
+ if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
+ FREE(pAddresses);
+ pAddresses = NULL;
+ } else {
+ break;
+ }
+
+ Iterations++;
+
+ } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (Iterations < MAX_TRIES));
+
+ if (dwRetVal == NO_ERROR) {
+ pCurrAddresses = pAddresses;
+ while (pCurrAddresses) {
+ if (strcmp(pCurrAddresses->AdapterName, ifname)) {
+ int mtu = pCurrAddresses->Mtu;
+ if (pAddresses) {
+ FREE(pAddresses);
+ }
+ return mtu;
+ }
+ pCurrAddresses = pCurrAddresses->Next;
+ }
+ }
+
+ if (pAddresses) {
+ FREE(pAddresses);
+ }
+ return -1;
+}
+
+InterfaceSet *system_Interfaces(Forwarder *forwarder) {
+ InterfaceSet *set = interfaceSetCreate();
+
+ Logger *logger = forwarder_GetLogger(forwarder);
+
+ DWORD dwSize = 0;
+ DWORD dwRetVal = 0;
+ unsigned int i = 0;
+ // Set the flags to pass to GetAdaptersAddresses
+ ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
+
+ // default to unspecified address family (both)
+ ULONG family = AF_UNSPEC;
+
+ LPVOID lpMsgBuf = NULL;
+
+ PIP_ADAPTER_ADDRESSES pAddresses = NULL;
+ ULONG outBufLen = 0;
+ ULONG Iterations = 0;
+
+ PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
+ PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
+ PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL;
+ PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL;
+ IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
+ IP_ADAPTER_PREFIX *pPrefix = NULL;
+
+ outBufLen = WORKING_BUFFER_SIZE;
+
+ do {
+ pAddresses = (IP_ADAPTER_ADDRESSES *)MALLOC(outBufLen);
+ parcAssertNotNull(
+ pAddresses,
+ "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
+ dwRetVal =
+ GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
+
+ if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
+ FREE(pAddresses);
+ pAddresses = NULL;
+ } else {
+ break;
+ }
+
+ Iterations++;
+
+ } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (Iterations < MAX_TRIES));
+ if (dwRetVal == NO_ERROR) {
+ // If successful, output some information from the data we received
+ pCurrAddresses = pAddresses;
+ while (pCurrAddresses) {
+ if (pCurrAddresses->OperStatus == IfOperStatusUp) {
+ Interface *iface =
+ interfaceSetGetByName(set, pCurrAddresses->AdapterName);
+ if (iface == NULL) {
+ pMulticast = pCurrAddresses->FirstMulticastAddress;
+ if (pMulticast) {
+ for (i = 0; pMulticast != NULL; i++) pMulticast = pMulticast->Next;
+ }
+
+ iface = interfaceCreate(
+ pCurrAddresses->AdapterName,
+ forwarder_GetNextConnectionId(forwarder),
+ pCurrAddresses->IfType == IF_TYPE_SOFTWARE_LOOPBACK, i > 0,
+ pCurrAddresses->Mtu);
+
+ interfaceSetAdd(set, iface);
+ for (pUnicast = pCurrAddresses->FirstUnicastAddress; pUnicast != NULL;
+ pUnicast = pUnicast->Next) {
+ int family = pUnicast->Address.lpSockaddr->sa_family;
+
+ switch (family) {
+ case AF_INET: {
+ char *ip = inet_ntoa(
+ ((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))
+ ->sin_addr);
+ Address *address = addressCreateFromInet(
+ (struct sockaddr_in *)(pUnicast->Address.lpSockaddr));
+ interfaceAddAddress(iface, address);
+ break;
+ }
+
+ case AF_INET6: {
+ char str[INET6_ADDRSTRLEN];
+ inet_ntop(
+ AF_INET6,
+ &((struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr))
+ ->sin6_addr,
+ str, INET6_ADDRSTRLEN);
+ Address *address = addressCreateFromInet6(
+ (struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr));
+ interfaceAddAddress(iface, address);
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
+ }
+ }
+ pCurrAddresses = pCurrAddresses->Next;
+ }
+ }
+
+ if (pAddresses) {
+ FREE(pAddresses);
+ }
+ return set;
+}
+
+Address *system_GetMacAddressByName(Forwarder *forwarder,
+ const char *interfaceName) {
+ return NULL;
+}
+
+unsigned system_InterfaceMtu(Forwarder *forwarder, const char *interfaceName) {
+ unsigned mtu = 0;
+
+ return mtu;
+}
diff --git a/hicn-light/src/platforms/windows/win_portability.c b/hicn-light/src/platforms/windows/win_portability.c
new file mode 100644
index 000000000..cc592cd4b
--- /dev/null
+++ b/hicn-light/src/platforms/windows/win_portability.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <src/platforms/windows/win_portability.h>
+
+int getline(char **lineptr, size_t *n, FILE *stream) {
+ static char line[256];
+ char *ptr;
+ unsigned int len;
+
+ if (lineptr == NULL || n == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (ferror(stream)) return -1;
+
+ if (feof(stream)) return -1;
+
+ fgets(line, 256, stream);
+
+ ptr = strchr(line, '\n');
+ if (ptr) *ptr = '\0';
+
+ len = (unsigned int)strlen(line);
+
+ if ((len + 1) < 256) {
+ ptr = (char *)realloc(*lineptr, 256);
+ if (ptr == NULL) return (-1);
+ *lineptr = ptr;
+ *n = 256;
+ }
+
+ strcpy(*lineptr, line);
+ return (len);
+} \ No newline at end of file
diff --git a/hicn-light/src/platforms/windows/win_portability.h b/hicn-light/src/platforms/windows/win_portability.h
new file mode 100644
index 000000000..e4e32b35a
--- /dev/null
+++ b/hicn-light/src/platforms/windows/win_portability.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#define WIN32_LEAN_AND_MEAN
+#include <afunix.h>
+#include <assert.h>
+#include <errno.h>
+#include <in6addr.h>
+#include <io.h>
+#include <iphlpapi.h>
+#include <process.h>
+#include <stdio.h>
+#include <windows.h>
+#include <winnt.h>
+#include <winsock2.h>
+#include <winternl.h>
+#include <ws2tcpip.h>
+#pragma comment(lib, "IPHLPAPI.lib")
+#include <parc/windows/parc_Utils.h>
+
+#ifndef in_port_t
+#define in_port_t uint16_t
+#endif
+
+#ifndef in_addr_t
+#define in_addr_t uint32_t
+#endif
+
+#ifndef strncasecmp
+#define strncasecmp _strnicmp
+#endif
+
+#ifndef strcasecmp
+#define strcasecmp _stricmp
+#endif
+
+#define HAVE_STRUCT_TIMESPEC
+
+#ifndef getline
+int getline(char **lineptr, size_t *n, FILE *stream);
+#endif \ No newline at end of file
diff --git a/hicn-light/src/utils/address.c b/hicn-light/src/utils/address.c
index 3f6fe2591..ee1167de0 100644
--- a/hicn-light/src/utils/address.c
+++ b/hicn-light/src/utils/address.c
@@ -13,12 +13,13 @@
* limitations under the License.
*/
+#ifndef _WIN32
#include <arpa/inet.h>
+#include <unistd.h>
+#endif
#include <errno.h>
#include <src/config.h>
#include <stdio.h>
-#include <strings.h>
-#include <unistd.h>
#include <src/utils/address.h>
diff --git a/hicn-light/src/utils/address.h b/hicn-light/src/utils/address.h
index a98d15084..d8b0efcab 100644
--- a/hicn-light/src/utils/address.h
+++ b/hicn-light/src/utils/address.h
@@ -33,9 +33,11 @@
#ifndef address_h
#define address_h
+#ifndef _WIN32
#include <netinet/in.h>
-#include <stdbool.h>
#include <sys/un.h>
+#endif
+#include <stdbool.h>
#include <parc/algol/parc_Buffer.h>
#include <parc/algol/parc_BufferComposer.h>
diff --git a/hicn-light/src/utils/commands.h b/hicn-light/src/utils/commands.h
index 2f8ebcbfe..e276d8dd2 100644
--- a/hicn-light/src/utils/commands.h
+++ b/hicn-light/src/utils/commands.h
@@ -23,10 +23,14 @@
#ifndef commands_h
#define commands_h
+#ifndef _WIN32
#include <netinet/in.h>
+#include <sys/socket.h>
+#endif
+#include <src/config.h>
+
#include <stdint.h>
#include <stdlib.h>
-#include <sys/socket.h>
typedef struct in6_addr ipv6_addr_t;
typedef uint32_t ipv4_addr_t;
diff --git a/hicn-light/src/utils/utils.c b/hicn-light/src/utils/utils.c
index a41478a4b..3ab837eeb 100644
--- a/hicn-light/src/utils/utils.c
+++ b/hicn-light/src/utils/utils.c
@@ -1,17 +1,19 @@
// Utility function for commands
-#include <ctype.h>
+#ifndef _WIN32
#include <netinet/in.h>
-#include <pthread.h>
+#endif
+
+#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
#include <parc/assert/parc_Assert.h>
+#include <pthread.h>
#include <src/utils/utils.h>
// This is the unique sequence number used by all messages and its thread locks