mirror of
https://github.com/ChronosX88/netsukuku.git
synced 2024-12-22 08:51:46 +00:00
Console: Add common console header to keep API in sync
This commit is contained in:
parent
2627ba6350
commit
bc054faf0c
18
SConstruct
18
SConstruct
@ -7,18 +7,12 @@ import platform as _platform
|
||||
#
|
||||
|
||||
opts = Options('build.conf')
|
||||
opts.AddOptions(('CONF_DIR', """Directory where the Netsukuku configuration files will be installed""",
|
||||
'/etc/netsukuku'),
|
||||
('DATA_DIR', 'Directory to install data files',
|
||||
'/usr/share/netsukuku'),
|
||||
('MAN_DIR', 'Where the manuals will be installed',
|
||||
'/usr/man'),
|
||||
('BIN_DIR' , 'Directory to install the binaries',
|
||||
'/usr/bin'),
|
||||
('PID_DIR', 'Specify location of ntkd.pid file',
|
||||
'/var/run'),
|
||||
('destdir', 'SCons will copy all the files under destdir during installation',
|
||||
'/'),
|
||||
opts.AddOptions(('CONF_DIR', """Directory where the Netsukuku configuration files will be installed""", '/etc/netsukuku'),
|
||||
('DATA_DIR', 'Directory to install data files', '/usr/share/netsukuku'),
|
||||
('MAN_DIR', 'Where the manuals will be installed', '/usr/man'),
|
||||
('BIN_DIR' , 'Directory to install the binaries', '/usr/bin'),
|
||||
('PID_DIR', 'Specify location of ntkd.pid file', '/var/run'),
|
||||
('destdir', 'SCons will copy all the files under destdir during installation', '/'),
|
||||
EnumOption('debug', 'build the debug code', 'no',
|
||||
allowed_values=('yes', 'no', '1', '0'), map={},
|
||||
ignorecase=0),
|
||||
|
@ -151,10 +151,10 @@ build_config_files(env = env)
|
||||
# Build
|
||||
#
|
||||
|
||||
ntkd = env.Program('ntkd', sources_netsukuku, LIBS = libs, CPPPATH = '.')
|
||||
qspn = env.Program('qspn-empiric', sources_qspn, LIBS = libs, CPPPATH = '.')
|
||||
ntkresolv = env.Program('ntk-resolv', sources_ntkresolv, LIBS = libs, CPPPATH = '.')
|
||||
ntkconsole = env.Program('ntk-console', sources_ntkconsole, LIBS = libs, CPPPATH = '.', CFLAGS = '-std=c99')
|
||||
ntkd = env.Program('ntkd', sources_netsukuku, LIBS = libs, CPPPATH = '.')
|
||||
qspn = env.Program('qspn-empiric', sources_qspn, LIBS = libs, CPPPATH = '.')
|
||||
ntkresolv = env.Program('ntk-resolv', sources_ntkresolv, LIBS = libs, CPPPATH = '.')
|
||||
ntkconsole = env.Program('ntk-console', sources_ntkconsole, LIBS = libs, CPPPATH = '.', CFLAGS = '-std=c99')
|
||||
|
||||
Default(ntkd, ntkresolv, ntkconsole)
|
||||
|
||||
|
51
src/console.h
Normal file
51
src/console.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* This file is part of Netsukuku
|
||||
*
|
||||
* This source code is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation; either version 2 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This source code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* Please refer to the GNU Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Public License along with
|
||||
* this source code; if not, write to:
|
||||
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
|
||||
#define CONSOLE_SOCKET_PATH "/tmp/ntk-console"
|
||||
#define CONSOLE_VERSION_MAJOR 0
|
||||
#define CONSOLE_VERSION_MINOR 3
|
||||
#define CONSOLE_BUFFER_LENGTH 250
|
||||
|
||||
#ifndef TRUE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
COMMAND_HELP = 0x100,
|
||||
COMMAND_UPTIME,
|
||||
COMMAND_KILL,
|
||||
COMMAND_VERSION,
|
||||
COMMAND_INETCONN,
|
||||
COMMAND_CURIFS,
|
||||
COMMAND_CURIFSCT,
|
||||
COMMAND_CURQSPNID,
|
||||
COMMAND_CURIP,
|
||||
COMMAND_CURNODE,
|
||||
COMMAND_IFS,
|
||||
COMMAND_IFSCT,
|
||||
COMMAND_QUIT,
|
||||
COMMAND_CONSUPTIME,
|
||||
} command_t;
|
||||
|
||||
|
||||
#endif /* CONSOLE_H */
|
@ -1,18 +1,14 @@
|
||||
/* Header files required for the console bindings
|
||||
* not included outside of this file. */
|
||||
|
||||
|
||||
#include <utmp.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "console.h"
|
||||
#include "netsukuku.h"
|
||||
|
||||
/* Constants used for the console bindings. */
|
||||
|
||||
#define SERVER_PATH "/tmp/ntk-console"
|
||||
#define REQUEST_LENGTH 250
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
/* Variable and structure defintions, serverfd refers to socket file descriptor
|
||||
* length refers to the required length of the requests that will be sent.
|
||||
@ -28,8 +24,9 @@ int rc, length;
|
||||
/* Cleans up the console bindings for closing, Closes socket file descriptors,
|
||||
* unlinks the server path, etc. */
|
||||
|
||||
void clean_up(void) {
|
||||
|
||||
static void
|
||||
clean_up(void)
|
||||
{
|
||||
const int optVal = 1;
|
||||
const socklen_t optLen = sizeof(optVal);
|
||||
|
||||
@ -38,14 +35,15 @@ void clean_up(void) {
|
||||
if (serverfd != -1)
|
||||
close(serverfd);
|
||||
|
||||
unlink(SERVER_PATH);
|
||||
unlink(CONSOLE_SOCKET_PATH);
|
||||
|
||||
}
|
||||
|
||||
/* Creates an AF_UNIX socket and binds it to a local address. */
|
||||
|
||||
void opensocket(void) {
|
||||
|
||||
static void
|
||||
opensocket(void)
|
||||
{
|
||||
int stop_trying;
|
||||
|
||||
serverfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
@ -56,7 +54,7 @@ void opensocket(void) {
|
||||
|
||||
memset(&serveraddr, 0, sizeof(serveraddr));
|
||||
serveraddr.sun_family = AF_UNIX;
|
||||
strcpy(serveraddr.sun_path, SERVER_PATH);
|
||||
strcpy(serveraddr.sun_path, CONSOLE_SOCKET_PATH);
|
||||
|
||||
rc = bind(serverfd, (struct sockaddr *)&serveraddr, SUN_LEN(&serveraddr));
|
||||
if (rc < 0) {
|
||||
@ -73,10 +71,11 @@ void opensocket(void) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Sends a parsed response to the ntk console client. */
|
||||
|
||||
void
|
||||
send_response(int session_fd, char response[REQUEST_LENGTH], ...)
|
||||
static void
|
||||
send_response(int session_fd, char response[CONSOLE_BUFFER_LENGTH], ...)
|
||||
{
|
||||
int response_length = (int)strlen(response);
|
||||
rc = send(session_fd, response, response_length, 0);
|
||||
@ -91,8 +90,8 @@ send_response(int session_fd, char response[REQUEST_LENGTH], ...)
|
||||
* to data from ntkd structures such as: me
|
||||
* into a response for the ntk console client. */
|
||||
|
||||
int
|
||||
request_processing(int session_fd, char unprocessed_request[REQUEST_LENGTH])
|
||||
static int
|
||||
request_processing(int session_fd, char unprocessed_request[CONSOLE_BUFFER_LENGTH])
|
||||
{
|
||||
if(strncmp(unprocessed_request,"uptime", (int)strlen(unprocessed_request)) == 0)
|
||||
send_response(session_fd, (char)time(0)-me.uptime);
|
||||
@ -153,7 +152,24 @@ request_receive(int sock, char message[], int max)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
static void
|
||||
handle_session(int session_fd)
|
||||
{
|
||||
char request[CONSOLE_BUFFER_LENGTH];
|
||||
|
||||
rc = request_receive(session_fd, request, CONSOLE_BUFFER_LENGTH);
|
||||
if (rc < 0) {
|
||||
perror("recv() failed");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("%d bytes of data were received\n", rc);
|
||||
|
||||
request_processing(session_fd, request);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wait_session(int server_fd)
|
||||
{
|
||||
rc = listen(serverfd, 10);
|
||||
@ -187,23 +203,6 @@ wait_session(int server_fd)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
handle_session(int session_fd)
|
||||
{
|
||||
char request[REQUEST_LENGTH];
|
||||
|
||||
rc = request_receive(session_fd, request, REQUEST_LENGTH);
|
||||
if (rc < 0) {
|
||||
perror("recv() failed");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("%d bytes of data were received\n", rc);
|
||||
|
||||
request_processing(session_fd, request);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
console_recv_send(void)
|
||||
{
|
||||
|
@ -1,6 +1,29 @@
|
||||
/* This file is part of Netsukuku
|
||||
*
|
||||
* This source code is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation; either version 2 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This source code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* Please refer to the GNU Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Public License along with
|
||||
* this source code; if not, write to:
|
||||
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "ntk-console.h"
|
||||
#include "console.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
@ -30,7 +53,7 @@ const struct supported_commands {
|
||||
command_t
|
||||
command_parse(char *request)
|
||||
{
|
||||
if (strlen(request) > BUFFER_LENGTH) {
|
||||
if (strlen(request) > CONSOLE_BUFFER_LENGTH) {
|
||||
printf("Error: Command longer than 250 bytes.\n");
|
||||
return -1;
|
||||
}
|
||||
@ -92,8 +115,8 @@ ntkd_request(char *request)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
char response[BUFFER_LENGTH];
|
||||
request_receive(sockfd, response, BUFFER_LENGTH);
|
||||
char response[CONSOLE_BUFFER_LENGTH];
|
||||
request_receive(sockfd, response, CONSOLE_BUFFER_LENGTH);
|
||||
if (rc < 0) {
|
||||
perror("recv() failed");
|
||||
exit(-1);
|
||||
@ -114,7 +137,7 @@ opensocket(void)
|
||||
|
||||
memset(&serveraddr, 0, sizeof(serveraddr));
|
||||
serveraddr.sun_family = AF_UNIX;
|
||||
strcpy(serveraddr.sun_path, SERVER_PATH);
|
||||
strcpy(serveraddr.sun_path, CONSOLE_SOCKET_PATH);
|
||||
|
||||
rc = connect(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
|
||||
if (rc < 0) {
|
||||
@ -206,7 +229,8 @@ console(char* request)
|
||||
millisleep(200);
|
||||
break;
|
||||
case COMMAND_VERSION:
|
||||
printf("Ntk-Console Version: %s\n", VERSION_STR);
|
||||
printf("ntk-console version: %d.%d\n",
|
||||
CONSOLE_VERSION_MAJOR, CONSOLE_VERSION_MINOR);
|
||||
ntkd_request(request);
|
||||
break;
|
||||
case COMMAND_CONSUPTIME:
|
||||
@ -241,7 +265,7 @@ main(void)
|
||||
|
||||
printf("This is the Netsukuku Console. Please type 'help' for more information.\n");
|
||||
for(;;) {
|
||||
char* request = (char*)malloc(BUFFER_LENGTH);
|
||||
char* request = (char*)malloc(CONSOLE_BUFFER_LENGTH);
|
||||
printf("\n> ");
|
||||
fgets(request, 16, stdin);
|
||||
fflush(stdin);
|
||||
|
@ -1,44 +1,27 @@
|
||||
/* This file is part of Netsukuku
|
||||
*
|
||||
* This source code is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation; either version 2 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This source code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* Please refer to the GNU Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Public License along with
|
||||
* this source code; if not, write to:
|
||||
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef NETSUKUKUCONSOLE_H
|
||||
#define NETSUKUKUCONSOLE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <utmp.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#define SERVER_PATH "/tmp/ntk-console"
|
||||
#define BUFFER_LENGTH 250
|
||||
#define VERSION_STR "0.0.2"
|
||||
|
||||
#ifndef TRUE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
COMMAND_HELP = 0x100,
|
||||
COMMAND_UPTIME,
|
||||
COMMAND_KILL,
|
||||
COMMAND_VERSION,
|
||||
COMMAND_INETCONN,
|
||||
COMMAND_CURIFS,
|
||||
COMMAND_CURIFSCT,
|
||||
COMMAND_CURQSPNID,
|
||||
COMMAND_CURIP,
|
||||
COMMAND_CURNODE,
|
||||
COMMAND_IFS,
|
||||
COMMAND_IFSCT,
|
||||
COMMAND_QUIT,
|
||||
COMMAND_CONSUPTIME,
|
||||
} command_t;
|
||||
#include "console.h"
|
||||
|
||||
|
||||
int sockfd = -1, sockfd1 = -1;
|
||||
|
Loading…
Reference in New Issue
Block a user