Skip to content

Commit

Permalink
8255264: Support for identifying the full range of IPv4 localhost add…
Browse files Browse the repository at this point in the history
…resses on Windows

Reviewed-by: alanb
  • Loading branch information
macarte authored and Alan Bateman committed Jan 6, 2021
1 parent 8a05d60 commit 7e01bc9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/java.base/windows/native/libnet/net_util_md.h
Expand Up @@ -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))) \
)
Expand Down

3 comments on commit 7e01bc9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@macarte
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 7e01bc9 Oct 27, 2021

Choose a reason for hiding this comment

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

@macarte Only OpenJDK contributors can use the /backport command

Please sign in to comment.