| 547 | } |
| 548 | |
| 549 | ByteBuf format_interfaces(const Engine& eng) { |
| 550 | auto ifs = enumerate_interfaces(eng); |
| 551 | if (ifs.empty()) { |
| 552 | const char msg[] = "; no interfaces enumerated (init_net unreadable or ISF lacks fields)\n"; |
| 553 | return ByteBuf(msg, msg + sizeof(msg) - 1); |
| 554 | } |
| 555 | std::string out; |
| 556 | out.reserve(2 * 1024); |
| 557 | out += fmt::format("# {} network interfaces (init namespace)\n", ifs.size()); |
| 558 | for (const auto& f : ifs) { |
| 559 | // Decode common flags (subset). |
| 560 | std::string fl; |
| 561 | if (f.flags & 0x0001) fl += "UP,"; |
| 562 | if (f.flags & 0x0002) fl += "BROADCAST,"; |
| 563 | if (f.flags & 0x0008) fl += "LOOPBACK,"; |
| 564 | if (f.flags & 0x0040) fl += "RUNNING,"; |
| 565 | if (f.flags & 0x1000) fl += "MULTICAST,"; |
| 566 | if (!fl.empty()) fl.pop_back(); |
| 567 | out += fmt::format("\n{:>3}: {} <{}> mtu {}\n", |
| 568 | f.ifindex, f.name, fl, f.mtu); |
| 569 | for (const auto& a : f.ipv4_addrs) |
| 570 | out += fmt::format(" inet {}\n", a); |
| 571 | for (const auto& a : f.ipv6_addrs) |
| 572 | out += fmt::format(" inet6 {}\n", a); |
| 573 | } |
| 574 | return ByteBuf(out.begin(), out.end()); |
| 575 | } |
| 576 | |
| 577 | } // namespace lmpfs::linux |
no test coverage detected