mirror of
https://github.com/ChronosX88/netsukuku.git
synced 2024-11-29 21:52:18 +00:00
Wow! I've done A LOT of work on the netsukuku console recently! I still haven't set up any way for ntkd to receive the commands, Or done much of anything in netsukuku itself recently except change some stuff in the exclude function to prevent possible errors if an interface had the same name up until the end of the one specified. I.E if it had tunl012, It wouldn't work because it had tunl0 in the beginning. Now, It will read from the entire length of the variable, And if it doesn't match it entirely, Then it is okay.
Anyway! The netsukuku console is almost ready! I just keep getting this weird issue around fgets() not working at all in console(). It causes the program to spam the > symbol. It functions in main()! However, After that, It has a segmentation fault. I've been trying everything I can think of, One thing made it not do a segmentation fault, However! The fgets() inside of console() still didn't work, So, It just spammed endlessly. Anyone who can, Please help! I've been working on this for a while! :/
This commit is contained in:
parent
d238933703
commit
e542a51345
@ -1,7 +1,7 @@
|
|||||||
LDLIBS=-pthread
|
LDLIBS=-pthread
|
||||||
LIBS=-pthread
|
LIBS=-pthread
|
||||||
C=clang
|
C=clang
|
||||||
DEBUG=-g -Wfatal-errors -pedantic -Weffc++ -Wunreachable-code -Winline -Wredundant-decls -Wno-vla
|
DEBUG=-g -Wfatal-errors -pedantic -Wunreachable-code -Winline -Wredundant-decls -Wno-vla
|
||||||
CFLAGS=-Wall ${DEBUG}
|
CFLAGS=-Wall ${DEBUG}
|
||||||
SRCBIN=Netsukuku-Console
|
SRCBIN=Netsukuku-Console
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <utmp.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "Netsukuku-Console.h"
|
#include "Netsukuku-Console.h"
|
||||||
|
|
||||||
@ -15,69 +17,82 @@ struct sockaddr ntkdaddr;
|
|||||||
int rc, length, exit_now;
|
int rc, length, exit_now;
|
||||||
char *request, *response;
|
char *request, *response;
|
||||||
|
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm *timeinfo;
|
||||||
|
|
||||||
|
int uptime_sec;
|
||||||
|
int uptime_min;
|
||||||
|
int uptime_hr;
|
||||||
|
|
||||||
void usage();
|
void usage();
|
||||||
|
|
||||||
void clean_up();
|
void clean_up();
|
||||||
|
|
||||||
int validity_check(void) {
|
int validity_check(void) {
|
||||||
|
|
||||||
if(strncmp(request,"help", 4) == 0)
|
if(request && strncmp(request, "null", (int)strlen(request)) != 0) {
|
||||||
|
|
||||||
|
if(strncmp(request,"help", (int)strlen(request)) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
else if(strncmp(request,"uptime", 6) == 0)
|
else if(strncmp(request,"uptime", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"kill", 4) == 0)
|
else if(strncmp(request,"kill", (int)strlen(request)) == 0)
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
else if(strncmp(request,"version", 7) == 0)
|
else if(strncmp(request,"version", (int)strlen(request)) == 0)
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
else if(strncmp(request,"console_uptime", 14) == 0)
|
else if(strncmp(request,"console_uptime", (int)strlen(request)) == 0)
|
||||||
return 4;
|
return 4;
|
||||||
|
|
||||||
else if(strncmp(request,"inet_connected", 14) == 0)
|
else if(strncmp(request,"inet_connected", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"cur_ifs", 7) == 0)
|
else if(strncmp(request,"cur_ifs", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"cur_ifs_n", 9) == 0)
|
else if(strncmp(request,"cur_ifs_n", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"cur_qspn_id", 11) == 0)
|
else if(strncmp(request,"cur_qspn_id", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"cur_ip", 6) == 0)
|
else if(strncmp(request,"cur_ip", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"cur_node", 8) == 0)
|
else if(strncmp(request,"cur_node", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"ifs", 3) == 0)
|
else if(strncmp(request,"ifs", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else if(strncmp(request,"ifs_n", 5) == 0)
|
else if(strncmp(request,"ifs_n", (int)strlen(request)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
else {
|
else {
|
||||||
printf("Incorrect or unreadable command, Please correct it.\n");
|
printf("Incorrect or unreadable command, Please correct it.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function is run by the second thread */
|
/* this function is run by the second thread */
|
||||||
void *ntkd_request(void *argv) {
|
void *ntkd_request(void *argv) {
|
||||||
|
|
||||||
while(sendrecv == 1) {
|
while(usleep(200)) {
|
||||||
rc = sendto(sockfd1, request, strlen(request), 0, (struct sockaddr *)&serveraddr, (socklen_t *)strlen(&serveraddr));
|
while(request && sendrecv == 1 && strncmp(request, "null", (int)strlen(request) != 0)) {
|
||||||
|
rc = sendto(sockfd1, request, strlen(request), 0, (struct sockaddr *)&serveraddr, (socklen_t)sizeof(&serveraddr));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("sendto() failed");
|
perror("sendto() failed");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = recvfrom(sockfd1, response, strlen(response), MSG_WAITALL, (struct sockaddr *)&ntkdaddr, (socklen_t *)strlen(&ntkdaddr));
|
rc = recvfrom(sockfd1, response, strlen(response), MSG_WAITALL, (struct sockaddr *)&ntkdaddr, (socklen_t *__restrict)sizeof(&ntkdaddr));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("recvfrom() failed");
|
perror("recvfrom() failed");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@ -90,8 +105,10 @@ void *ntkd_request(void *argv) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int opensocket(void) {
|
void opensocket(void) {
|
||||||
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sockfd < 0) {
|
if (sockfd < 0) {
|
||||||
@ -107,28 +124,52 @@ int opensocket(void) {
|
|||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("bind() failed");
|
perror("bind() failed");
|
||||||
clean_up();
|
clean_up();
|
||||||
exit(-1);
|
opensocket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void console_uptime(void) {
|
||||||
|
|
||||||
|
int uptime_sec1;
|
||||||
|
int uptime_min1;
|
||||||
|
int uptime_hr1;
|
||||||
|
|
||||||
|
time(&rawtime);
|
||||||
|
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
|
uptime_sec1 = timeinfo->tm_sec;
|
||||||
|
uptime_min1 = timeinfo->tm_min;
|
||||||
|
uptime_hr1 = timeinfo->tm_hour;
|
||||||
|
|
||||||
|
uptime_sec1 -= uptime_sec;
|
||||||
|
uptime_min1 -= uptime_min;
|
||||||
|
uptime_hr1 -= uptime_hr;
|
||||||
|
|
||||||
|
printf("Total Uptime is: %i, %i, %i\n", uptime_hr1, uptime_min1, uptime_sec1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void console(void) {
|
void console(void) {
|
||||||
|
|
||||||
|
char request_buf[16];
|
||||||
|
|
||||||
exit_now = 1;
|
exit_now = 1;
|
||||||
|
|
||||||
while(exit_now == 1) {
|
while(exit_now == 1) {
|
||||||
printf("\n>");
|
printf("\n>");
|
||||||
|
|
||||||
//request = scanf("%s");
|
fgets(request_buf, 16, stdin);
|
||||||
fgets(request, 15, stdin);
|
|
||||||
|
|
||||||
int len = strlen(request);
|
strcpy(request, request_buf);
|
||||||
if (len > 0 && request[len-1] == '\n')
|
|
||||||
request[len-1] = '\0';
|
if(validity_check() == -2)
|
||||||
|
printf("Error: Command has not been processed!");
|
||||||
|
|
||||||
if(validity_check() == -1)
|
if(validity_check() == -1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if(strncmp(request,"quit", 4) == 0) {
|
if(strncmp(request,"quit", (int)strlen(request)) == 0) {
|
||||||
exit_now = 2;
|
exit_now = 2;
|
||||||
clean_up();
|
clean_up();
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -149,7 +190,7 @@ void console(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(validity_check() == 4)
|
if(validity_check() == 4)
|
||||||
sizeof(char); // Place holder text
|
console_uptime();
|
||||||
|
|
||||||
sendrecv = 0;
|
sendrecv = 0;
|
||||||
}
|
}
|
||||||
@ -157,36 +198,53 @@ void console(void) {
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
|
char request_buf[16];
|
||||||
|
|
||||||
|
printf("\n>");
|
||||||
|
|
||||||
|
fgets(request_buf, 16, stdin);
|
||||||
|
|
||||||
|
printf("uhm %s", request_buf);
|
||||||
|
|
||||||
sendrecv = 0;
|
sendrecv = 0;
|
||||||
|
|
||||||
|
/*request = "null";*/
|
||||||
|
|
||||||
|
time(&rawtime);
|
||||||
|
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
|
uptime_sec = timeinfo->tm_sec;
|
||||||
|
uptime_min = timeinfo->tm_min;
|
||||||
|
uptime_hr = timeinfo->tm_hour;
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
/* This variable is our reference to the second thread */
|
/* This variable is our reference to the second thread */
|
||||||
pthread_t NtkdRequest;
|
pthread_t NtkdRequest;
|
||||||
|
|
||||||
/* Create a second thread which executes ntkd_request() */
|
/* Create a second thread which executes ntkd_request() */
|
||||||
if(pthread_create(&NtkdRequest, NULL, ntkd_request, NULL)) {
|
if(pthread_create(&NtkdRequest, NULL, ntkd_request, 0)) {
|
||||||
fprintf(stderr, "Error creating thread\n");
|
fprintf(stderr, "Error creating thread\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detach the second thread */
|
/* Detach the second thread */
|
||||||
if(exit_now == 2) {
|
|
||||||
if(pthread_detach(NtkdRequest)) {
|
if(pthread_detach(NtkdRequest)) {
|
||||||
fprintf(stderr, "Error detaching thread\n");
|
fprintf(stderr, "Error detaching thread\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
console();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void) {
|
void usage(void) {
|
||||||
|
|
||||||
printf("Usage)\n"
|
printf("Usage\n"
|
||||||
" uptime Returns the time when ntkd finished the hooking,"
|
" uptime Returns the time when ntkd finished the hooking,"
|
||||||
"to get the the actual uptime just do) "
|
"to get the the actual uptime just do) "
|
||||||
"time(0)-me.uptime \n"
|
"time(0)-me.uptime \n"
|
||||||
@ -206,7 +264,7 @@ void usage(void) {
|
|||||||
" ifs Lists all of the interfaces in server_opt.ifs\n"
|
" ifs Lists all of the interfaces in server_opt.ifs\n"
|
||||||
" ifs_n Lists the number of interfaces present in server_opt.ifs\n"
|
" ifs_n Lists the number of interfaces present in server_opt.ifs\n"
|
||||||
" quit Exits this program\n"
|
" quit Exits this program\n"
|
||||||
" console_uptime Gets the uptime of this console (Yet to be implemented)\n");
|
" console_uptime Gets the uptime of this console\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
clang Netsukuku-Console.c -o Netsukuku-Console -pthread -g
|
make clean
|
||||||
|
make
|
@ -372,7 +372,7 @@ int exclude_interface(int prevent_doubles) {
|
|||||||
|
|
||||||
old_tmp = ifs;
|
old_tmp = ifs;
|
||||||
|
|
||||||
if(tmp && tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET && tmp->ifa_flags & IFF_UP && !(tmp->ifa_flags & IFF_LOOPBACK && strncmp(tmp->ifa_name, "tunl0", 5) != 0 && strncmp(tmp->ifa_name, "tunl1", 5) != 0 && strcmp(optarg, tmp->ifa_name) != 0)) {
|
if(tmp && tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET && tmp->ifa_flags & IFF_UP && !(tmp->ifa_flags & IFF_LOOPBACK && strncmp(tmp->ifa_name, "tunl0", (int)strlen(tmp->ifa_name)) != 0 && strncmp(tmp->ifa_name, "tunl1", (int)strlen(tmp->ifa_name)) != 0 && strcmp(optarg, tmp->ifa_name) != 0)) {
|
||||||
ifs = tmp->ifa_name;
|
ifs = tmp->ifa_name;
|
||||||
ifs_n++;
|
ifs_n++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user