diff options
Diffstat (limited to 'hicn-light/src/hicn/config/controlAddListener.c')
-rw-r--r-- | hicn-light/src/hicn/config/controlAddListener.c | 55 |
1 files changed, 12 insertions, 43 deletions
diff --git a/hicn-light/src/hicn/config/controlAddListener.c b/hicn-light/src/hicn/config/controlAddListener.c index c9253425a..cfd061131 100644 --- a/hicn-light/src/hicn/config/controlAddListener.c +++ b/hicn-light/src/hicn/config/controlAddListener.c @@ -58,27 +58,26 @@ static const int _indexProtocol = 2; static const int _indexSymbolic = 3; static const int _indexAddress = 4; static const int _indexPort = 5; -#ifdef __linux__ static const int _indexInterfaceName = 6; -#endif static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser, CommandOps *ops, PARCList *args) { printf("commands:\n"); - printf(" add listener hicn <symbolic> <localAddress> \n"); #ifdef __linux__ + printf(" add listener hicn <symbolic> <localAddress> \n"); +#endif printf(" add listener udp <symbolic> <localAddress> <port> <interface>\n"); printf(" add listener tcp <symbolic> <localAddress> <port> <interface>\n"); -#else - printf(" add listener udp <symbolic> <localAddress> <port>\n"); - printf(" add listener tcp <symbolic> <localAddress> <port>\n"); -#endif printf("\n"); printf( " symbolic: User defined name for listener, must start with " "alpha and be alphanum\n"); +#ifdef __linux__ printf(" protocol: hicn | udp\n"); +#else + printf(" protocol: udp\n"); +#endif printf( " localAddress: IPv4 or IPv6 address (or prefix protocol = hicn) " "assigend to the local interface\n"); @@ -88,23 +87,18 @@ static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser, printf("\n"); printf("Notes:\n"); printf(" The symblic name must be unique or the source will reject it.\n"); +#ifdef __linux__ printf( - " If protocol = hinc: the address 0::0 indicates the main listern, " + " If protocol = hicn: the address 0::0 indicates the main listern, " "for which we can set punting rules.\n"); +#endif return CommandReturn_Success; } -#ifdef __linux__ -static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops, - const char *symbolic, const char *addr, - const char *port, const char *interfaceName, listener_mode mode, - connection_type type) { -#else static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops, const char *symbolic, const char *addr, - const char *port, listener_mode mode, + const char *port, char *interfaceName, listener_mode mode, connection_type type) { -#endif ControlState *state = ops->closure; // allocate command payload @@ -126,9 +120,7 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops, } // Fill remaining payload fields -#ifdef __linux__ memcpy(addListenerCommand->interfaceName, interfaceName, 16); -#endif addListenerCommand->listenerMode = mode; addListenerCommand->connectionType = type; addListenerCommand->port = htons((uint16_t)atoi(port)); @@ -149,11 +141,7 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops, static CommandReturn _controlAddListener_Execute(CommandParser *parser, CommandOps *ops, PARCList *args) { -#ifdef __linux__ if (parcList_Size(args) != 5 && parcList_Size(args) != 7) { -#else - if (parcList_Size(args) != 5 && parcList_Size(args) != 6) { -#endif _controlAddListener_HelpExecute(parser, ops, args); return CommandReturn_Failure; } @@ -169,45 +157,26 @@ static CommandReturn _controlAddListener_Execute(CommandParser *parser, return result; } - const char *host = parcList_GetAtIndex(args, _indexAddress); -#ifdef __linux__ - const char *interfaceName = parcList_GetAtIndex(args, _indexInterfaceName); -#endif const char *protocol = parcList_GetAtIndex(args, _indexProtocol); - + const char *host = parcList_GetAtIndex(args, _indexAddress); + char *interfaceName = parcList_GetAtIndex(args, _indexInterfaceName); if ((strcasecmp("hicn", protocol) == 0)) { const char *port = "1234"; // this is a random port number that will be ignored // here we discard the prefix len if it exists, since we don't use it in // code but we let libhicn to find the right ip address. -#ifdef __linux__ return _CreateListener(parser, ops, symbolic, host, port, "hicn", HICN_MODE, HICN_CONN); -#else - return _CreateListener(parser, ops, symbolic, host, port, HICN_MODE, - HICN_CONN); -#endif } - const char *port = parcList_GetAtIndex(args, _indexPort); if ((strcasecmp("udp", protocol) == 0)) { -#ifdef __linux__ return _CreateListener(parser, ops, symbolic, host, port, interfaceName, IP_MODE, UDP_CONN); -#else - return _CreateListener(parser, ops, symbolic, host, port, IP_MODE, - UDP_CONN); -#endif } else if ((strcasecmp("tcp", protocol) == 0)) { -#ifdef __linux__ return _CreateListener(parser, ops, symbolic, host, port, interfaceName, IP_MODE, TCP_CONN); -#else - return _CreateListener(parser, ops, symbolic, host, port, IP_MODE, - TCP_CONN); -#endif } else { _controlAddListener_HelpExecute(parser, ops, args); return CommandReturn_Failure; |