ywkaras commented on code in PR #10944:
URL: https://github.com/apache/trafficserver/pull/10944#discussion_r1430905082


##########
lib/swoc/include/swoc/swoc_ip_util.h:
##########
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright Network Geographics 2014
+/** @file
+   Shared utilities for IP address classes.
+ */
+
+#pragma once
+#include <netinet/in.h>
+
+#include "swoc/swoc_version.h"
+
+// These have to be global namespace, unfortunately.
+inline bool
+operator==(in6_addr const& lhs, in6_addr const& rhs) {
+  return 0 == memcmp(&lhs, &rhs, sizeof(in6_addr));
+}
+
+inline bool
+operator!=(in6_addr const& lhs, in6_addr const& rhs) {
+  return 0 != memcmp(&lhs, &rhs, sizeof(in6_addr));
+}
+
+namespace swoc { inline namespace SWOC_VERSION_NS {
+
+/// Internal IP address utilities.
+namespace ip {
+
+inline bool is_loopback_host_order(in_addr_t addr) {
+  return (addr & 0xFF000000) == 0x7F000000;
+}
+
+inline bool is_link_local_host_order(in_addr_t addr) {
+  return (addr & 0xFFFF0000) == 0xA9FE0000; // 169.254.0.0/16

Review Comment:
   `((169 << 24)|(254 << 16))` is less error-prone.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to