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!

This commit is contained in:
MissValeska 2014-06-07 04:52:30 -07:00
parent a7b9b6cf51
commit f47aae4605
2 changed files with 53 additions and 52 deletions

View File

@ -1,8 +1,12 @@
#include "Netsukuku-Console.h"
int validity_check(void) {
char *response;
if(request && strncmp(request, "null", (int)strlen(request)) != 0) {
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];
printf("%s", request);
exit_now = 1;
while(exit_now == 1) {
printf("\n>");
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)
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");
printf("This is the Netsukuku Console, Please type 'help' for more information.\n");*/
console();
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;
}

View File

@ -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*/