From: Willy Tarreau Date: Sun, 9 May 2021 08:32:54 +0000 (+0200) Subject: BUILD: http_fetch: address a few aliasing warnings with older compilers X-Git-Tag: v2.4-dev19~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=48584645fbe8ec869b0f7f54b26945aa2aa3c26d;p=thirdparty%2Fhaproxy.git BUILD: http_fetch: address a few aliasing warnings with older compilers gcc-4.4 complains about aliasing in smp_fetch_url_port() and smp_fetch_url_ip() because the local addr variable is casted to sturct sockaddr_in before being checked. The family should be checked on the sockaddr_storage and we have a function to retrieve the port. The compiler still sees some warnings but these ones are OK now. --- diff --git a/src/http_fetch.c b/src/http_fetch.c index 020b25fcf5..1f3fa4e0cd 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -710,7 +710,7 @@ static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const ch sl = http_get_stline(htx); url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL); - if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) + if (addr.ss_family != AF_INET) return 0; smp->data.type = SMP_T_IPV4; @@ -731,11 +731,11 @@ static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const sl = http_get_stline(htx); url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL); - if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) + if (addr.ss_family != AF_INET) return 0; smp->data.type = SMP_T_SINT; - smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port); + smp->data.u.sint = get_host_port(&addr); smp->flags = 0; return 1; }