From 94716ceb5d6304a445f86eb1bb522062834555f2 Mon Sep 17 00:00:00 2001 From: d00f Date: Tue, 4 Aug 2026 05:43:05 +0200 Subject: [PATCH] system: derive the default hostname from the MAC address Every switch came up as "RTLPlayground", so several of them on one network were indistinguishable until someone configured a name. Append the last three MAC octets (e.g. RTLPlayground-1ef924) - unique in practice, still recognisable, and any "hostname ..." line in the startup config overrides it as before. Suggested-by: plaes --- rtlplayground.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rtlplayground.c b/rtlplayground.c index 4886848..bc010a2 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -2146,7 +2146,19 @@ void main(void) vlan_setup(); port_l2_setup(); igmp_setup(); - strcpy((__xdata uint8_t *)hostname, "RTLPlayground"); /* default until "hostname ..." replay */ + /* Default name carries the tail of the MAC, so several switches on one + * network are distinguishable out of the box (suggested in review). + * Overridden by a "hostname ..." line in the startup config. */ + strcpy((__xdata uint8_t *)hostname, "RTLPlayground-"); + /* Spelled out rather than looped: locals here land in the 8051's + * internal-RAM overlay, which is full on a build with every feature on. */ + hostname[14] = hex[uip_ethaddr.addr[3] >> 4]; + hostname[15] = hex[uip_ethaddr.addr[3] & 0xf]; + hostname[16] = hex[uip_ethaddr.addr[4] >> 4]; + hostname[17] = hex[uip_ethaddr.addr[4] & 0xf]; + hostname[18] = hex[uip_ethaddr.addr[5] >> 4]; + hostname[19] = hex[uip_ethaddr.addr[5] & 0xf]; + hostname[20] = '\0'; bandwidth_setup(); uip_init(); uip_arp_init();