summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2022-02-03 00:21:30 -0800
committerAndreas Kling <kling@serenityos.org>2022-02-03 14:57:16 +0100
commit2b14a112381ac945b5c6d66829e622b1db257214 (patch)
tree948a95d09f1f033cf4af4c7ceb36f764ca9f7451
parente8857f9b2d42b2464f50616438ad5137cd99ab30 (diff)
downloadserenity-2b14a112381ac945b5c6d66829e622b1db257214.zip
LibC: Add IN6_IS_ADDR_LINKLOCAL to in.h
I tried the OpenSSH port but it failed to compile due to a missing definition of this macro. It's simple enough to add, and it's addition allowed OpenSSH to compile once again. I also went ahead and added spec comments for these macros as well.
-rw-r--r--Userland/Libraries/LibC/netinet/in.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/netinet/in.h b/Userland/Libraries/LibC/netinet/in.h
index 9f340719ed..5b8e1274e5 100644
--- a/Userland/Libraries/LibC/netinet/in.h
+++ b/Userland/Libraries/LibC/netinet/in.h
@@ -41,10 +41,19 @@ static inline uint32_t ntohl(uint32_t value)
return htonl(value);
}
+// NOTE: The IPv6 Addressing Scheme that we detect are documented in RFC# 2373.
+// See: https://datatracker.ietf.org/doc/html/rfc2373
+
+// RFC# 2373 - 2.5.3 The Loopback Address
#define IN6_IS_ADDR_LOOPBACK(addr) \
((addr)->s6_addr[0] == 0 && (addr)->s6_addr[1] == 0 && (addr)->s6_addr[2] == 0 && (addr)->s6_addr[3] == 0 && (addr)->s6_addr[4] == 0 && (addr)->s6_addr[5] == 0 && (addr)->s6_addr[6] == 0 && (addr)->s6_addr[7] == 0 && (addr)->s6_addr[8] == 0 && (addr)->s6_addr[9] == 0 && (addr)->s6_addr[10] == 0 && (addr)->s6_addr[11] == 0 && (addr)->s6_addr[12] == 0 && (addr)->s6_addr[13] == 0 && (addr)->s6_addr[14] == 0 && (addr)->s6_addr[15] == 1)
+// RFC# 2373 - 2.5.4 IPv6 Addresses with Embedded IPv4 Addresses
#define IN6_IS_ADDR_V4MAPPED(addr) \
((((addr)->s6_addr[0]) == 0) && (((addr)->s6_addr[1]) == 0) && (((addr)->s6_addr[2]) == 0) && (((addr)->s6_addr[3]) == 0) && (((addr)->s6_addr[4]) == 0) && (((addr)->s6_addr[5]) == 0) && (((addr)->s6_addr[6]) == 0) && (((addr)->s6_addr[7]) == 0) && (((addr)->s6_addr[8]) == 0) && (((addr)->s6_addr[9]) == 0) && (((addr)->s6_addr[10]) == 0xFF) && (((addr)->s6_addr[11]) == 0xFF))
+// RFC# 2373 - 2.5.8 Local-Use IPv6 Unicast Addresses
+#define IN6_IS_ADDR_LINKLOCAL(addr) \
+ (((addr)->s6_addr[0] == 0xfe) && (((addr)->s6_addr[1] & 0xc0) == 0x80))
+
__END_DECLS