From db72c4bf2385deb118d98fbf3459633f324ed822 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 24 Mar 2024 00:26:53 +0000 Subject: linux_inet_diag: avoid errors for users compiling w/o assertions We should warn gracefully when we hit IPv7+ or whatever... --- ext/raindrops/linux_inet_diag.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c index 2fd158a..79f24bb 100644 --- a/ext/raindrops/linux_inet_diag.c +++ b/ext/raindrops/linux_inet_diag.c @@ -208,7 +208,9 @@ static struct listen_stats *stats_for(addr2stats *a2s, struct inet_diag_msg *r) break; } default: - assert(0 && "unsupported address family, could that be IPv7?!"); + fprintf(stderr, "unsupported .idiag_family: %u\n", + (unsigned)r->idiag_family); + return NULL; /* can't raise w/o GVL */ } if (!inet_ntop(r->idiag_family, src, host, hostlen)) { bug_warn_nogvl("BUG: inet_ntop: %s\n", strerror(errno)); @@ -228,7 +230,8 @@ static struct listen_stats *stats_for(addr2stats *a2s, struct inet_diag_msg *r) port = host + hostlen + 2; break; default: - assert(0 && "unsupported address family, could that be IPv7?!"); + assert(0 && "should never get here (returned above)"); + abort(); } n = snprintf(port, portlen, "%u", ntohs(r->id.idiag_sport)); @@ -278,12 +281,14 @@ static struct listen_stats *stats_for(addr2stats *a2s, struct inet_diag_msg *r) static void table_incr_active(addr2stats *a2s, struct inet_diag_msg *r) { struct listen_stats *stats = stats_for(a2s, r); + if (!stats) return; ++stats->active; } static void table_set_queued(addr2stats *a2s, struct inet_diag_msg *r) { struct listen_stats *stats = stats_for(a2s, r); + if (!stats) return; stats->listener_p = 1; stats->queued += r->idiag_rqueue; } -- cgit v1.2.3-24-ge0c7