| 73 | } |
| 74 | |
| 75 | ByteBuf format_sockets_json(const Engine& eng, SocketInfo::Proto only, |
| 76 | const char* proto_name) |
| 77 | { |
| 78 | auto socks = (only == SocketInfo::P_UDP) |
| 79 | ? enumerate_udp_sockets(eng) |
| 80 | : enumerate_tcp_sockets(eng); |
| 81 | json arr = json::array(); |
| 82 | for (const auto& s : socks) { |
| 83 | if (s.proto != only) continue; |
| 84 | const char* fam = s.family == SocketInfo::AF_INET6 ? "INET6" |
| 85 | : s.family == SocketInfo::AF_INET4 ? "INET" : "?"; |
| 86 | json o; |
| 87 | o["proto"] = proto_name; |
| 88 | o["state"] = tcp_state_name(s.state); |
| 89 | o["family"] = fam; |
| 90 | o["local_ip"] = fmt_addr(s, s.local_addr); |
| 91 | o["local_port"] = s.local_port; |
| 92 | o["remote_ip"] = fmt_addr(s, s.remote_addr); |
| 93 | o["remote_port"] = s.remote_port; |
| 94 | o["sock_va"] = fmt::format("{:#x}", s.sock_va); |
| 95 | arr.push_back(std::move(o)); |
| 96 | } |
| 97 | return dump_json(arr); |
| 98 | } |
| 99 | |
| 100 | } // anonymous |
| 101 |
no test coverage detected