From e4eca848c8d95f48652096284fd8e2752ed1a316 Mon Sep 17 00:00:00 2001 From: michele papalini Date: Thu, 9 Jan 2020 14:55:32 +0100 Subject: [HICN-469] execute hicn-light-control from remote Signed-off-by: michele papalini Change-Id: I2a23a5f7648614213b83e2409e2ff3784b083758 Signed-off-by: michele papalini --- hicn-light/src/hicn/config/configurationFile.c | 3 ++- hicn-light/src/hicn/config/controlRoot.c | 4 ++-- hicn-light/src/hicn/config/controlState.c | 16 +++++++--------- hicn-light/src/hicn/config/controlState.h | 6 +++++- 4 files changed, 16 insertions(+), 13 deletions(-) (limited to 'hicn-light/src/hicn/config') diff --git a/hicn-light/src/hicn/config/configurationFile.c b/hicn-light/src/hicn/config/configurationFile.c index adc089396..3cce740ac 100644 --- a/hicn-light/src/hicn/config/configurationFile.c +++ b/hicn-light/src/hicn/config/configurationFile.c @@ -210,7 +210,8 @@ ConfigurationFile *configurationFile_Create(Forwarder *forwarder, // because // writeRead still not implemented from configuration file. configFile->controlState = - controlState_Create(configFile, _writeRead, false); + controlState_Create(configFile, _writeRead, false, + SRV_CTRL_IP, SRV_CTRL_PORT); // we do not register Help commands controlState_RegisterCommand(configFile->controlState, diff --git a/hicn-light/src/hicn/config/controlRoot.c b/hicn-light/src/hicn/config/controlRoot.c index e135dfc50..8c8cc1804 100644 --- a/hicn-light/src/hicn/config/controlRoot.c +++ b/hicn-light/src/hicn/config/controlRoot.c @@ -62,11 +62,11 @@ static CommandReturn _controlRoot_HelpExecute(CommandParser *parser, CommandOps *ops, PARCList *args) { printf("Command-line execution:\n"); printf( - " controller [--keystore ] [--password ] " + " controller [--server ] [--port ] " "command\n"); printf("\n"); printf("Interactive execution:\n"); - printf(" controller [--keystore ] [--password ]\n"); + printf(" controller [--server ] [--port ]\n"); printf("\n"); printf( "If the keystore is not specified, the default path is used. Keystore " diff --git a/hicn-light/src/hicn/config/controlState.c b/hicn-light/src/hicn/config/controlState.c index 6cd1b905d..2df8805c6 100644 --- a/hicn-light/src/hicn/config/controlState.c +++ b/hicn-light/src/hicn/config/controlState.c @@ -37,9 +37,6 @@ #include -#define SRV_IP "127.0.0.1" -#define PORT 9695 - struct controller_state { CommandParser *parser; bool debugFlag; @@ -51,7 +48,7 @@ struct controller_state { bool isInteractive; }; -int controlState_connectToFwdDeamon() { +int controlState_connectToFwdDeamon(char *server_ip, uint16_t port) { int sockfd; struct sockaddr_in servaddr; @@ -64,8 +61,8 @@ int controlState_connectToFwdDeamon() { // Filling server information servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(PORT); - inet_pton(AF_INET, SRV_IP, &(servaddr.sin_addr.s_addr)); + servaddr.sin_port = htons(port); + inet_pton(AF_INET, server_ip, &(servaddr.sin_addr.s_addr)); // Establish connection if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { @@ -79,7 +76,8 @@ int controlState_connectToFwdDeamon() { ControlState *controlState_Create( void *userdata, struct iovec *(*writeRead)(ControlState *state, struct iovec *msg), - bool openControllerConnetion) { + bool openControllerConnetion, + char *server_ip, uint16_t port) { ControlState *state = parcMemory_AllocateAndClear(sizeof(ControlState)); parcAssertNotNull(state, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(ControlState)); @@ -92,7 +90,7 @@ ControlState *controlState_Create( state->isInteractive = true; if (openControllerConnetion) { - state->sockfd = controlState_connectToFwdDeamon(); + state->sockfd = controlState_connectToFwdDeamon(server_ip, port); } else { state->sockfd = 2; // stderr } @@ -235,4 +233,4 @@ bool controlState_isConfigFile(ControlState *state) { } else { return true; } -} \ No newline at end of file +} diff --git a/hicn-light/src/hicn/config/controlState.h b/hicn-light/src/hicn/config/controlState.h index 25542657f..cc38cbe37 100644 --- a/hicn-light/src/hicn/config/controlState.h +++ b/hicn-light/src/hicn/config/controlState.h @@ -32,6 +32,9 @@ #include +#define SRV_CTRL_IP "127.0.0.1" +#define SRV_CTRL_PORT 9695 + struct controller_state; typedef struct controller_state ControlState; @@ -59,7 +62,8 @@ typedef struct controller_state ControlState; ControlState *controlState_Create( void *userdata, struct iovec *(*writeRead)(ControlState *state, struct iovec *msg), - bool openControllerConnetion); + bool openControllerConnetion, + char * server_ip, uint16_t port); /** * Destroys the control state, closing all network connections -- cgit 1.2.3-korg