I used the defines BUFFER_LENGTH and REQUEST_LENGTH instead of 250 in the console client and bindings.

This commit is contained in:
MissValeska 2014-08-17 00:06:22 -07:00
parent b13c3bf5de
commit 17aa8921b3
2 changed files with 22 additions and 16 deletions

View File

@ -1,12 +1,12 @@
#include "Netsukuku-Console.h"
char response[250];
char response[BUFFER_LENGTH];
void usage();
void clean_up();
int validity_check(char request) {
int validity_check(char request[BUFFER_LENGTH]) {
if(strncmp(request,"help", (int)strlen(request)) == 0)
return 1;
@ -23,6 +23,9 @@ int validity_check(char request) {
else if(strncmp(request,"console_uptime", (int)strlen(request)) == 0)
return 4;
else if(strlen(request) > 250)
return 5;
else if(strncmp(request,"inet_connected", (int)strlen(request)) == 0)
return 0;
@ -56,7 +59,7 @@ int validity_check(char request) {
}
void response_cleanup(char response[250]) {
void response_cleanup(char response[BUFFER_LENGTH]) {
char remove = 'a';
@ -73,7 +76,7 @@ void response_cleanup(char response[250]) {
}
/* Sends and receives to ntkd */
void ntkd_request(char request) {
void ntkd_request(char request[BUFFER_LENGTH]) {
int request_length;
@ -85,7 +88,7 @@ void ntkd_request(char request) {
request_length = (int)strlen(request);
memset(request, 'a', 250 - request_length);
memset(request, 'a', BUFFER_LENGTH - request_length);
rc = send(sockfd, request, sizeof(request), 0);
if (rc < 0) {
perror("send() failed");
@ -158,10 +161,10 @@ void console_uptime(void) {
}
void console(char request) {
void console(char request[BUFFER_LENGTH]) {
if(validity_check(request) == -2)
printf("Error: Command has not been processed!");
printf("Error: Command has not been processed!\n");
if(validity_check(request) == -1)
usage();
@ -181,12 +184,15 @@ void console(char request) {
system("ntkd -k");
if(validity_check(request) == 3) {
printf("Ntk-Console Version: %s", VERSION_STR);
printf("Ntk-Console Version: %s\n", VERSION_STR);
ntkd_request(request);
}
if(validity_check(request) == 4)
console_uptime();
if(validity_check(request) == 5)
printf("Error: Command longer than 250 bytes.\n");
}
int main(void) {
@ -208,11 +214,11 @@ int main(void) {
char request;
request = (char)malloc(512);
request = (char)malloc(BUFFER_LENGTH);
char *request1;
request1 = (char*)malloc(512);
request1 = (char*)malloc(BUFFER_LENGTH);
do {

View File

@ -78,11 +78,11 @@ void opensocket(void) {
/* Sends a parsed response to the ntk console client. */
void send_response(char response) {
void send_response(char response[REQUEST_LENGTH]) {
int response_length;
response_length = (int)strlen(response);
memset(response, 'a', 250 - response_length);
memset(response, 'a', REQUEST_LENGTH - response_length);
rc = send(sockfd_2, response, sizeof(response), 0);
if (rc < 0){
perror("send() failed");
@ -91,7 +91,7 @@ void send_response(char response) {
}
void request_cleanup(char unprocessed_request) {
void request_cleanup(char unprocessed_request[REQUEST_LENGTH]) {
char remove = 'a';
@ -114,7 +114,7 @@ void request_cleanup(char unprocessed_request) {
* to data from ntkd structures such as: me
* into a response for the ntk console client. */
int request_processing(char unprocessed_request) {
int request_processing(char unprocessed_request[REQUEST_LENGTH]) {
if(strncmp(unprocessed_request,"uptime", (int)strlen(unprocessed_request)) == 0)
send_response((char)time(0)-me.uptime);