diff --git a/src/dhcp.c b/src/dhcp.c index 043975d..162f001 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -470,7 +470,7 @@ ssize_t send_selecting(struct client_state_t cs[static 1]) return send_dhcp_raw(&packet); } -ssize_t send_renew(struct client_state_t cs[static 1]) +ssize_t send_renew_or_rebind(struct client_state_t cs[static 1], bool is_renew) { struct dhcpmsg packet = {.xid = cs->xid}; init_packet(&packet, DHCPREQUEST); @@ -478,20 +478,9 @@ ssize_t send_renew(struct client_state_t cs[static 1]) add_option_maxsize(&packet); add_option_request_list(&packet); add_options_vendor_hostname(&packet); - log_line("%s: Sending a renew request...", client_config.interface); - return send_dhcp_unicast(cs, &packet); -} - -ssize_t send_rebind(struct client_state_t cs[static 1]) -{ - struct dhcpmsg packet = {.xid = cs->xid}; - init_packet(&packet, DHCPREQUEST); - packet.ciaddr = cs->clientAddr; - add_option_maxsize(&packet); - add_option_request_list(&packet); - add_options_vendor_hostname(&packet); - log_line("%s: Sending a rebind request...", client_config.interface); - return send_dhcp_raw(&packet); + log_line("%s: Sending a %s request...", client_config.interface, + is_renew? "renew" : "rebind"); + return is_renew? send_dhcp_unicast(cs, &packet) : send_dhcp_raw(&packet); } ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server) diff --git a/src/dhcp.h b/src/dhcp.h index 99aa448..c90757c 100644 --- a/src/dhcp.h +++ b/src/dhcp.h @@ -89,8 +89,15 @@ bool dhcp_packet_get(struct client_state_t cs[static 1], uint32_t srcaddr[static 1]); ssize_t send_discover(struct client_state_t cs[static 1]); ssize_t send_selecting(struct client_state_t cs[static 1]); -ssize_t send_renew(struct client_state_t cs[static 1]); -ssize_t send_rebind(struct client_state_t cs[static 1]); +ssize_t send_renew_or_rebind(struct client_state_t cs[static 1], bool is_renew); +static inline ssize_t send_renew(struct client_state_t cs[static 1]) +{ + return send_renew_or_rebind(cs, true); +} +static inline ssize_t send_rebind(struct client_state_t cs[static 1]) +{ + return send_renew_or_rebind(cs, false); +} ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server); ssize_t send_release(struct client_state_t cs[static 1]);