From 3e5cf09486cd6f881bf0f2ea9e437fa32b7f6034 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 12 Feb 2025 11:42:44 -0400 Subject: [PATCH] MT#55283 convert endpoint_parse_any_getaddrinfo_alt to bool Change-Id: I6e4437ce60065205c13271b96ee6b346af0a24fa --- daemon/main.c | 2 +- daemon/websocket.c | 4 ++-- lib/socket.c | 14 +++++++------- lib/socket.h | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index 8b1baf39a..88841a762 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -531,7 +531,7 @@ static void parse_listen_list(GQueue *out, char **epv, const char *option) { for (; *epv; epv++) { char *ep = *epv; endpoint_t x, y; - if (endpoint_parse_any_getaddrinfo_alt(&x, &y, ep)) + if (!endpoint_parse_any_getaddrinfo_alt(&x, &y, ep)) die("Invalid IP or port '%s' ('%s')", ep, option); if (x.port) g_queue_push_tail(out, endpoint_dup(&x)); diff --git a/daemon/websocket.c b/daemon/websocket.c index 137b27210..599f8f6c3 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -1117,7 +1117,7 @@ int websocket_init(void) { ilogs(http, LOG_DEBUG, "Starting HTTP/WS '%s'", ifa); endpoint_t eps[2]; err = "Failed to parse address/port"; - if (endpoint_parse_any_getaddrinfo_alt(&eps[0], &eps[1], ifa)) + if (!endpoint_parse_any_getaddrinfo_alt(&eps[0], &eps[1], ifa)) goto err; addr_any_v6_consolidate(eps, have_lws_ipv6); @@ -1164,7 +1164,7 @@ int websocket_init(void) { ilogs(http, LOG_DEBUG, "Starting HTTPS/WSS '%s'", ifa); endpoint_t eps[2]; err = "Failed to parse address/port"; - if (endpoint_parse_any_getaddrinfo_alt(&eps[0], &eps[1], ifa)) + if (!endpoint_parse_any_getaddrinfo_alt(&eps[0], &eps[1], ifa)) goto err; addr_any_v6_consolidate(eps, have_lws_ipv6); diff --git a/lib/socket.c b/lib/socket.c index c236b4b18..7951d9941 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -674,7 +674,7 @@ bool sockaddr_getaddrinfo_alt(sockaddr_t *a, sockaddr_t *a2, const char *s) { return ret; } -int endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char *s) { +bool endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char *s) { unsigned int len; const char *ep; char buf[64]; @@ -682,7 +682,7 @@ int endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char ep = strrchr(s, ':'); if (!ep) { if (strchr(s, '.')) - return -1; + return false; /* just a port number */ d->port = atoi(s); ZERO(d->address); @@ -692,14 +692,14 @@ int endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char *d2 = *d; ipv46_any_convert(d2); } - return 0; + return true; } len = ep - s; if (len >= sizeof(buf)) - return -1; + return false; d->port = atoi(ep+1); if (d->port > 0xffff) - return -1; + return false; /* original s was [IPv6]:port */ if ((len > 2) && (s[0] == '[') && (s[len - 1] == ']')) { @@ -709,7 +709,7 @@ int endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char } if (!sockaddr_getaddrinfo_alt(&d->address, d2 ? &d2->address : NULL, buf)) - return -1; + return false; if (d2) { if (d2->address.family) @@ -718,7 +718,7 @@ int endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char ZERO(*d2); } - return 0; + return true; } static int __socket(socket_t *r, int type, sockfamily_t *fam) { diff --git a/lib/socket.h b/lib/socket.h index e4d2d0091..1eec005a3 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -291,7 +291,7 @@ bool sockaddr_parse_any_str(sockaddr_t *dst, const str *src); bool sockaddr_parse_str(sockaddr_t *dst, sockfamily_t *fam, const str *src); bool endpoint_parse_any(endpoint_t *, const char *); // address (ip) optional bool sockaddr_getaddrinfo_alt(sockaddr_t *a, sockaddr_t *a2, const char *s); -int endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char *s); // address (ip or hostname) optional +bool endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char *s); // address (ip or hostname) optional INLINE int endpoint_parse_any_getaddrinfo(endpoint_t *d, const char *s); void endpoint_parse_sockaddr_storage(endpoint_t *, struct sockaddr_storage *); void kernel2endpoint(endpoint_t *ep, const struct re_address *ra); @@ -339,7 +339,7 @@ INLINE int sockaddr_getaddrinfo(sockaddr_t *a, const char *s) { return sockaddr_getaddrinfo_alt(a, NULL, s) ? 0 : 1; } INLINE int endpoint_parse_any_getaddrinfo(endpoint_t *d, const char *s) { - return endpoint_parse_any_getaddrinfo_alt(d, NULL, s); + return endpoint_parse_any_getaddrinfo_alt(d, NULL, s) ? 0 : 1; } INLINE int ipv46_any_convert(endpoint_t *ep) { if (ep->address.family->af != AF_INET)