diff --git a/repos/os/src/lib/net/dhcp.cc b/repos/os/src/lib/net/dhcp.cc index 2f9567617e..afb1060223 100644 --- a/repos/os/src/lib/net/dhcp.cc +++ b/repos/os/src/lib/net/dhcp.cc @@ -15,9 +15,59 @@ #include #include +using namespace Genode; + +using Message_type = Net::Dhcp_packet::Message_type; + + +static char const *msg_type_to_string(Message_type type) +{ + switch (type) { + case Message_type::DISCOVER: return "DISCOVER"; + case Message_type::OFFER : return "OFFER"; + case Message_type::REQUEST : return "REQUEST"; + case Message_type::DECLINE : return "DECLINE"; + case Message_type::ACK : return "ACK"; + case Message_type::NAK : return "NAK"; + case Message_type::RELEASE : return "RELEASE"; + case Message_type::INFORM : return "INFORM"; + } + class Never_reached { }; + throw Never_reached { }; +} + + +static char const *opcode_to_string(uint8_t op) +{ + switch (op) { + case 1: return "REPLY"; + case 2: return "REQUEST"; + default: return "?"; + } + class Never_reached { }; + throw Never_reached { }; +} + void Net::Dhcp_packet::print(Genode::Output &output) const { - Genode::print(output, "\033[32mDHCP\033[0m ", client_mac(), - " > ", siaddr(), " cmd ", op()); + bool msg_type_found { false }; + for_each_option([&] (Option const &opt) { + + if (opt.code() == Option::Code::MSG_TYPE) { + + msg_type_found = true; + Message_type_option const &msg_type { + *reinterpret_cast(&opt) }; + + Genode::print(output, "\033[32mDHCP ", + msg_type_to_string(msg_type.value()), "\033[0m ", + client_mac(), " > ", siaddr()); + } + }); + if (!msg_type_found) { + + Genode::print(output, "\033[32mDHCP ", opcode_to_string(op()), + "\033[0m ", client_mac(), " > ", siaddr()); + } }