diff --git a/src/net/AllocatedSocketAddress.cxx b/src/net/AllocatedSocketAddress.cxx
index 3deb78909..d38f6ed4b 100644
--- a/src/net/AllocatedSocketAddress.cxx
+++ b/src/net/AllocatedSocketAddress.cxx
@@ -30,7 +30,6 @@
 #include "AllocatedSocketAddress.hxx"
 #include "IPv4Address.hxx"
 #include "IPv6Address.hxx"
-#include "util/StringView.hxx"
 
 #include <string.h>
 
diff --git a/src/net/SocketAddress.cxx b/src/net/SocketAddress.cxx
index 6963c50b7..94ce4b8bb 100644
--- a/src/net/SocketAddress.cxx
+++ b/src/net/SocketAddress.cxx
@@ -131,6 +131,8 @@ SocketAddress::GetPort() const noexcept
 	}
 }
 
+#ifdef __cpp_lib_span
+
 static std::span<const std::byte>
 GetSteadyPart(const struct sockaddr_in &address) noexcept
 {
@@ -149,7 +151,11 @@ GetSteadyPart(const struct sockaddr_in6 &address) noexcept
 	};
 }
 
-#endif
+#endif // __cpp_lib_span
+
+#endif // HAVE_TCP
+
+#ifdef __cpp_lib_span
 
 std::span<const std::byte>
 SocketAddress::GetSteadyPart() const noexcept
@@ -175,3 +181,5 @@ SocketAddress::GetSteadyPart() const noexcept
 		return {};
 	}
 }
+
+#endif
diff --git a/src/net/SocketAddress.hxx b/src/net/SocketAddress.hxx
index 420d32939..f7a0d4e39 100644
--- a/src/net/SocketAddress.hxx
+++ b/src/net/SocketAddress.hxx
@@ -39,7 +39,14 @@
 #endif
 
 #include <cstddef>
+
+#if __cplusplus >= 202002 || (defined(__GNUC__) && __GNUC__ >= 10)
+#include <version>
+#endif
+
+#ifdef __cpp_lib_span
 #include <span>
+#endif
 
 #ifdef HAVE_UN
 #include <string_view>
@@ -72,10 +79,6 @@ public:
 				size_type _size) noexcept
 		:address(_address), size(_size) {}
 
-	explicit SocketAddress(std::span<const std::byte> src) noexcept
-		:address((const struct sockaddr *)(const void *)src.data()),
-		 size(src.size()) {}
-
 	static constexpr SocketAddress Null() noexcept {
 		return nullptr;
 	}
@@ -161,14 +164,7 @@ public:
 	unsigned GetPort() const noexcept;
 #endif
 
-	operator std::span<const std::byte>() const noexcept {
-		const void *q = reinterpret_cast<const void *>(address);
-		return {
-			(const std::byte *)q,
-			(std::size_t)size,
-		};
-	}
-
+#ifdef __cpp_lib_span
 	/**
 	 * Return a buffer pointing to the "steady" portion of the
 	 * address, i.e. without volatile parts like the port number.
@@ -178,6 +174,7 @@ public:
 	 */
 	[[gnu::pure]]
 	std::span<const std::byte> GetSteadyPart() const noexcept;
+#endif
 
 	[[gnu::pure]]
 	bool operator==(const SocketAddress other) const noexcept;