diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2026-01-16 11:59:13 +1100 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-01-18 12:47:29 +0100 |
| commit | 016e3d756447ebadb45fb68719b4ea28bb12d103 (patch) | |
| tree | f592279c8f49e404dc7a612d84be481c2bcdff31 | |
| parent | 81c97f66595f4fab5171ebcb42f43e9f1505b4c4 (diff) | |
| download | passt-016e3d756447ebadb45fb68719b4ea28bb12d103.tar passt-016e3d756447ebadb45fb68719b4ea28bb12d103.tar.gz passt-016e3d756447ebadb45fb68719b4ea28bb12d103.tar.bz2 passt-016e3d756447ebadb45fb68719b4ea28bb12d103.tar.lz passt-016e3d756447ebadb45fb68719b4ea28bb12d103.tar.xz passt-016e3d756447ebadb45fb68719b4ea28bb12d103.tar.zst passt-016e3d756447ebadb45fb68719b4ea28bb12d103.zip | |
inany: Extend inany_ntop() to treat NULL as a fully unspecified address
In a number of places we're using a convention that a NULL inany represents
a dual-stack unspecified address, that is one which includes both 0.0.0.0
and ::. Extend inany_ntop() to handle that convention, representing it
as "*".
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | inany.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -22,7 +22,7 @@ const union inany_addr inany_loopback4 = INANY_INIT4(IN4ADDR_LOOPBACK_INIT); const union inany_addr inany_any4 = INANY_INIT4(IN4ADDR_ANY_INIT); /** inany_ntop - Convert an IPv[46] address to text format - * @src: IPv[46] address + * @src: IPv[46] address (NULL for unspecified) * @dst: output buffer, minimum INANY_ADDRSTRLEN bytes * @size: size of buffer at @dst * @@ -30,9 +30,12 @@ const union inany_addr inany_any4 = INANY_INIT4(IN4ADDR_ANY_INIT); */ const char *inany_ntop(const union inany_addr *src, char *dst, socklen_t size) { - const struct in_addr *v4 = inany_v4(src); + const struct in_addr *v4; + + if (!src) + return strncpy(dst, "*", size); - if (v4) + if ((v4 = inany_v4(src))) return inet_ntop(AF_INET, v4, dst, size); return inet_ntop(AF_INET6, &src->a6, dst, size); |
