dhcp-client: Use dprintln for debug printing

This commit is contained in:
Bananymous 2024-02-05 01:24:45 +02:00
parent 692cec8458
commit 89805fb092
1 changed files with 13 additions and 12 deletions

View File

@ -1,3 +1,4 @@
#include <BAN/Debug.h>
#include <BAN/Endianness.h> #include <BAN/Endianness.h>
#include <BAN/IPv4.h> #include <BAN/IPv4.h>
#include <BAN/MAC.h> #include <BAN/MAC.h>
@ -12,7 +13,7 @@
#include <stropts.h> #include <stropts.h>
#include <sys/socket.h> #include <sys/socket.h>
#define DEBUG_DHCP 0 #define DEBUG_DHCP 1
struct DHCPPacket struct DHCPPacket
{ {
@ -304,12 +305,12 @@ int main()
auto mac_address = get_mac_address(socket); auto mac_address = get_mac_address(socket);
#if DEBUG_DHCP #if DEBUG_DHCP
BAN::Formatter::println(putchar, "MAC: {}", mac_address); dprintln("MAC: {}", mac_address);
#endif #endif
send_dhcp_discover(socket, mac_address); send_dhcp_discover(socket, mac_address);
#if DEBUG_DHCP #if DEBUG_DHCP
printf("DHCPDISCOVER sent\n"); dprintln("DHCPDISCOVER sent");
#endif #endif
auto dhcp_offer = read_dhcp_packet(socket); auto dhcp_offer = read_dhcp_packet(socket);
@ -322,15 +323,15 @@ int main()
} }
#if DEBUG_DHCP #if DEBUG_DHCP
BAN::Formatter::println(putchar, "DHCPOFFER"); dprintln("DHCPOFFER");
BAN::Formatter::println(putchar, " IP {}", dhcp_offer->address); dprintln(" IP {}", dhcp_offer->address);
BAN::Formatter::println(putchar, " SUBNET {}", dhcp_offer->subnet); dprintln(" SUBNET {}", dhcp_offer->subnet);
BAN::Formatter::println(putchar, " SERVER {}", dhcp_offer->server); dprintln(" SERVER {}", dhcp_offer->server);
#endif #endif
send_dhcp_request(socket, mac_address, dhcp_offer->address, dhcp_offer->server); send_dhcp_request(socket, mac_address, dhcp_offer->address, dhcp_offer->server);
#if DEBUG_DHCP #if DEBUG_DHCP
printf("DHCPREQUEST sent\n"); dprintln("DHCPREQUEST sent");
#endif #endif
auto dhcp_ack = read_dhcp_packet(socket); auto dhcp_ack = read_dhcp_packet(socket);
@ -343,10 +344,10 @@ int main()
} }
#if DEBUG_DHCP #if DEBUG_DHCP
BAN::Formatter::println(putchar, "DHCPACK"); dprintln("DHCPACK");
BAN::Formatter::println(putchar, " IP {}", dhcp_ack->address); dprintln(" IP {}", dhcp_ack->address);
BAN::Formatter::println(putchar, " SUBNET {}", dhcp_ack->subnet); dprintln(" SUBNET {}", dhcp_ack->subnet);
BAN::Formatter::println(putchar, " SERVER {}", dhcp_ack->server); dprintln(" SERVER {}", dhcp_ack->server);
#endif #endif
if (dhcp_offer->address != dhcp_ack->address) if (dhcp_offer->address != dhcp_ack->address)