mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add support in simulator for mtus
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user