From de361e0258afa77e46afad5a90fc874bb0a95eea Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 6 May 2024 22:57:39 -0700 Subject: [PATCH] IPv4 host network addresses convert with htonl() not htons() (#501) --- src/inet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/inet.c b/src/inet.c index ecdbab6..1526a57 100644 --- a/src/inet.c +++ b/src/inet.c @@ -26,6 +26,7 @@ #include #include #include +/* if using inet_ntop you must #include */ #endif /* DOS */ #if (defined(OS5) || defined(__CYGWIN__)) && !defined(O_ASYNC) @@ -93,7 +94,8 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li LispStringToCString(nameConn, namestring, 100); host = gethostbyname(namestring); if (!host) return (NIL); - N_ARITH_SWITCH(ntohl(*(long *)host->h_addr)); + res = ntohl(*(in_addr_t *)host->h_addr); + N_ARITH_SWITCH(res); break; case TCPservicelookup: @@ -120,7 +122,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li case TCPconnect: /* args: hostname or (fixp)address, socket# */ memset(&farend, 0, sizeof farend); N_GETNUMBER(nameConn, res, string_host); - farend.sin_addr.s_addr = htons(res); + farend.sin_addr.s_addr = htonl(res); goto host_ok; string_host: LispStringToCString(nameConn, namestring, 100);