From dba7f0f5cee06dcfc205b0284ba19c2651f594c4 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 17 Jun 2024 11:55:04 +0200 Subject: treewide: Replace strerror() calls Now that we have logging functions embedding perror() functionality, we can make _some_ calls more terse by using them. In many places, the strerror() calls are still more convenient because, for example, they are used in flow debugging functions, or because the return code variable of interest is not 'errno'. While at it, convert a few error messages from a scant perror style to proper failure descriptions. Signed-off-by: Stefano Brivio Reviewed-by: David Gibson --- tcp.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index a2e81d5..698e7ec 100644 --- a/tcp.c +++ b/tcp.c @@ -1553,19 +1553,15 @@ static void tcp_bind_outbound(const struct ctx *c, int s, sa_family_t af) .sin_addr = c->ip4.addr_out, }; - if (bind(s, (struct sockaddr *)&addr4, sizeof(addr4))) { - debug("Can't bind IPv4 TCP socket address: %s", - strerror(errno)); - } + if (bind(s, (struct sockaddr *)&addr4, sizeof(addr4))) + debug_perror("IPv4 TCP socket address bind"); } if (*c->ip4.ifname_out) { if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, c->ip4.ifname_out, - strlen(c->ip4.ifname_out))) { - debug("Can't bind IPv4 TCP socket to interface:" - " %s", strerror(errno)); - } + strlen(c->ip4.ifname_out))) + debug_perror("IPv4 TCP socket interface bind"); } } else if (af == AF_INET6) { if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr_out)) { @@ -1575,19 +1571,15 @@ static void tcp_bind_outbound(const struct ctx *c, int s, sa_family_t af) .sin6_addr = c->ip6.addr_out, }; - if (bind(s, (struct sockaddr *)&addr6, sizeof(addr6))) { - debug("Can't bind IPv6 TCP socket address: %s", - strerror(errno)); - } + if (bind(s, (struct sockaddr *)&addr6, sizeof(addr6))) + debug_perror("IPv6 TCP socket address bind"); } if (*c->ip6.ifname_out) { if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, c->ip6.ifname_out, - strlen(c->ip6.ifname_out))) { - debug("Can't bind IPv6 TCP socket to interface:" - " %s", strerror(errno)); - } + strlen(c->ip6.ifname_out))) + debug_perror("IPv6 TCP socket interface bind"); } } } -- cgit v1.2.3