mirror of
https://github.com/ChronosX88/netsukuku.git
synced 2024-11-26 04:02:19 +00:00
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:
parent
a7b9b6cf51
commit
f47aae4605
@ -1,8 +1,12 @@
|
|||||||
#include "Netsukuku-Console.h"
|
#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)
|
if(strncmp(request,"help", (int)strlen(request)) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -47,14 +51,13 @@ int validity_check(void) {
|
|||||||
printf("Incorrect or unreadable command, Please correct it.\n");
|
printf("Incorrect or unreadable command, Please correct it.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function is run by the second thread */
|
/* 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));
|
rc = sendto(sockfd1, request, strlen(request), 0, (struct sockaddr *)&serveraddr, (socklen_t)sizeof(&serveraddr));
|
||||||
if (rc < 0) {
|
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;
|
if(validity_check(request) == -2)
|
||||||
|
|
||||||
while(exit_now == 1) {
|
|
||||||
printf("\n>");
|
|
||||||
|
|
||||||
fgets(request_buf, 16, stdin);
|
|
||||||
|
|
||||||
strcpy(request, request_buf);
|
|
||||||
|
|
||||||
if(validity_check() == -2)
|
|
||||||
printf("Error: Command has not been processed!");
|
printf("Error: Command has not been processed!");
|
||||||
|
|
||||||
if(validity_check() == -1)
|
if(validity_check(request) == -1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if(strncmp(request,"quit", (int)strlen(request)) == 0) {
|
if(strncmp(request,"quit", (int)strlen(request)) == 0) {
|
||||||
exit_now = 2;
|
|
||||||
clean_up();
|
clean_up();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(validity_check() == 0)
|
if(validity_check(request) == 0)
|
||||||
ntkd_request();
|
ntkd_request(request);
|
||||||
|
|
||||||
if(validity_check() == 1)
|
if(validity_check(request) == 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if(validity_check() == 2)
|
if(validity_check(request) == 2)
|
||||||
system("ntkd -k");
|
/*system("ntkd -k");*/
|
||||||
|
printf("");
|
||||||
|
|
||||||
if(validity_check() == 3) {
|
if(validity_check(request) == 3) {
|
||||||
printf("%s", VERSION_STR);
|
printf("%s", VERSION_STR);
|
||||||
ntkd_request();
|
ntkd_request(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(validity_check() == 4)
|
if(validity_check(request) == 4)
|
||||||
console_uptime();
|
console_uptime();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
char request_buf[16];
|
/*time(&rawtime);
|
||||||
|
|
||||||
printf("\n>");
|
|
||||||
|
|
||||||
fgets(request_buf, 16, stdin);
|
|
||||||
|
|
||||||
printf("uhm: %s", request_buf);
|
|
||||||
|
|
||||||
sendrecv = 0;
|
|
||||||
|
|
||||||
/*request = "null";*/
|
|
||||||
|
|
||||||
time(&rawtime);
|
|
||||||
|
|
||||||
timeinfo = localtime(&rawtime);
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
@ -199,9 +180,32 @@ int main(void) {
|
|||||||
|
|
||||||
opensocket();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,10 @@
|
|||||||
#define VERSION_STR "0.0.1"
|
#define VERSION_STR "0.0.1"
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
int sockfd, sockfd1, sendrecv;
|
int sockfd, sockfd1;
|
||||||
struct sockaddr_un serveraddr;
|
struct sockaddr_un serveraddr;
|
||||||
struct sockaddr ntkdaddr;
|
struct sockaddr ntkdaddr;
|
||||||
int rc, length, exit_now;
|
int rc;
|
||||||
char *request, *response;
|
|
||||||
|
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *timeinfo;
|
struct tm *timeinfo;
|
||||||
@ -32,8 +31,6 @@ int uptime_day;
|
|||||||
int uptime_month;
|
int uptime_month;
|
||||||
int uptime_year;
|
int uptime_year;
|
||||||
|
|
||||||
void usage();
|
int i;
|
||||||
|
|
||||||
void clean_up();
|
|
||||||
|
|
||||||
#endif /*NETSUKUKUCONSOLE_H*/
|
#endif /*NETSUKUKUCONSOLE_H*/
|
Loading…
Reference in New Issue
Block a user