Skip to content

Commit 659382f

Browse files
tpambordkalowsk
authored andcommitted
tests: net: dns-sd: Use standard struct in_addr for IPs
Refactored the code to use the standard struct in_addr for representing IPv4 addresses instead of a uint32_t combined with the custom IP_ADDR macro. Signed-off-by: Tim Pambor <[email protected]>
1 parent 7fbff46 commit 659382f

File tree

1 file changed

+6
-17
lines changed
  • tests/net/lib/dns_sd/src

1 file changed

+6
-17
lines changed

tests/net/lib/dns_sd/src/main.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
#include "dns_sd.h"
1919

2020
#define BUFSZ 256
21-
#define IP_ADDR(a, b, c, d) ((uint32_t) \
22-
0 \
23-
| ((a & 0xff) << 24) \
24-
| ((b & 0xff) << 16) \
25-
| ((c & 0xff) << 8) \
26-
| ((d & 0xff) << 0) \
27-
)
2821

2922
extern bool label_is_valid(const char *label, size_t label_size);
3023
extern int add_a_record(const struct dns_sd_rec *inst, uint32_t ttl,
@@ -441,7 +434,7 @@ ZTEST(dns_sd, test_add_a_record)
441434
const uint32_t offset = 0;
442435
const uint16_t host_offset = 0x59;
443436
/* this one is made up */
444-
const uint32_t addr = IP_ADDR(177, 5, 240, 13);
437+
const struct in_addr addr = { { { 177, 5, 240, 13 } } };
445438

446439
static uint8_t actual_buf[BUFSZ];
447440
static const uint8_t expected_buf[] = {
@@ -451,7 +444,7 @@ ZTEST(dns_sd, test_add_a_record)
451444

452445
int expected_int = sizeof(expected_buf);
453446
int actual_int = add_a_record(&nasxxxxxx, ttl, host_offset,
454-
addr, actual_buf, offset,
447+
ntohl(addr.s_addr), actual_buf, offset,
455448
sizeof(actual_buf));
456449

457450
zassert_equal(actual_int, expected_int, "");
@@ -462,12 +455,12 @@ ZTEST(dns_sd, test_add_a_record)
462455
/* test offset too large */
463456
zassert_equal(-E2BIG,
464457
add_a_record(&nasxxxxxx, ttl, DNS_SD_PTR_MASK,
465-
addr, actual_buf, offset,
458+
ntohl(addr.s_addr), actual_buf, offset,
466459
sizeof(actual_buf)), "");
467460

468461
/* test buffer too small */
469462
zassert_equal(-ENOSPC, add_a_record(&nasxxxxxx, ttl,
470-
host_offset, addr,
463+
host_offset, ntohl(addr.s_addr),
471464
actual_buf, offset,
472465
0), "");
473466
}
@@ -518,9 +511,7 @@ ZTEST(dns_sd, test_add_aaaa_record)
518511
/** Test for @ref dns_sd_handle_ptr_query */
519512
ZTEST(dns_sd, test_dns_sd_handle_ptr_query)
520513
{
521-
struct in_addr addr = {
522-
.s_addr = htonl(IP_ADDR(177, 5, 240, 13)),
523-
};
514+
struct in_addr addr = { { { 177, 5, 240, 13 } } };
524515
static uint8_t actual_rsp[512];
525516
static uint8_t expected_rsp[] = {
526517
0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01,
@@ -586,9 +577,7 @@ ZTEST(dns_sd, test_dns_sd_handle_service_type_enum)
586577
DNS_SD_EMPTY_TXT,
587578
CONST_PORT);
588579

589-
struct in_addr addr = {
590-
.s_addr = htonl(IP_ADDR(177, 5, 240, 13)),
591-
};
580+
struct in_addr addr = { { { 177, 5, 240, 13 } } };
592581
static uint8_t actual_rsp[512];
593582
static uint8_t expected_rsp[] = {
594583
0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,

0 commit comments

Comments
 (0)