Skip to content
Permalink
Browse files
8255264: Support for identifying the full range of IPv4 localhost add…
…resses on Windows

Backport-of: 7e01bc9
  • Loading branch information
macarte authored and RealCLanger committed Nov 29, 2021
1 parent a412974 commit 5d99c71f5cd6665062fc14dde6e6c08ad393cbea
Showing 1 changed file with 17 additions and 11 deletions.
@@ -90,24 +90,30 @@ struct ipv6bind {
/**
* With dual socket implementation the
* IPv4 addresseses might be mapped as IPv6.
* The IPv4 loopback adapter address will
* be mapped as the following IPv6 ::ffff:127.0.0.1.
* The IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255) will
* be mapped as the following IPv6 ::ffff:127.0.0.0 through ::ffff:127.255.255.255.
* For example, this is done by NET_InetAddressToSockaddr.
*/
#define IN6_IS_ADDR_V4MAPPED_LOOPBACK(x) ( \
(((x)->s6_words[0] == 0) && \
((x)->s6_words[1] == 0) && \
((x)->s6_words[2] == 0) && \
((x)->s6_words[3] == 0) && \
((x)->s6_words[4] == 0) && \
((x)->s6_words[5] == 0xFFFF) && \
((x)->s6_words[6] == 0x007F) && \
((x)->s6_words[7] == 0x0100)) \
(((x)->s6_words[0] == 0) && \
((x)->s6_words[1] == 0) && \
((x)->s6_words[2] == 0) && \
((x)->s6_words[3] == 0) && \
((x)->s6_words[4] == 0) && \
((x)->s6_words[5] == 0xFFFF) && \
(((x)->s6_words[6] & 0x00FF) == 0x007F)) \
)

/**
* Check for IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255)
*/
#define IN4_IS_ADDR_NETLONG_LOOPBACK(l) ( \
((l & 0xFF000000) == 0x7F000000) \
)

#define IS_LOOPBACK_ADDRESS(x) ( \
((x)->sa.sa_family == AF_INET) ? \
(ntohl((x)->sa4.sin_addr.s_addr) == INADDR_LOOPBACK) : \
(IN4_IS_ADDR_NETLONG_LOOPBACK(ntohl((x)->sa4.sin_addr.s_addr))) : \
((IN6_IS_ADDR_LOOPBACK(&(x)->sa6.sin6_addr)) || \
(IN6_IS_ADDR_V4MAPPED_LOOPBACK(&(x)->sa6.sin6_addr))) \
)

1 comment on commit 5d99c71

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 5d99c71 Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.