From b7cfc73752efe68a6e9d2644bef64d45769bf6a1 Mon Sep 17 00:00:00 2001 From: logicog Date: Thu, 18 Dec 2025 20:23:26 +0100 Subject: [PATCH] Add support in simulator for mtus --- tools/httpd_sim.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/httpd_sim.c b/tools/httpd_sim.c index 138faa9..1b9f5ac 100644 --- a/tools/httpd_sim.c +++ b/tools/httpd_sim.c @@ -286,6 +286,30 @@ void send_lag(int s) } +void send_mtu(int s) +{ + struct json_object *mtus, *v; + const char *jstring; + char *header = "HTTP/1.1 200 OK\r\n" + "Content-Type: application/json; charset=UTF-8\r\n\r\n"; + + mtus = json_object_new_array_ext(PORTS); + char mtu[8]; + for (int i = 1; i <= PORTS; i++) { + v = json_object_new_object(); + json_object_object_add(v, "portNum", json_object_new_int(i)); + sprintf(mtu, "0x%04x", i % 2 ? 16383 : 1522); + json_object_object_add(v, "mtu", json_object_new_string(mtu)); + json_object_array_add(mtus, v); + } + write(s, header, strlen(header)); + + jstring = json_object_to_json_string_ext(mtus, JSON_C_TO_STRING_PLAIN); + write(s, jstring, strlen(jstring)); + json_object_put(mtus); +} + + void send_cmd_log(int s) { char *header = "HTTP/1.1 200 OK\r\n" @@ -494,6 +518,13 @@ void launch(struct Server *server) else send_lag(new_socket); goto done; + } else if (!strncmp(&buffer[4], "/mtu.json", 9)) { + printf("MTU request\n"); + if (!authenticated) + send_unauthorized(new_socket); + else + send_mtu(new_socket); + goto done; } else if (!strncmp(&buffer[4], "/vlan.json?vid=", 15)) { int vlan = atoi(&buffer[19]); printf("VLAN request for %d\n", vlan);