#include <string.h>
#include <stdio.h>
#include <net/ethernet.h>
+#include <net/if_arp.h>
#include <sys/param.h>
#include <sys/ioctl.h>
}
static int client_send_discover(sd_dhcp_client *client) {
- _cleanup_free_ DHCPPacket *discover;
+ _cleanup_free_ DHCPPacket *discover = NULL;
size_t optlen, len;
uint8_t *opt;
usec_t time_now;
assert(client);
- r = sd_event_get_now_monotonic(client->event, &time_now);
+ r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
if (r < 0)
return r;
assert(time_now >= client->start_time);
assert(client);
assert(client->event);
- r = sd_event_get_now_monotonic(client->event, &time_now);
+ r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
if (r < 0)
goto error;
client->timeout_resend = sd_event_source_unref(client->timeout_resend);
- r = sd_event_add_monotonic(client->event,
- &client->timeout_resend,
- next_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_resend, client);
+ r = sd_event_add_time(client->event,
+ &client->timeout_resend,
+ CLOCK_MONOTONIC,
+ next_timeout, 10 * USEC_PER_MSEC,
+ client_timeout_resend, client);
if (r < 0)
goto error;
client->timeout_resend = sd_event_source_unref(client->timeout_resend);
- r = sd_event_add_monotonic(client->event,
- &client->timeout_resend, 0, 0,
- client_timeout_resend, client);
+ r = sd_event_add_time(client->event,
+ &client->timeout_resend,
+ CLOCK_MONOTONIC,
+ 0, 0,
+ client_timeout_resend, client);
if (r < 0)
goto error;
if (client->lease->lifetime == 0xffffffff)
return 0;
- r = sd_event_get_now_monotonic(client->event, &time_now);
+ r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
if (r < 0)
return r;
assert(client->request_sent <= time_now);
}
/* arm lifetime timeout */
- r = sd_event_add_monotonic(client->event,
- &client->timeout_expire, lifetime_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_expire, client);
+ r = sd_event_add_time(client->event, &client->timeout_expire,
+ CLOCK_MONOTONIC,
+ lifetime_timeout, 10 * USEC_PER_MSEC,
+ client_timeout_expire, client);
if (r < 0)
return r;
return 0;
/* arm T2 timeout */
- r = sd_event_add_monotonic(client->event,
- &client->timeout_t2,
- t2_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_t2, client);
+ r = sd_event_add_time(client->event,
+ &client->timeout_t2,
+ CLOCK_MONOTONIC,
+ t2_timeout,
+ 10 * USEC_PER_MSEC,
+ client_timeout_t2, client);
if (r < 0)
return r;
return 0;
/* arm T1 timeout */
- r = sd_event_add_monotonic(client->event,
- &client->timeout_t1,
- t1_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_t1, client);
+ r = sd_event_add_time(client->event,
+ &client->timeout_t1,
+ CLOCK_MONOTONIC,
+ t1_timeout, 10 * USEC_PER_MSEC,
+ client_timeout_t1, client);
if (r < 0)
return r;
return 0;
}
+ if (be32toh(message->magic) != DHCP_MAGIC_COOKIE) {
+ log_dhcp_client(client, "not a DHCP message: ignoring");
+ return 0;
+ }
+
if (message->op != BOOTREPLY) {
log_dhcp_client(client, "not a BOOTREPLY message: ignoring");
return 0;
return 0;
}
+ if (message->htype != ARPHRD_ETHER || message->hlen != ETHER_ADDR_LEN) {
+ log_dhcp_client(client, "not an ethernet packet");
+ return 0;
+ }
+
if (memcmp(&message->chaddr[0], &client->client_id.mac_addr,
ETH_ALEN)) {
log_dhcp_client(client, "received chaddr does not match "
client->state = DHCP_STATE_REQUESTING;
client->attempt = 1;
- r = sd_event_add_monotonic(client->event,
- &client->timeout_resend, 0,
- 0, client_timeout_resend,
- client);
+ r = sd_event_add_time(client->event,
+ &client->timeout_resend,
+ CLOCK_MONOTONIC,
+ 0, 0,
+ client_timeout_resend, client);
if (r < 0)
goto error;