#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <net/if.h>
#include "sd-dhcp-client.h"
#include "sd-event.h"
#include "dhcp-internal.h"
#include "dhcp-protocol.h"
#include "fd-util.h"
+#include "random-util.h"
#include "tests.h"
#include "util.h"
assert_se(dhcp_packet_checksum((uint8_t*)&buf, 20) == be16toh(0x78ae));
}
+static void test_dhcp_identifier_set_iaid(void) {
+ uint32_t iaid;
+ int ifindex;
+
+ for (;;) {
+ char ifname[IFNAMSIZ];
+
+ /* try to find an ifindex which does not exist. I causes dhcp_identifier_set_iaid()
+ * to hash the MAC address. */
+ pseudo_random_bytes(&ifindex, sizeof(ifindex));
+ if (ifindex > 0 && !if_indextoname(ifindex, ifname))
+ break;
+ }
+
+ assert_se(dhcp_identifier_set_iaid(ifindex, mac_addr, sizeof(mac_addr), &iaid) >= 0);
+
+ /* we expect, that the MAC address was hashed. Note that the value is in native
+ * endianness. */
+ assert_se(iaid == 0x8dde4ba8u);
+}
+
static int check_options(uint8_t code, uint8_t len, const void *option, void *userdata) {
switch(code) {
case SD_DHCP_OPTION_CLIENT_IDENTIFIER:
test_request_basic(e);
test_request_anonymize(e);
test_checksum();
+ test_dhcp_identifier_set_iaid();
test_discover_message(e);
test_addr_acq(e);