mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
Merge pull request #333 from DrDoof/feat/syslog-hostname-port
syslog: send a hostname, allow a port other than 514, and stop the save from dropping the address
This commit is contained in:
8 files changed
+112
-14
No files matched your search
+30
-2
@@ -67,6 +67,10 @@ __xdata char save_cmd;
|
||||
|
||||
__xdata uint8_t ip[4];
|
||||
|
||||
/* Scratch for parse_syslog(), in xdata: a local here would take internal RAM
|
||||
* the linker has none of. */
|
||||
__xdata uint8_t syslog_port_was_on;
|
||||
|
||||
// These variables combined create a Fixed-capacity vector/bounded buffer.
|
||||
// `N_WORDS`: The total number of command arguments that can be tracked.
|
||||
// `cmd_words_len` stores the number of arguments found inside `cmd_buffer`
|
||||
@@ -1415,6 +1419,7 @@ void parse_syslog(void)
|
||||
if (syslog_state.enabled) {
|
||||
print_string("enabled, sending to ");
|
||||
print_ip(syslog_state.server_ip);
|
||||
write_char(':'); itoa_short(syslog_state.server_port);
|
||||
write_char('\n');
|
||||
} else {
|
||||
print_string("disabled\n");
|
||||
@@ -1443,11 +1448,34 @@ void parse_syslog(void)
|
||||
} else {
|
||||
print_string("Invalid IP address\n");
|
||||
}
|
||||
} else if (cmd_compare(1, "port")) {
|
||||
if (cmd_words_len < 3) { // no additional argument -> print current port
|
||||
print_string("Current syslog port: ");
|
||||
itoa_short(syslog_state.server_port); write_char('\n');
|
||||
return;
|
||||
}
|
||||
/* atoi_short() returns zero for no digits and for a value past
|
||||
* 65535; port zero is not a port either, so both tests are needed. */
|
||||
if (!atoi_short(cmd_words_b[2]) || !atoi_results_short) {
|
||||
print_string("Invalid port\n");
|
||||
return;
|
||||
}
|
||||
/* The port is frozen into the connection by uip_udp_new(), so
|
||||
* changing it has to tear the connection down and build a new one -
|
||||
* same dance as setting the address above. */
|
||||
syslog_port_was_on = syslog_state.enabled;
|
||||
if (syslog_port_was_on)
|
||||
syslog_stop();
|
||||
print_string("Setting new syslog port.\n");
|
||||
syslog_state.server_port = atoi_results_short;
|
||||
if (syslog_port_was_on)
|
||||
syslog_start();
|
||||
}
|
||||
else
|
||||
{
|
||||
print_string("Error: syslog [on|off|ip [ip-address]]\n");
|
||||
print_string(" on/off enables or disables syslog, ip sets the syslog server IP address\n");
|
||||
print_string("Error: syslog [on|off|ip [ip-address]|port [number]]\n");
|
||||
print_string(" on/off enables or disables syslog, ip sets the syslog server IP address,\n");
|
||||
print_string(" port sets the destination UDP port (default 514)\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user