ntk-console: Begin returning valid results in ntk-console-server

This commit is contained in:
Alexander von Gluck IV 2014-09-15 18:06:26 -05:00
parent 2694b1cda4
commit cea41ed409
2 changed files with 19 additions and 12 deletions

View File

@ -94,41 +94,48 @@ send_response(int session_fd, char response[CONSOLE_BUFFER_LENGTH], ...)
static void static void
request_processing(int session_fd, cmd_packet_t packet) request_processing(int session_fd, cmd_packet_t packet)
{ {
char buffer[CONSOLE_BUFFER_LENGTH];
int maxBuffer = CONSOLE_BUFFER_LENGTH - 1;
switch (packet.command) { switch (packet.command) {
case COMMAND_UPTIME: case COMMAND_UPTIME:
send_response(session_fd, (char)time(0)-me.uptime); {
int uptime = time(0) - me.uptime;
snprintf(buffer, maxBuffer, "node uptime: %d seconds", uptime);
break; break;
}
case COMMAND_VERSION: case COMMAND_VERSION:
send_response(session_fd, VERSION_STR); snprintf(buffer, maxBuffer, "ntkd version: %s", VERSION_STR);
break; break;
case COMMAND_CURIFS: case COMMAND_CURIFS:
send_response(session_fd, (char)me.cur_ifs); //send_response(session_fd, (char)me.cur_ifs);
break; break;
case COMMAND_CURIFSCT: case COMMAND_CURIFSCT:
send_response(session_fd, (char)me.cur_ifs_n); snprintf(buffer, maxBuffer, "current interface count: %d", me.cur_ifs_n);
break; break;
case COMMAND_INETCONN: case COMMAND_INETCONN:
send_response(session_fd, (char)me.inet_connected); //send_response(session_fd, (char)me.inet_connected);
break; break;
case COMMAND_CURQSPNID: case COMMAND_CURQSPNID:
send_response(session_fd, (char)me.cur_qspn_id); //send_response(session_fd, (char)me.cur_qspn_id);
break; break;
case COMMAND_CURIP: case COMMAND_CURIP:
send_response(session_fd, (char)me.cur_ip.data); //send_response(session_fd, (char)me.cur_ip.data);
break; break;
case COMMAND_CURNODE: case COMMAND_CURNODE:
send_response(session_fd, (char)me.cur_node); //send_response(session_fd, (char)me.cur_node);
break; break;
case COMMAND_IFS: case COMMAND_IFS:
send_response(session_fd, "IFS: TODO"); //send_response(session_fd, "IFS: TODO");
break; break;
case COMMAND_IFSCT: case COMMAND_IFSCT:
send_response(session_fd, "IFS: TODO"); //send_response(session_fd, "IFS: TODO");
break; break;
default: default:
send_response(session_fd, "Provided command is invalid or yet to be implemented."); snprintf(buffer, maxBuffer, "Provided command is invalid or not implemented in this API");
break; break;
} }
send_response(session_fd, buffer);
} }

View File

@ -158,7 +158,7 @@ ntkd_request(command_t command)
exit(-1); exit(-1);
} }
printf("Response: '%s'\n", response); printf("%s\n", response);
free(response); free(response);
closesocket(); closesocket();
} }