Skip to content

Commit 7e01bc9

Browse files
macarteAlan Bateman
authored and
Alan Bateman
committed
8255264: Support for identifying the full range of IPv4 localhost addresses on Windows
Reviewed-by: alanb
1 parent 8a05d60 commit 7e01bc9

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/java.base/windows/native/libnet/net_util_md.h

+17-11
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,30 @@ struct ipv6bind {
9090
/**
9191
* With dual socket implementation the
9292
* IPv4 addresseses might be mapped as IPv6.
93-
* The IPv4 loopback adapter address will
94-
* be mapped as the following IPv6 ::ffff:127.0.0.1.
93+
* The IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255) will
94+
* be mapped as the following IPv6 ::ffff:127.0.0.0 through ::ffff:127.255.255.255.
9595
* For example, this is done by NET_InetAddressToSockaddr.
9696
*/
9797
#define IN6_IS_ADDR_V4MAPPED_LOOPBACK(x) ( \
98-
(((x)->s6_words[0] == 0) && \
99-
((x)->s6_words[1] == 0) && \
100-
((x)->s6_words[2] == 0) && \
101-
((x)->s6_words[3] == 0) && \
102-
((x)->s6_words[4] == 0) && \
103-
((x)->s6_words[5] == 0xFFFF) && \
104-
((x)->s6_words[6] == 0x007F) && \
105-
((x)->s6_words[7] == 0x0100)) \
98+
(((x)->s6_words[0] == 0) && \
99+
((x)->s6_words[1] == 0) && \
100+
((x)->s6_words[2] == 0) && \
101+
((x)->s6_words[3] == 0) && \
102+
((x)->s6_words[4] == 0) && \
103+
((x)->s6_words[5] == 0xFFFF) && \
104+
(((x)->s6_words[6] & 0x00FF) == 0x007F)) \
105+
)
106+
107+
/**
108+
* Check for IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255)
109+
*/
110+
#define IN4_IS_ADDR_NETLONG_LOOPBACK(l) ( \
111+
((l & 0xFF000000) == 0x7F000000) \
106112
)
107113

108114
#define IS_LOOPBACK_ADDRESS(x) ( \
109115
((x)->sa.sa_family == AF_INET) ? \
110-
(ntohl((x)->sa4.sin_addr.s_addr) == INADDR_LOOPBACK) : \
116+
(IN4_IS_ADDR_NETLONG_LOOPBACK(ntohl((x)->sa4.sin_addr.s_addr))) : \
111117
((IN6_IS_ADDR_LOOPBACK(&(x)->sa6.sin6_addr)) || \
112118
(IN6_IS_ADDR_V4MAPPED_LOOPBACK(&(x)->sa6.sin6_addr))) \
113119
)

0 commit comments

Comments
 (0)