1
0
mirror of https://passt.top/passt synced 2024-09-28 10:05:47 +00:00

treewide: Use IN4ADDR_LOOPBACK_INIT more widely

We already define IN4ADDR_LOOPBACK_INIT to initialise a struct in_addr to
the loopback address without delving into its internals.  However there are
some places we don't use it, and explicitly look at the internal structure
of struct in_addr, which we generally want to avoid.  Use the define more
widely to avoid that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2023-12-08 01:31:34 +11:00 committed by Stefano Brivio
parent 1f2aab8aaa
commit 546332786c
3 changed files with 4 additions and 4 deletions

2
tcp.c
View File

@ -2976,7 +2976,7 @@ static void tcp_ns_sock_init4(const struct ctx *c, in_port_t port)
.port = port + c->tcp.fwd_out.delta[port],
.pif = PIF_SPLICE,
};
struct in_addr loopback = { htonl(INADDR_LOOPBACK) };
struct in_addr loopback = IN4ADDR_LOOPBACK_INIT;
int s;
ASSERT(c->mode == MODE_PASTA);

View File

@ -347,7 +347,7 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn,
struct sockaddr_in addr4 = {
.sin_family = AF_INET,
.sin_port = htons(port),
.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
.sin_addr = IN4ADDR_LOOPBACK_INIT,
};
const struct sockaddr *sa;
socklen_t sl;

4
udp.c
View File

@ -429,7 +429,7 @@ int udp_splice_new(const struct ctx *c, int v6, in_port_t src, bool ns)
struct sockaddr_in addr4 = {
.sin_family = AF_INET,
.sin_port = htons(src),
.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
.sin_addr = IN4ADDR_LOOPBACK_INIT,
};
if (bind(s, (struct sockaddr *)&addr4, sizeof(addr4)))
goto fail;
@ -1012,7 +1012,7 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
udp_tap_map[V4][uref.port].sock = s < 0 ? -1 : s;
udp_splice_init[V4][port].sock = s < 0 ? -1 : s;
} else {
struct in_addr loopback = { htonl(INADDR_LOOPBACK) };
struct in_addr loopback = IN4ADDR_LOOPBACK_INIT;
r4 = s = sock_l4(c, AF_INET, IPPROTO_UDP, &loopback,
ifname, port, uref.u32);