From: Masatake YAMATO Date: Fri, 3 Feb 2023 00:32:01 +0000 (+0900) Subject: lsfd: refactor the usage of tcp_decode_state() X-Git-Tag: v2.39-rc1~83^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b182ee750b94257b44ad42ee688f1f20d54a863;p=thirdparty%2Futil-linux.git lsfd: refactor the usage of tcp_decode_state() Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-sock-xinfo.c b/misc-utils/lsfd-sock-xinfo.c index cd5c7cf7d4..8b985299d0 100644 --- a/misc-utils/lsfd-sock-xinfo.c +++ b/misc-utils/lsfd-sock-xinfo.c @@ -520,19 +520,19 @@ static char *tcp_get_name(struct sock_xinfo *sock_xinfo, struct tcp_xinfo *tcp = ((struct tcp_xinfo *)sock_xinfo); struct l4_xinfo *l4 = &tcp->l4; struct inet_xinfo *inet = &l4->inet; - unsigned int st = l4->st; + const char *st_str = tcp_decode_state(l4->st); char local_s[INET_ADDRSTRLEN], remote_s[INET_ADDRSTRLEN]; if (!inet_ntop(AF_INET, &inet->local_addr, local_s, sizeof(local_s))) - xasprintf(&str, "state=%s", tcp_decode_state(st)); - else if (st == TCP_LISTEN + xasprintf(&str, "state=%s", st_str); + else if (l4->st == TCP_LISTEN || !inet_ntop(AF_INET, &inet->remote_addr, remote_s, sizeof(remote_s))) xasprintf(&str, "state=%s laddr=%s:%u", - tcp_decode_state(st), + st_str, local_s, tcp->local_port); else xasprintf(&str, "state=%s laddr=%s:%u raddr=%s:%u", - tcp_decode_state(st), + st_str, local_s, tcp->local_port, remote_s, tcp->remote_port); return str; @@ -733,19 +733,19 @@ static char *udp_get_name(struct sock_xinfo *sock_xinfo, struct l4_xinfo *l4 = &tcp->l4; struct inet_xinfo *inet = &l4->inet; unsigned int st = l4->st; - + const char *st_str = tcp_decode_state(st); char local_s[INET_ADDRSTRLEN], remote_s[INET_ADDRSTRLEN]; if (!inet_ntop(AF_INET, &inet->local_addr, local_s, sizeof(local_s))) - xasprintf(&str, "state=%s", tcp_decode_state(st)); + xasprintf(&str, "state=%s", st_str); else if ((inet->remote_addr.s_addr == 0 && tcp->remote_port == 0) || !inet_ntop(AF_INET, &inet->remote_addr, remote_s, sizeof(remote_s))) xasprintf(&str, "state=%s laddr=%s:%u", - tcp_decode_state(st), + st_str, local_s, tcp->local_port); else xasprintf(&str, "state=%s laddr=%s:%u raddr=%s:%u", - tcp_decode_state(st), + st_str, local_s, tcp->local_port, remote_s, tcp->remote_port); return str;