This is an automated email from the ASF dual-hosted git repository. bneradt pushed a commit to branch ipsrv in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
commit 109a69a3b28e5d550b9ea8e360a66cd3b654cd41 Author: Alan M. Carroll <[email protected]> AuthorDate: Sun Nov 13 08:58:04 2022 -0600 Fix overzealous refactor. --- code/src/bw_format.cc | 61 ------------------------------------------- doc/code/BW_Format.en.rst | 6 ++--- doc/code/ip_networking.en.rst | 8 +++--- unit_tests/test_ip.cc | 12 ++++++--- 4 files changed, 16 insertions(+), 71 deletions(-) diff --git a/code/src/bw_format.cc b/code/src/bw_format.cc index 29a06fb..ac9ce9e 100644 --- a/code/src/bw_format.cc +++ b/code/src/bw_format.cc @@ -943,67 +943,6 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Pattern const &pattern) { return w; } -// --- IP address support --- - -#if 0 -BufferWriter & -bwformat(BufferWriter &w, bwf::Spec const &spec, IpAddr const &addr) -{ - bwf::Spec local_spec{spec}; // Format for address elements and host_order_port. - bool addr_p{true}; - bool family_p{false}; - - if (spec._ext.size()) { - if (spec._ext.front() == '=') { - local_spec._ext.remove_prefix(1); - } else if (spec._ext.size() > 1 && spec._ext[1] == '=') { - local_spec._ext.remove_prefix(2); - } - } - if (local_spec._ext.size()) { - addr_p = false; - for (char c : local_spec._ext) { - switch (c) { - case 'a': - case 'A': - addr_p = true; - break; - case 'f': - case 'F': - family_p = true; - break; - } - } - } - - if (addr_p) { - if (addr.isIp4()) { - bwformat(w, spec, addr._addr._ip4); - } else if (addr.isIp6()) { - bwformat(w, spec, addr._addr._ip6); - } else { - w.print("*Not IP address [{}]*", addr.family()); - } - } - - if (family_p) { - local_spec._min = 0; - if (addr_p) { - w.write(' '); - } - if (spec.has_numeric_type()) { - bwformat(w, local_spec, static_cast<uintmax_t>(addr.family())); - } else { - bwformat(w, local_spec, addr.family()); - } - } - return w; -} -#endif - -namespace { -} // namespace - }} // namespace swoc::SWOC_VERSION_NS namespace std { diff --git a/doc/code/BW_Format.en.rst b/doc/code/BW_Format.en.rst index 99f2eb5..d8a1e81 100644 --- a/doc/code/BW_Format.en.rst +++ b/doc/code/BW_Format.en.rst @@ -501,14 +501,14 @@ Specific types The pointer address is printed as hexadecimal lower ('p') or upper ('P') case. The extension can be used to control which parts of the address are printed. These can be in any order, - the output is always address, host_order_port, family. The default is the equivalent of "ap". In addition, the + the output is always address, port, family. The default is the equivalent of "ap". In addition, the character '=' ("numeric align") can be used to internally right justify the elements. 'a' The address. 'p' - The host_order_port (host order). + The port (host order). 'f' The IP address family. @@ -521,7 +521,7 @@ Specific types void func(sockaddr const* addr) { bw.print("To {}", addr); // -> "To 172.19.3.105:4951" - bw.print("To {0::a} on host_order_port {0::p}", addr); // -> "To 172.19.3.105 on host_order_port 4951" + bw.print("To {0::a} on port {0::p}", addr); // -> "To 172.19.3.105 on port 4951" bw.print("To {::=}", addr); // -> "To 127.019.003.105:04951" bw.print("Using address family {::f}", addr); bw.print("{::a}",addr); // -> "172.19.3.105" diff --git a/doc/code/ip_networking.en.rst b/doc/code/ip_networking.en.rst index 2efcdb2..055bd29 100644 --- a/doc/code/ip_networking.en.rst +++ b/doc/code/ip_networking.en.rst @@ -25,9 +25,9 @@ IPEndpoint :libswoc:`swoc::IPEndpoint` is a wrapper around :code:`sockaddr` and provides a number of utilities. It enables constructing an instance from the string representation of an address, supporting IPv4 -and IPv6. It will also parse and store the host_order_port if that is part of the string. Some of the internal +and IPv6. It will also parse and store the port if that is part of the string. Some of the internal logic is exposed via :libswoc:`swoc::IPEndpoint::tokenize` which finds and returns the elements of -an address string, the host (address), host_order_port, and any trailing remnants. This is useful for doing +an address string, the host (address), port, and any trailing remnants. This is useful for doing syntax checks or more specialized processing of the address string. IPAddr @@ -53,10 +53,10 @@ will conform to the family of the address in the :code:`sockaddr`. IPSrv ===== -A container for an address and a host_order_port. There is no really good name for this therefore I used the +A container for an address and a port. There is no really good name for this therefore I used the DNS term for such an object. This consists of the usual triplet of classes, :swoc:`IP4Srv`, :swoc:`IP6Srv`, and :swoc:`IPSrv`. The first two are protocol family specific and the third holds an instance of -either an :code:`IP4Srv` or an `IP6Srv`. The address and host_order_port can be manipulated separately. +either an :code:`IP4Srv` or an `IP6Srv`. The address and port can be manipulated separately. IPRange ======= diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc index 128c4ba..ffac762 100644 --- a/unit_tests/test_ip.cc +++ b/unit_tests/test_ip.cc @@ -107,6 +107,11 @@ TEST_CASE("Basic IP", "[libswoc][ip]") { REQUIRE(alpha[2] == 0x0D); REQUIRE(alpha[3] == 0x56); CHECK_FALSE(alpha.load("192.172.3.")); + CHECK(alpha.load("192.0xAC.014.135")); + REQUIRE(alpha[0] == 192); + REQUIRE(alpha[1] == 172); + REQUIRE(alpha[2] == 12); + REQUIRE(alpha[3] == 135); CHECK(IP6Addr().load("ffee:1f2d:c587:24c3:9128:3349:3cee:143")); @@ -349,7 +354,7 @@ TEST_CASE("IP Formatting", "[libswoc][ip][bwformat]") { w.clear().print("{:: =a}", ep); REQUIRE(w.view() == "ffee: 0: 0: 0:24c3:3349:3cee: 143"); - // Verify @c IPEndpoint will parse without the host_order_port. + // Verify @c IPEndpoint will parse without the port. REQUIRE(ep.parse(addr_8) == true); REQUIRE(ep.network_order_port() == 0); REQUIRE(ep.parse(addr_9) == true); @@ -399,8 +404,8 @@ TEST_CASE("IP Formatting", "[libswoc][ip][bwformat]") { REQUIRE(ep.parse(addr_7) == true); w.clear().print("To {}", ep); REQUIRE(w.view() == "To 172.19.3.105:4951"); - w.clear().print("To {0::a} on host_order_port {0::p}", ep); // no need to pass the argument twice. - REQUIRE(w.view() == "To 172.19.3.105 on host_order_port 4951"); + w.clear().print("To {0::a} on port {0::p}", ep); // no need to pass the argument twice. + REQUIRE(w.view() == "To 172.19.3.105 on port 4951"); w.clear().print("To {::=}", ep); REQUIRE(w.view() == "To 172.019.003.105:04951"); w.clear().print("{::a}", ep); @@ -1849,6 +1854,7 @@ TEST_CASE("IPSrv", "[libswoc][IPSrv]") { CHECK(s4_1.load("10.2:56")); CHECK_FALSE(s4_1.load("10.1.2.3.567899")); CHECK_FALSE(s4_1.load("10.1.2.3.56f")); + CHECK_FALSE(s4_1.load("10.1.2.56f")); CHECK(s4_1.load("10.1.2.3")); REQUIRE(s4_1.host_order_port() == 0);
