diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c index 8dd2af9081f4..9b60069028d4 100644 --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c @@ -218,21 +218,11 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - if (ipv6) { - struct sockaddr_in6 *c = (struct sockaddr_in6 *)&caddr; - - c->sin6_family = AF_INET6; - inet_pton(AF_INET6, VETH0_ADDR6, &c->sin6_addr); - c->sin6_port = htons(CLIENT_PORT); - err = bind(client_rx_fd, (struct sockaddr *)c, sizeof(*c)); - } else { - struct sockaddr_in *c = (struct sockaddr_in *)&caddr; - - c->sin_family = AF_INET; - inet_pton(AF_INET, VETH0_ADDR, &c->sin_addr); - c->sin_port = htons(CLIENT_PORT); - err = bind(client_rx_fd, (struct sockaddr *)c, sizeof(*c)); - } + if (ipv6) + make_sockaddr(AF_INET6, VETH0_ADDR6, CLIENT_PORT, &caddr, &caddr_len); + else + make_sockaddr(AF_INET, VETH0_ADDR, CLIENT_PORT, &caddr, &caddr_len); + err = bind(client_rx_fd, (struct sockaddr *)&caddr, sizeof(caddr)); close_netns(nstoken); if (!ASSERT_OK(err, "bind")) goto out;