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 "lib/nvt_socket.h"
|
||||||
#include "telnet.h"
|
#include "telnet.h"
|
||||||
|
|
||||||
#define MATCH(s1, s2) (strcmp(s1, s2) == 0)
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned char mline;
|
unsigned char mline;
|
||||||
tn_ctx_t *tnct;
|
tn_ctx_t *tnct;
|
||||||
@@ -76,25 +74,23 @@ static void _nvtsrv_init(void)
|
|||||||
dd.tnct = telnet_ctx_init(NULL, _tn_tx, _tn_ss);
|
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];
|
int val;
|
||||||
const char *args;
|
|
||||||
int len, val;
|
|
||||||
|
|
||||||
cmd[0] = '\0';
|
if (line[0] == '*' && len > 2)
|
||||||
len = 0;
|
|
||||||
sscanf(line, "%7s %n", cmd, &len);
|
|
||||||
args = line + len;
|
|
||||||
|
|
||||||
if (MATCH(cmd, "w"))
|
|
||||||
{
|
{
|
||||||
_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);
|
/* Send all input */
|
||||||
telnet_rfc2217_change_modemstate(tcc, val);
|
_tn_tx(NULL, line, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,10 +159,9 @@ int main(int argc, char **argv)
|
|||||||
if (nr <= 0)
|
if (nr <= 0)
|
||||||
break;
|
break;
|
||||||
buf[nr] = 0;
|
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);
|
// 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;
|
i = 2;
|
||||||
@@ -190,14 +185,11 @@ int main(int argc, char **argv)
|
|||||||
if (nr > 0)
|
if (nr > 0)
|
||||||
{
|
{
|
||||||
buf[nr] = 0;
|
buf[nr] = 0;
|
||||||
len = strcspn(buf, "\n\r");
|
|
||||||
buf[len] = 0;
|
|
||||||
nvt_log_buf(LOG_INFO, "Rx", buf, nr);
|
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;
|
len = nr;
|
||||||
rc = telnet_rx(dd.tnct, buf, &len);
|
rc = telnet_rx(dd.tnct, buf, &len);
|
||||||
printf("%d: fd=%d: r %d: '%.*s'\n", i, pfds[i].fd, rc, len,
|
printf("%d: fd=%d: r %d: '%.*s'\n", i, pfds[i].fd, rc,
|
||||||
buf);
|
len, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user