There is no real need to have print_host() with the extra arguments. So convert the last remaining print_host() calls to use print_addr(). I'm not entierly sure how to really test all these code paths but the changes are failry simple.
-- :wq Claudio Index: ikev2.c =================================================================== RCS file: /cvs/src/sbin/iked/ikev2.c,v retrieving revision 1.370 diff -u -p -r1.370 ikev2.c --- ikev2.c 13 Jun 2023 12:34:12 -0000 1.370 +++ ikev2.c 13 Jun 2023 13:18:56 -0000 @@ -2285,7 +2285,7 @@ ikev2_nat_detection(struct iked *env, st struct sockaddr_in *in4; struct sockaddr_in6 *in6; ssize_t ret = -1; - struct sockaddr *src, *dst, *ss; + struct sockaddr_storage *src, *dst, *ss; uint64_t rspi, ispi; struct ibuf *buf; uint32_t rnd; @@ -2299,13 +2299,13 @@ ikev2_nat_detection(struct iked *env, st return (-1); ispi = hdr->ike_ispi; rspi = hdr->ike_rspi; - src = (struct sockaddr *)&msg->msg_peer; - dst = (struct sockaddr *)&msg->msg_local; + src = &msg->msg_peer; + dst = &msg->msg_local; } else { ispi = htobe64(sa->sa_hdr.sh_ispi); rspi = htobe64(sa->sa_hdr.sh_rspi); - src = (struct sockaddr *)&msg->msg_local; - dst = (struct sockaddr *)&msg->msg_peer; + src = &msg->msg_local; + dst = &msg->msg_peer; } ctx = EVP_MD_CTX_new(); @@ -2337,7 +2337,7 @@ ikev2_nat_detection(struct iked *env, st EVP_DigestUpdate(ctx, &ispi, sizeof(ispi)); EVP_DigestUpdate(ctx, &rspi, sizeof(rspi)); - switch (ss->sa_family) { + switch (ss->ss_family) { case AF_INET: in4 = (struct sockaddr_in *)ss; EVP_DigestUpdate(ctx, &in4->sin_addr.s_addr, @@ -6941,8 +6941,7 @@ ikev2_print_id(struct iked_id *id, char s4->sin_len = sizeof(*s4); memcpy(&s4->sin_addr.s_addr, ptr, len); - if (print_host((struct sockaddr *)s4, - idstr, idstrlen) == NULL) + if (strlcpy(idstr, print_addr(s4), idstrlen) >= idstrlen) return (-1); break; case IKEV2_ID_FQDN: @@ -6965,8 +6964,7 @@ ikev2_print_id(struct iked_id *id, char s6->sin6_len = sizeof(*s6); memcpy(&s6->sin6_addr, ptr, len); - if (print_host((struct sockaddr *)s6, - idstr, idstrlen) == NULL) + if (strlcpy(idstr, print_addr(s6), idstrlen) >= idstrlen) return (-1); break; case IKEV2_ID_ASN1_DN: Index: ikev2_pld.c =================================================================== RCS file: /cvs/src/sbin/iked/ikev2_pld.c,v retrieving revision 1.129 diff -u -p -r1.129 ikev2_pld.c --- ikev2_pld.c 6 Jun 2023 16:09:35 -0000 1.129 +++ ikev2_pld.c 14 Jun 2023 08:41:36 -0000 @@ -1522,9 +1522,8 @@ int ikev2_pld_ts(struct iked *env, struct ikev2_payload *pld, struct iked_message *msg, size_t offset, size_t left, unsigned int type) { - struct sockaddr_in s4; - struct sockaddr_in6 s6; - uint8_t buf[2][128]; + struct sockaddr_in start4, end4; + struct sockaddr_in6 start6, end6; uint8_t *msgbuf = ibuf_data(msg->msg_data); uint8_t *ptr; @@ -1539,22 +1538,21 @@ ikev2_pld_ts(struct iked *env, struct ik return (-1); } - bzero(&s4, sizeof(s4)); - s4.sin_family = AF_INET; - s4.sin_len = sizeof(s4); - memcpy(&s4.sin_addr.s_addr, ptr, 4); + bzero(&start4, sizeof(start4)); + start4.sin_family = AF_INET; + start4.sin_len = sizeof(start4); + memcpy(&start4.sin_addr.s_addr, ptr, 4); ptr += 4; left -= 4; - print_host((struct sockaddr *)&s4, - (char *)buf[0], sizeof(buf[0])); - memcpy(&s4.sin_addr.s_addr, ptr, 4); + bzero(&end4, sizeof(end4)); + end4.sin_family = AF_INET; + end4.sin_len = sizeof(end4); + memcpy(&end4.sin_addr.s_addr, ptr, 4); left -= 4; - print_host((struct sockaddr *)&s4, - (char *)buf[1], sizeof(buf[1])); log_debug("%s: start %s end %s", __func__, - buf[0], buf[1]); + print_addr(&start4), print_addr(&end4)); break; case IKEV2_TS_IPV6_ADDR_RANGE: if (left < 2 * 16) { @@ -1563,21 +1561,21 @@ ikev2_pld_ts(struct iked *env, struct ik __func__, left, 2 * 16); return (-1); } - bzero(&s6, sizeof(s6)); - s6.sin6_family = AF_INET6; - s6.sin6_len = sizeof(s6); - memcpy(&s6.sin6_addr, ptr, 16); + bzero(&start6, sizeof(start6)); + start6.sin6_family = AF_INET6; + start6.sin6_len = sizeof(start6); + memcpy(&start6.sin6_addr, ptr, 16); ptr += 16; left -= 16; - print_host((struct sockaddr *)&s6, - (char *)buf[0], sizeof(buf[0])); - memcpy(&s6.sin6_addr, ptr, 16); + bzero(&end6, sizeof(end6)); + end6.sin6_family = AF_INET6; + end6.sin6_len = sizeof(end6); + memcpy(&end6.sin6_addr, ptr, 16); left -= 16; - print_host((struct sockaddr *)&s6, - (char *)buf[1], sizeof(buf[1])); + log_debug("%s: start %s end %s", __func__, - buf[0], buf[1]); + print_addr(&start6), print_addr(&end6)); break; default: log_debug("%s: ignoring unknown TS type %u", __func__, type); @@ -1949,9 +1947,8 @@ ikev2_pld_cp(struct iked *env, struct ik in4->sin_family = AF_INET; in4->sin_len = sizeof(*in4); memcpy(&in4->sin_addr.s_addr, ptr, 4); - print_host((struct sockaddr *)in4, (char *)buf, - sizeof(buf)); - log_debug("%s: cfg %s", __func__, buf); + log_debug("%s: cfg %s", __func__, + print_addr(&addr->addr)); switch(cfg_type) { case IKEV2_CFG_INTERNAL_IP4_ADDRESS: msg->msg_parent->msg_cp_addr = addr; @@ -1999,9 +1996,8 @@ ikev2_pld_cp(struct iked *env, struct ik in6->sin6_family = AF_INET6; in6->sin6_len = sizeof(*in6); memcpy(&in6->sin6_addr, ptr, 16); - print_host((struct sockaddr *)in6, (char *)buf, - sizeof(buf)); - log_debug("%s: cfg %s/%d", __func__, buf, ptr[16]); + log_debug("%s: cfg %s/%d", __func__, + print_addr(&addr->addr), ptr[16]); switch(cfg_type) { case IKEV2_CFG_INTERNAL_IP6_ADDRESS: msg->msg_parent->msg_cp_addr6 = addr; Index: parse.y =================================================================== RCS file: /cvs/src/sbin/iked/parse.y,v retrieving revision 1.142 diff -u -p -r1.142 parse.y --- parse.y 19 Apr 2023 13:33:37 -0000 1.142 +++ parse.y 13 Jun 2023 13:14:51 -0000 @@ -2880,8 +2880,7 @@ create_ike(char *name, int af, struct ip if (dstid) strlcpy(idstr, dstid, sizeof(idstr)); else if (!pol.pol_peer.addr_net) - print_host((struct sockaddr *)&pol.pol_peer.addr, idstr, - sizeof(idstr)); + strlcpy(idstr, print_addr(&pol.pol_peer.addr), sizeof(idstr)); ikeauth = &pol.pol_auth; switch (ikeauth->auth_method) {