MCPcopy Create free account
hub / github.com/MemNixFS/MemNixFS / format_sockets_json

Function format_sockets_json

src/os/linux/json_export.cpp:75–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75ByteBuf 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

Callers 2

format_tcp_jsonFunction · 0.85
format_udp_jsonFunction · 0.85

Calls 5

enumerate_udp_socketsFunction · 0.85
enumerate_tcp_socketsFunction · 0.85
dump_jsonFunction · 0.85
tcp_state_nameFunction · 0.70
fmt_addrFunction · 0.70

Tested by

no test coverage detected