43 const uint8_t *src_addr,
const uint8_t *dest_addr,
const int proto)
62#define LONGDOMAIN "a-reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally-long-domain"
63 const char *search_list[] = {
72 const unsigned char output_1[28] =
"\x77\x1a\x07openvpn\x03net\x00\x07openvpn\x03org";
75 assert_memory_equal(
BPTR(&out_buf), output_1,
sizeof(output_1));
86 const unsigned char output_2[0xEC + 3 + 1] =
"\x77\xEE\xEC" LONGDOMAIN;
89 assert_memory_equal(
BPTR(&out_buf), output_2,
sizeof(output_2));
92 const unsigned char output_3[0xEC + 3 + 10 + 7 + 1] =
"\x77\xFF\x09subdomain\xEC" LONGDOMAIN "\x06top123";
95 assert_memory_equal(
BPTR(&out_buf), output_3,
sizeof(output_3));
98 const unsigned char output_4[0xEC + 3 + 10 + 7 + 1] =
"\x77\xFF\xFDsubdomain-" LONGDOMAIN "-top123";
101 assert_memory_equal(
BPTR(&out_buf), output_4,
sizeof(output_4));
117 const char output_5[12] =
"\x77\x0a\x03sub\x00\x03tld";
120 assert_memory_equal(
BPTR(&out_buf), output_5,
sizeof(output_5));
129#define D50 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
130#define D47 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
132 assert_int_equal(strlen(
D50), 50);
133 assert_int_equal(strlen(
D47), 47);
147 const struct CMUnitTest tests[] = {
151 return cmocka_run_group_tests_name(
"dhcp", tests, NULL, NULL);
void buf_clear(struct buffer *buf)
Zeroise and reset a buffer.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
#define BPTR(buf)
Return a pointer to the start of the buffer content.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
static int buf_forward_capacity_total(const struct buffer *buf)
Return the total number of bytes available from the current offset to the end of the allocated memory...
static void write_dhcp_search_str(struct buffer *buf, const uint8_t type, const char *const *str_array, int array_len, bool *error)
#define DHCP_DOMAIN_SEARCH
Wrapper structure for dynamically allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
unsigned short sa_family_t
static void test_write_dhcp_search_str(void **state)
uint16_t ip_checksum(const sa_family_t af, const uint8_t *payload, const int len_payload, const uint8_t *src_addr, const uint8_t *dest_addr, const int proto)
Calculates an IP or IPv6 checksum with a pseudo header as required by TCP, UDP and ICMPv6.
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)