From a79d86609be467db6a5660be3861a7b3a73c54a9 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Sat, 13 Nov 2010 11:42:26 -0500 Subject: [PATCH] Wrap raw_packet() with specialized bcast_raw_packet(). --- ndhc/clientpacket.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ndhc/clientpacket.c b/ndhc/clientpacket.c index 731cbe5..ecff649 100644 --- a/ndhc/clientpacket.c +++ b/ndhc/clientpacket.c @@ -102,6 +102,13 @@ static void add_requests(struct dhcpMessage *packet) packet->options[end + OPT_DATA + len] = DHCP_END; } +/* Wrapper that broadcasts a raw dhcp packet on the bound interface. */ +static int bcast_raw_packet(struct dhcpMessage *packet) +{ + return raw_packet(packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, + SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); +} + /* Broadcast a DHCP discover packet to the network, with an optionally * requested IP */ int send_discover(uint32_t xid, uint32_t requested) @@ -117,8 +124,7 @@ int send_discover(uint32_t xid, uint32_t requested) add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); add_requests(&packet); log_line("Sending discover..."); - return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, - SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); + return bcast_raw_packet(&packet); } /* Broadcasts a DHCP request message */ @@ -136,8 +142,7 @@ int send_selecting(uint32_t xid, uint32_t server, uint32_t requested) add_requests(&packet); addr.s_addr = requested; log_line("Sending select for %s...", inet_ntoa(addr)); - return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, - SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); + return bcast_raw_packet(&packet); } /* Unicasts or broadcasts a DHCP renew message */ @@ -155,8 +160,7 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) if (server) ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); else - ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, - SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); + ret = bcast_raw_packet(&packet); return ret; }