Browse Source

add sockets to gui

congestion
Evgeny 6 months ago
parent
commit
ad35bbab15
  1. 19
      src/control_server.c
  2. 1
      tools/etcpmon/etcpmon_client.c
  3. 5
      tools/etcpmon/etcpmon_gui.c

19
src/control_server.c

@ -767,6 +767,23 @@ static void send_conn_list(struct control_server* server, struct control_client*
static void send_socket_list(struct control_server* server, struct control_client* client, uint8_t seq_id) { static void send_socket_list(struct control_server* server, struct control_client* client, uint8_t seq_id) {
struct UTUN_INSTANCE* instance = server->instance; struct UTUN_INSTANCE* instance = server->instance;
if (!instance || !instance->etcp_sockets) {
uint16_t rsp_size = ETCPMON_SOCKET_LIST_SIZE(0);
uint8_t* buffer = (uint8_t*)u_malloc(rsp_size);
if (!buffer) return;
struct etcpmon_msg_header* hdr = (struct etcpmon_msg_header*)buffer;
etcpmon_build_header(hdr, sizeof(struct etcpmon_rsp_socket_list),
ETCPMON_RSP_SOCKET_LIST, seq_id);
struct etcpmon_rsp_socket_list* rsp = (struct etcpmon_rsp_socket_list*)(buffer + sizeof(*hdr));
rsp->count = 0;
send(client->fd, buffer, rsp_size, 0);
u_free(buffer);
return;
}
uint8_t count = 0; uint8_t count = 0;
struct ETCP_SOCKET* sock = instance->etcp_sockets; struct ETCP_SOCKET* sock = instance->etcp_sockets;
while (sock && count < ETCPMON_MAX_CONNECTIONS) { while (sock && count < ETCPMON_MAX_CONNECTIONS) {
@ -774,6 +791,8 @@ static void send_socket_list(struct control_server* server, struct control_clien
sock = sock->next; sock = sock->next;
} }
if (count > ETCPMON_MAX_CONNECTIONS) count = ETCPMON_MAX_CONNECTIONS;
uint16_t rsp_size = ETCPMON_SOCKET_LIST_SIZE(count); uint16_t rsp_size = ETCPMON_SOCKET_LIST_SIZE(count);
uint8_t* buffer = (uint8_t*)u_malloc(rsp_size); uint8_t* buffer = (uint8_t*)u_malloc(rsp_size);
if (!buffer) { if (!buffer) {

1
tools/etcpmon/etcpmon_client.c

@ -476,6 +476,7 @@ static void handle_response(struct etcpmon_client* client, uint8_t msg_type,
struct etcpmon_rsp_socket_list* rsp = (struct etcpmon_rsp_socket_list*)payload; struct etcpmon_rsp_socket_list* rsp = (struct etcpmon_rsp_socket_list*)payload;
uint8_t count = rsp->count; uint8_t count = rsp->count;
if (count > 16) count = 16; /* Limit to prevent buffer overflow */
if (payload_size < sizeof(*rsp) + count * sizeof(struct etcpmon_socket_info)) break; if (payload_size < sizeof(*rsp) + count * sizeof(struct etcpmon_socket_info)) break;
if (client->socket_list) { if (client->socket_list) {

5
tools/etcpmon/etcpmon_gui.c

@ -955,11 +955,14 @@ static const char* nat_type_to_string(uint8_t nat_type) {
void etcpmon_gui_update_socket_list(struct etcpmon_app* app, void etcpmon_gui_update_socket_list(struct etcpmon_app* app,
struct etcpmon_socket_info* list, struct etcpmon_socket_info* list,
uint8_t count) { uint8_t count) {
if (!app || !app->hListSockets) return; if (!app || !app->hListSockets || !list || count == 0 || count > 32) return;
SendMessage(app->hListSockets, LB_RESETCONTENT, 0, 0); SendMessage(app->hListSockets, LB_RESETCONTENT, 0, 0);
for (uint8_t i = 0; i < count; i++) { for (uint8_t i = 0; i < count; i++) {
if (!list[i].ip || list[i].ip[0] == '\0') continue;
if (!list[i].name || list[i].name[0] == '\0') continue;
char display[128]; char display[128];
const char* nat_str = nat_type_to_string(list[i].nat_type); const char* nat_str = nat_type_to_string(list[i].nat_type);
if (list[i].is_ipv6) { if (list[i].is_ipv6) {

Loading…
Cancel
Save