Skip to content

Commit

Permalink
reach into address bytes when converting struct in6_addr to ziti_addr…
Browse files Browse the repository at this point in the history
…ess. (#869)
  • Loading branch information
scareything authored Jun 14, 2024
1 parent 35e298d commit 2cab71f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ziti-tunnel/intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ziti_address_from_in6_addr(ziti_address *za, const struct in6_addr *a) {
za->type = ziti_address_cidr;
za->addr.cidr.af = AF_INET6;
za->addr.cidr.bits = 128;
memcpy(&za->addr.cidr.ip, &a, sizeof(struct in6_addr));
memcpy(&za->addr.cidr.ip, &a->s6_addr, sizeof(struct in6_addr));
}

void ziti_address_from_sockaddr_in(ziti_address *za, const struct sockaddr_in *sin) {
Expand Down
16 changes: 16 additions & 0 deletions lib/ziti-tunnel/tests/address_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,20 @@ TEST_CASE("address_match", "[address]") {
REQUIRE(model_map_get(&tctx.intercepts_cache, "tcp:192.168.0.10:81") == intercept_s3);

// todo hostname and wildcard dns matching
}

TEST_CASE("address_conversion", "[address]") {
const char *ip6_str = "2768:8631:c02:ffc9::1308";
ip_addr_t ip6;
ipaddr_aton(ip6_str, &ip6);
ziti_address za_from_ip6;
ziti_address_from_ip_addr(&za_from_ip6, &ip6);

ziti_address za_from_str;
ziti_address_from_string(&za_from_str, ip6_str);

char za_str[128];
ziti_address_print(za_str, sizeof(za_str), &za_from_ip6);
fprintf(stderr, "%s converted to %s\n", ip6_str, za_str);
REQUIRE(ziti_address_match(&za_from_ip6, &za_from_str) == 0);
}

0 comments on commit 2cab71f

Please sign in to comment.