Skip to content

Commit 794162b

Browse files
committed
Fix convSockAddr6to4(): eliminate bogus assumptions about byte ordering,
remove useless SockAddr_ntop() call. Per report from Andreas Pflug.
1 parent d6f1aa9 commit 794162b

File tree

1 file changed

+6
-11
lines changed
  • src/backend/libpq

1 file changed

+6
-11
lines changed

src/backend/libpq/ip.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.4 2003/04/02 00:49:28 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.5 2003/04/02 20:00:21 tgl Exp $
1212
*
1313
* This file and the IPV6 implementation were initially provided by
1414
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -328,18 +328,13 @@ rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr,
328328
static void
329329
convSockAddr6to4(const SockAddr *src, SockAddr *dst)
330330
{
331-
char addr_str[INET6_ADDRSTRLEN];
332-
331+
MemSet(dst, 0, sizeof(*dst));
333332
dst->in.sin_family = AF_INET;
333+
/* both src and dst are assumed to be in network byte order */
334334
dst->in.sin_port = src->in6.sin6_port;
335-
336-
dst->in.sin_addr.s_addr =
337-
(src->in6.sin6_addr.s6_addr[15])
338-
+ (src->in6.sin6_addr.s6_addr[14] << 8)
339-
+ (src->in6.sin6_addr.s6_addr[13] << 16)
340-
+ (src->in6.sin6_addr.s6_addr[12] << 24);
341-
342-
SockAddr_ntop(src, addr_str, INET6_ADDRSTRLEN, 0);
335+
memcpy(&dst->in.sin_addr.s_addr,
336+
((char *) (&src->in6.sin6_addr.s6_addr)) + 12,
337+
sizeof(struct in_addr));
343338
}
344339

345340
#endif /* HAVE_IPV6 */

0 commit comments

Comments
 (0)