2014-06-02 07:14:19 +00:00
|
|
|
#include "Netsukuku-Console.h"
|
|
|
|
|
2014-08-17 07:06:22 +00:00
|
|
|
char response[BUFFER_LENGTH];
|
2014-06-07 11:52:30 +00:00
|
|
|
|
|
|
|
void usage();
|
|
|
|
|
|
|
|
void clean_up();
|
|
|
|
|
2014-08-17 16:20:10 +00:00
|
|
|
int validity_check(char *request) {
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
|
|
|
if(strncmp(request,"help", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 1;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"uptime", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"kill", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 2;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"version", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 3;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"console_uptime", (int)strlen(request)) == 0)
|
2014-06-03 17:55:39 +00:00
|
|
|
return 4;
|
|
|
|
|
2014-08-17 07:06:22 +00:00
|
|
|
else if(strlen(request) > 250)
|
|
|
|
return 5;
|
|
|
|
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"inet_connected", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"cur_ifs", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"cur_ifs_n", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"cur_qspn_id", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"cur_ip", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"cur_node", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"ifs", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
else if(strncmp(request,"ifs_n", (int)strlen(request)) == 0)
|
2014-06-03 05:06:48 +00:00
|
|
|
return 0;
|
2014-06-03 17:55:39 +00:00
|
|
|
|
|
|
|
else {
|
2014-06-03 05:06:48 +00:00
|
|
|
printf("Incorrect or unreadable command, Please correct it.\n");
|
|
|
|
return -1;
|
2014-06-03 17:55:39 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
|
|
|
return -2;
|
2014-06-03 05:06:48 +00:00
|
|
|
|
2014-06-02 07:14:19 +00:00
|
|
|
}
|
|
|
|
|
2014-08-17 16:14:32 +00:00
|
|
|
void response_cleanup(char response[BUFFER_LENGTH]) {
|
2014-08-16 05:51:54 +00:00
|
|
|
|
|
|
|
char remove = 'a';
|
|
|
|
|
|
|
|
char* c;
|
|
|
|
char* pPosition;
|
2014-08-17 16:35:46 +00:00
|
|
|
while((pPosition = strchr(response, 'a')) != NULL) {
|
2014-08-16 05:51:54 +00:00
|
|
|
if ((c = index(response, remove)) != NULL) {
|
|
|
|
size_t len_left = sizeof(response) - (c+1-response);
|
|
|
|
memmove(c, c+1, len_left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("Sent and received Successfully!\n The Response was: %s", response);
|
|
|
|
}
|
|
|
|
|
2014-08-04 07:04:46 +00:00
|
|
|
/* Sends and receives to ntkd */
|
2014-08-17 16:20:10 +00:00
|
|
|
void ntkd_request(char *request) {
|
2014-06-05 02:41:12 +00:00
|
|
|
|
2014-08-16 05:51:54 +00:00
|
|
|
int request_length;
|
|
|
|
|
|
|
|
rc = connect(sockfd, (struct sockaddr *)&serveraddr, SUN_LEN(&serveraddr));
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
if (rc < 0) {
|
2014-08-16 05:51:54 +00:00
|
|
|
perror("connect() failed");
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2014-08-16 05:51:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
request_length = (int)strlen(request);
|
2014-08-17 07:06:22 +00:00
|
|
|
memset(request, 'a', BUFFER_LENGTH - request_length);
|
2014-08-16 05:51:54 +00:00
|
|
|
rc = send(sockfd, request, sizeof(request), 0);
|
2014-06-03 05:06:48 +00:00
|
|
|
if (rc < 0) {
|
2014-08-16 05:51:54 +00:00
|
|
|
perror("send() failed");
|
2014-06-03 05:06:48 +00:00
|
|
|
exit(-1);
|
2014-08-16 05:51:54 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
2014-08-16 05:51:54 +00:00
|
|
|
bytesReceived = 0;
|
|
|
|
while (bytesReceived < BUFFER_LENGTH) {
|
|
|
|
rc = recv(sockfd, & response[bytesReceived],
|
|
|
|
BUFFER_LENGTH - bytesReceived, 0);
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("recv() failed");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
else if (rc == 0) {
|
|
|
|
printf("The server closed the connection\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
2014-08-16 05:51:54 +00:00
|
|
|
/* Increment the number of bytes that have been received so far */
|
|
|
|
bytesReceived += rc;
|
|
|
|
}
|
2014-08-17 16:14:32 +00:00
|
|
|
response_cleanup(response);
|
2014-06-03 05:06:48 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
void opensocket(void) {
|
2014-06-02 07:14:19 +00:00
|
|
|
|
2014-06-03 05:06:48 +00:00
|
|
|
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (sockfd < 0) {
|
|
|
|
perror("socket creation failed");
|
|
|
|
exit(-1);
|
2014-06-02 07:14:19 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 05:06:48 +00:00
|
|
|
memset(&serveraddr, 0, sizeof(serveraddr));
|
|
|
|
serveraddr.sun_family = AF_UNIX;
|
|
|
|
strcpy(serveraddr.sun_path, SERVER_PATH);
|
2014-06-02 07:14:19 +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! :/
2014-06-04 10:47:49 +00:00
|
|
|
void console_uptime(void) {
|
|
|
|
|
|
|
|
int uptime_sec1;
|
|
|
|
int uptime_min1;
|
2014-06-05 02:41:12 +00:00
|
|
|
int uptime_hour1;
|
|
|
|
|
|
|
|
int uptime_day1;
|
|
|
|
int uptime_month1;
|
|
|
|
int uptime_year1;
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
|
|
|
time(&rawtime);
|
|
|
|
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
|
|
|
|
uptime_sec1 = timeinfo->tm_sec;
|
|
|
|
uptime_min1 = timeinfo->tm_min;
|
2014-06-05 02:41:12 +00:00
|
|
|
uptime_hour1 = timeinfo->tm_hour;
|
|
|
|
|
|
|
|
uptime_day1 = timeinfo->tm_mday;
|
|
|
|
uptime_month1 = timeinfo->tm_mon;
|
|
|
|
uptime_year1 = timeinfo->tm_year;
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
|
|
|
uptime_sec1 -= uptime_sec;
|
|
|
|
uptime_min1 -= uptime_min;
|
2014-06-05 02:41:12 +00:00
|
|
|
uptime_hour1 -= uptime_hour;
|
|
|
|
|
|
|
|
uptime_day1 -= uptime_day;
|
|
|
|
uptime_month1 -= uptime_month;
|
|
|
|
uptime_year1 -= uptime_year;
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
2014-06-05 02:41:12 +00:00
|
|
|
printf("Total Uptime is: %i Year(s), %i Month(s), %i Day(s), %i Hour(s), %i Minute(s), %i Second(s)\n",uptime_year1, uptime_month1, uptime_day1, uptime_hour1, uptime_min1, uptime_sec1);
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-17 15:27:29 +00:00
|
|
|
int millisleep(unsigned ms)
|
|
|
|
{
|
|
|
|
return usleep(1000 * ms);
|
|
|
|
}
|
|
|
|
|
2014-08-17 16:20:10 +00:00
|
|
|
void console(char * request) {
|
2014-08-17 07:06:22 +00:00
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(validity_check(request) == -2)
|
2014-08-17 07:06:22 +00:00
|
|
|
printf("Error: Command has not been processed!\n");
|
2014-06-03 17:55:39 +00:00
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(validity_check(request) == -1)
|
2014-06-03 05:06:48 +00:00
|
|
|
usage();
|
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(strncmp(request,"quit", (int)strlen(request)) == 0) {
|
2014-06-03 17:55:39 +00:00
|
|
|
clean_up();
|
2014-06-03 05:06:48 +00:00
|
|
|
exit(0);
|
2014-06-03 17:55:39 +00:00
|
|
|
}
|
2014-06-02 07:14:19 +00:00
|
|
|
|
2014-08-17 15:27:29 +00:00
|
|
|
if(validity_check(request) == 0) {
|
2014-06-07 11:52:30 +00:00
|
|
|
ntkd_request(request);
|
2014-08-17 15:27:29 +00:00
|
|
|
millisleep(200);
|
|
|
|
}
|
2014-06-03 05:06:48 +00:00
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(validity_check(request) == 1)
|
2014-06-03 05:06:48 +00:00
|
|
|
usage();
|
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(validity_check(request) == 2)
|
2014-08-04 07:04:46 +00:00
|
|
|
system("ntkd -k");
|
2014-06-03 05:06:48 +00:00
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(validity_check(request) == 3) {
|
2014-08-17 07:06:22 +00:00
|
|
|
printf("Ntk-Console Version: %s\n", VERSION_STR);
|
2014-06-07 11:52:30 +00:00
|
|
|
ntkd_request(request);
|
2014-06-03 05:06:48 +00:00
|
|
|
}
|
2014-06-05 02:41:12 +00:00
|
|
|
|
2014-06-07 11:52:30 +00:00
|
|
|
if(validity_check(request) == 4)
|
2014-08-17 07:06:22 +00:00
|
|
|
console_uptime();
|
|
|
|
|
|
|
|
if(validity_check(request) == 5)
|
|
|
|
printf("Error: Command longer than 250 bytes.\n");
|
2014-06-03 05:06:48 +00:00
|
|
|
}
|
2014-06-02 07:14:19 +00:00
|
|
|
|
2014-06-03 05:06:48 +00:00
|
|
|
int main(void) {
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
2014-08-04 07:04:46 +00:00
|
|
|
time(&rawtime);
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
|
|
|
|
uptime_sec = timeinfo->tm_sec;
|
|
|
|
uptime_min = timeinfo->tm_min;
|
2014-06-05 02:41:12 +00:00
|
|
|
uptime_hour = timeinfo->tm_hour;
|
|
|
|
uptime_day = timeinfo->tm_mday;
|
|
|
|
uptime_month = timeinfo->tm_mon;
|
|
|
|
uptime_year = timeinfo->tm_year;
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
|
2014-06-03 05:06:48 +00:00
|
|
|
opensocket();
|
|
|
|
|
2014-08-04 07:04:46 +00:00
|
|
|
printf("This is the Netsukuku Console, Please type 'help' for more information.\n");
|
2014-06-07 11:52:30 +00:00
|
|
|
|
2014-08-17 16:20:10 +00:00
|
|
|
char * request;
|
2014-06-07 11:52:30 +00:00
|
|
|
|
2014-08-17 16:20:10 +00:00
|
|
|
request = (char *)malloc(BUFFER_LENGTH);
|
2014-06-07 11:52:30 +00:00
|
|
|
|
2014-08-16 05:51:54 +00:00
|
|
|
do {
|
2014-06-07 11:52:30 +00:00
|
|
|
|
|
|
|
printf("\n>");
|
|
|
|
|
|
|
|
fgets(request, 16, stdin);
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
2014-08-04 07:04:46 +00:00
|
|
|
console(request);
|
2014-08-16 05:51:54 +00:00
|
|
|
} while(FALSE);
|
2014-06-03 05:06:48 +00:00
|
|
|
|
2014-08-16 05:51:54 +00:00
|
|
|
clean_up();
|
|
|
|
return 0;
|
2014-06-03 05:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usage(void) {
|
|
|
|
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
printf("Usage\n"
|
2014-06-03 17:55:39 +00:00
|
|
|
" uptime Returns the time when ntkd finished the hooking,"
|
|
|
|
"to get the the actual uptime just do) "
|
2014-06-03 05:06:48 +00:00
|
|
|
"time(0)-me.uptime \n"
|
|
|
|
" help Shows this\n"
|
|
|
|
" kill Kills the running instance of netsukuku with SIGINT\n\n"
|
2014-08-04 07:04:46 +00:00
|
|
|
" version Shows the running version of the ntk-console, and ntkd.\n"
|
2014-06-03 05:06:48 +00:00
|
|
|
" inet_connected If it is 1, Ntkd is connected to the Internet\n"
|
|
|
|
"\n"
|
|
|
|
" cur_ifs Lists all of the interfaces in cur_ifs\n"
|
|
|
|
" cur_ifs_n Lists the number of interfaces present in `cur_ifs'\n"
|
2014-06-03 17:55:39 +00:00
|
|
|
"\n");
|
|
|
|
printf(" cur_qspn_id The current qspn_id we are processing. "
|
2014-06-03 05:06:48 +00:00
|
|
|
"It is cur_qspn_id[levels] big\n"
|
|
|
|
" cur_ip Current IP address\n"
|
|
|
|
"\n"
|
|
|
|
" cur_node Current Node\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"
|
|
|
|
" quit Exits this program\n"
|
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! :/
2014-06-04 10:47:49 +00:00
|
|
|
" console_uptime Gets the uptime of this console\n");
|
2014-06-03 05:06:48 +00:00
|
|
|
|
2014-06-03 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void clean_up(void) {
|
|
|
|
|
|
|
|
const int optVal = 1;
|
|
|
|
const socklen_t optLen = sizeof(optVal);
|
|
|
|
|
|
|
|
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);
|
|
|
|
setsockopt(sockfd1, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);
|
|
|
|
|
|
|
|
if (sockfd != -1)
|
|
|
|
close(sockfd);
|
|
|
|
|
|
|
|
if (sockfd1 != -1)
|
|
|
|
close(sockfd1);
|
|
|
|
|
|
|
|
unlink(SERVER_PATH);
|
|
|
|
|
2014-06-02 07:14:19 +00:00
|
|
|
}
|