Commit 794162bb authored by Tom Lane's avatar Tom Lane

Fix convSockAddr6to4(): eliminate bogus assumptions about byte ordering,

remove useless SockAddr_ntop() call.  Per report from Andreas Pflug.
parent d6f1aa97
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.4 2003/04/02 00:49:28 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.5 2003/04/02 20:00:21 tgl Exp $
* *
* This file and the IPV6 implementation were initially provided by * This file and the IPV6 implementation were initially provided by
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design * Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
...@@ -328,18 +328,13 @@ rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr, ...@@ -328,18 +328,13 @@ rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr,
static void static void
convSockAddr6to4(const SockAddr *src, SockAddr *dst) convSockAddr6to4(const SockAddr *src, SockAddr *dst)
{ {
char addr_str[INET6_ADDRSTRLEN]; MemSet(dst, 0, sizeof(*dst));
dst->in.sin_family = AF_INET; dst->in.sin_family = AF_INET;
/* both src and dst are assumed to be in network byte order */
dst->in.sin_port = src->in6.sin6_port; dst->in.sin_port = src->in6.sin6_port;
memcpy(&dst->in.sin_addr.s_addr,
dst->in.sin_addr.s_addr = ((char *) (&src->in6.sin6_addr.s6_addr)) + 12,
(src->in6.sin6_addr.s6_addr[15]) sizeof(struct in_addr));
+ (src->in6.sin6_addr.s6_addr[14] << 8)
+ (src->in6.sin6_addr.s6_addr[13] << 16)
+ (src->in6.sin6_addr.s6_addr[12] << 24);
SockAddr_ntop(src, addr_str, INET6_ADDRSTRLEN, 0);
} }
#endif /* HAVE_IPV6 */ #endif /* HAVE_IPV6 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment