From f47aae46056733c0b0d04ebdb09548e4a7ddf3d7 Mon Sep 17 00:00:00 2001 From: MissValeska Date: Sat, 7 Jun 2014 04:52:30 -0700 Subject: [PATCH] Ugh! This console "should" work, But it doesn't! I tested the same thing and was able to get it to work in another file! Something about these functions and what ever is causing a segmentation fault! fgets is not setting request, Even though it does in my test file! Anyway, I'll keep working on this, However, I have been working on this for a while, I would appreciate any help anyone would like to give! Thank you for reading! --- src/Ntk-Console/Netsukuku-Console.c | 96 +++++++++++++++-------------- src/Ntk-Console/Netsukuku-Console.h | 9 +-- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/Ntk-Console/Netsukuku-Console.c b/src/Ntk-Console/Netsukuku-Console.c index e39bd03..c8f1f16 100644 --- a/src/Ntk-Console/Netsukuku-Console.c +++ b/src/Ntk-Console/Netsukuku-Console.c @@ -1,8 +1,12 @@ #include "Netsukuku-Console.h" -int validity_check(void) { - - if(request && strncmp(request, "null", (int)strlen(request)) != 0) { +char *response; + +void usage(); + +void clean_up(); + +int validity_check(char *request) { if(strncmp(request,"help", (int)strlen(request)) == 0) return 1; @@ -47,14 +51,13 @@ int validity_check(void) { printf("Incorrect or unreadable command, Please correct it.\n"); return -1; } - } return -2; } /* this function is run by the second thread */ -void ntkd_request(void) { +void ntkd_request(char *request) { rc = sendto(sockfd1, request, strlen(request), 0, (struct sockaddr *)&serveraddr, (socklen_t)sizeof(&serveraddr)); if (rc < 0) { @@ -128,65 +131,43 @@ void console_uptime(void) { } -void console(void) { +void console(char *request) { - char request_buf[16]; - - exit_now = 1; - - while(exit_now == 1) { - printf("\n>"); + printf("%s", request); - fgets(request_buf, 16, stdin); - - strcpy(request, request_buf); - - if(validity_check() == -2) + if(validity_check(request) == -2) printf("Error: Command has not been processed!"); - if(validity_check() == -1) + if(validity_check(request) == -1) usage(); - if(strncmp(request,"quit", (int)strlen(request)) == 0) { - exit_now = 2; + if(strncmp(request,"quit", (int)strlen(request)) == 0) { clean_up(); exit(0); } - if(validity_check() == 0) - ntkd_request(); + if(validity_check(request) == 0) + ntkd_request(request); - if(validity_check() == 1) + if(validity_check(request) == 1) usage(); - if(validity_check() == 2) - system("ntkd -k"); + if(validity_check(request) == 2) + /*system("ntkd -k");*/ + printf(""); - if(validity_check() == 3) { + if(validity_check(request) == 3) { printf("%s", VERSION_STR); - ntkd_request(); + ntkd_request(request); } - if(validity_check() == 4) - console_uptime(); - } + if(validity_check(request) == 4) + console_uptime(); } int main(void) { - - char request_buf[16]; - printf("\n>"); - - fgets(request_buf, 16, stdin); - - printf("uhm: %s", request_buf); - - sendrecv = 0; - - /*request = "null";*/ - - time(&rawtime); + /*time(&rawtime); timeinfo = localtime(&rawtime); @@ -199,9 +180,32 @@ int main(void) { opensocket(); - printf("This is the Netsukuku Console, Please type 'help' for more information.\n"); - - console(); + printf("This is the Netsukuku Console, Please type 'help' for more information.\n");*/ + + char *request; + + int exit_now; + + exit_now = 1; + + while(exit_now == 1) { + + printf("\n>"); + + fgets(request, 16, stdin); + + perror("fgets failed"); + + fflush(stdin); + + printf("%s", request); + + request[strlen(request)-1] = '\0'; + + printf("%s", request); + + /*console(request);*/ + } return 0; } diff --git a/src/Ntk-Console/Netsukuku-Console.h b/src/Ntk-Console/Netsukuku-Console.h index 6285a74..a3daf11 100644 --- a/src/Ntk-Console/Netsukuku-Console.h +++ b/src/Ntk-Console/Netsukuku-Console.h @@ -16,11 +16,10 @@ #define VERSION_STR "0.0.1" #define FALSE 0 -int sockfd, sockfd1, sendrecv; +int sockfd, sockfd1; struct sockaddr_un serveraddr; struct sockaddr ntkdaddr; -int rc, length, exit_now; -char *request, *response; +int rc; time_t rawtime; struct tm *timeinfo; @@ -32,8 +31,6 @@ int uptime_day; int uptime_month; int uptime_year; -void usage(); - -void clean_up(); +int i; #endif /*NETSUKUKUCONSOLE_H*/ \ No newline at end of file