Browse Source

syslog: include our IP address in the message

Sergey Alirzaev 4 years ago
parent
commit
0259506dbc
2 changed files with 5 additions and 2 deletions
  1. 2 0
      modules/Ethernet/netconf.h
  2. 3 2
      modules/syslog.c

+ 2 - 0
modules/Ethernet/netconf.h

@@ -40,6 +40,8 @@ typedef enum
 } 
 DHCP_State_TypeDef;
 
+extern struct netif xnetif;
+
 void LwIP_Init(void);
 
 void LwIP_DHCP_task(void * pvParameters);

+ 3 - 2
modules/syslog.c

@@ -7,6 +7,7 @@
 #include "tcpip.h"
 #include "udp.h"
 #include "rtc.h"
+#include "netconf.h"
 
 static struct udp_pcb *upcb;
 
@@ -50,9 +51,9 @@ void syslog_str(char *msg)
 	struct pbuf* psend;
 	// TODO to reduce memory consumption one can use a scatter-gather I/O instead of packet[]
 	//char packet[256]; // arbitrary length; "Any transport receiver MUST be able to accept messages of up to and including 480 octets in length."
-	char timestamp[30];
+	static char timestamp[30];
 	timestamp_rfc3339(timestamp);
-	unsigned len = snprintf(packet, sizeof(packet), "<%u>" SYSLOG_VERSION " %s - " HW_REV "_" VERSION " - - - " BOM "%s", priority, timestamp, msg);
+	unsigned len = snprintf(packet, sizeof(packet), "<%u>" SYSLOG_VERSION " %s %s " HW_REV "_" VERSION " - - - " BOM "%s", priority, timestamp, ipaddr_ntoa(&xnetif.ip_addr), msg);
 	//psend = pbuf_alloc(PBUF_RAW, sizeof(packet), PBUF_REF);
 	psend = pbuf_alloc(PBUF_RAW, len, PBUF_REF);
 	psend->payload = packet;