Skip to content

Commit de361e0

Browse files
authored
IPv4 host network addresses convert with htonl() not htons() (#501)
1 parent 3979cdd commit de361e0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/inet.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/time.h>
2727
#include <sys/types.h>
2828
#include <unistd.h>
29+
/* if using inet_ntop you must #include <arpa/inet.h> */
2930
#endif /* DOS */
3031

3132
#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
9394
LispStringToCString(nameConn, namestring, 100);
9495
host = gethostbyname(namestring);
9596
if (!host) return (NIL);
96-
N_ARITH_SWITCH(ntohl(*(long *)host->h_addr));
97+
res = ntohl(*(in_addr_t *)host->h_addr);
98+
N_ARITH_SWITCH(res);
9799
break;
98100

99101
case TCPservicelookup:
@@ -120,7 +122,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
120122
case TCPconnect: /* args: hostname or (fixp)address, socket# */
121123
memset(&farend, 0, sizeof farend);
122124
N_GETNUMBER(nameConn, res, string_host);
123-
farend.sin_addr.s_addr = htons(res);
125+
farend.sin_addr.s_addr = htonl(res);
124126
goto host_ok;
125127
string_host:
126128
LispStringToCString(nameConn, namestring, 100);

0 commit comments

Comments
 (0)