@@ -90,24 +90,30 @@ struct ipv6bind {
90
90
/**
91
91
* With dual socket implementation the
92
92
* 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 .
95
95
* For example, this is done by NET_InetAddressToSockaddr.
96
96
*/
97
97
#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) \
106
112
)
107
113
108
114
#define IS_LOOPBACK_ADDRESS (x ) ( \
109
115
((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)) ) : \
111
117
((IN6_IS_ADDR_LOOPBACK(&(x)->sa6.sin6_addr)) || \
112
118
(IN6_IS_ADDR_V4MAPPED_LOOPBACK(&(x)->sa6.sin6_addr))) \
113
119
)
0 commit comments