nvtsrv: Input processing changes, send all from console
This commit is contained in:
+16
-24
@@ -12,8 +12,6 @@
|
||||
#include "lib/nvt_socket.h"
|
||||
#include "telnet.h"
|
||||
|
||||
#define MATCH(s1, s2) (strcmp(s1, s2) == 0)
|
||||
|
||||
struct {
|
||||
unsigned char mline;
|
||||
tn_ctx_t *tnct;
|
||||
@@ -76,25 +74,23 @@ static void _nvtsrv_init(void)
|
||||
dd.tnct = telnet_ctx_init(NULL, _tn_tx, _tn_ss);
|
||||
}
|
||||
|
||||
static void _nvtsrv_cmd(tn_ctx_t * tcc, const char *line)
|
||||
static void _nvtsrv_cmd(tn_ctx_t * tcc, const char *line, int len)
|
||||
{
|
||||
char cmd[8];
|
||||
const char *args;
|
||||
int len, val;
|
||||
int val;
|
||||
|
||||
cmd[0] = '\0';
|
||||
len = 0;
|
||||
sscanf(line, "%7s %n", cmd, &len);
|
||||
args = line + len;
|
||||
|
||||
if (MATCH(cmd, "w"))
|
||||
if (line[0] == '*' && len > 2)
|
||||
{
|
||||
_tn_tx(NULL, args, strlen(args));
|
||||
/* Special features */
|
||||
if (line[1] == 'm')
|
||||
{
|
||||
sscanf(line + 2, "%x", &val);
|
||||
telnet_rfc2217_change_modemstate(tcc, val);
|
||||
}
|
||||
}
|
||||
else if (MATCH(cmd, "m"))
|
||||
else
|
||||
{
|
||||
sscanf(args, "%x", &val);
|
||||
telnet_rfc2217_change_modemstate(tcc, val);
|
||||
/* Send all input */
|
||||
_tn_tx(NULL, line, len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,10 +159,9 @@ int main(int argc, char **argv)
|
||||
if (nr <= 0)
|
||||
break;
|
||||
buf[nr] = 0;
|
||||
len = strcspn(buf, "\n\r");
|
||||
buf[len] = 0;
|
||||
// printf("%d: fd=%d: r %d: '%.*s'\n", i, pfds[i].fd, nr, nr, buf);
|
||||
_nvtsrv_cmd(dd.tnct, buf);
|
||||
nvt_log_buf(LOG_INFO, "Con Rx", buf, nr);
|
||||
_nvtsrv_cmd(dd.tnct, buf, nr);
|
||||
}
|
||||
|
||||
i = 2;
|
||||
@@ -190,14 +185,11 @@ int main(int argc, char **argv)
|
||||
if (nr > 0)
|
||||
{
|
||||
buf[nr] = 0;
|
||||
len = strcspn(buf, "\n\r");
|
||||
buf[len] = 0;
|
||||
nvt_log_buf(LOG_INFO, "Rx", buf, nr);
|
||||
// printf("%d: fd=%d: r %d: '%.*s'\n", i, pfds[i].fd, nr, nr, buf);
|
||||
len = nr;
|
||||
rc = telnet_rx(dd.tnct, buf, &len);
|
||||
printf("%d: fd=%d: r %d: '%.*s'\n", i, pfds[i].fd, rc, len,
|
||||
buf);
|
||||
printf("%d: fd=%d: r %d: '%.*s'\n", i, pfds[i].fd, rc,
|
||||
len, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user