Spicy
network.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <hilti/ast/builder/type.h>
6 #include <hilti/ast/operators/common.h>
7 #include <hilti/ast/types/integer.h>
8 #include <hilti/ast/types/network.h>
9 
10 namespace hilti::operator_ {
11 
12 STANDARD_OPERATOR_2(network, Equal, type::Bool(), type::Network(), type::Network(), "Compares two network values.")
13 STANDARD_OPERATOR_2(network, Unequal, type::Bool(), type::Network(), type::Network(), "Compares two network values.")
14 STANDARD_OPERATOR_2(network, In, type::Bool(), type::Address(), type::Network(),
15  "Returns true if the address is part of the network range.")
16 
17 BEGIN_METHOD(network, Family)
18  const auto& signature() const {
19  static auto _signature = Signature{.self = type::Network(),
20  .result = builder::typeByID("hilti::AddressFamily"),
21  .id = "family",
22  .args = {},
23  .doc = R"(
24 Returns the protocol family of the network, which can be IPv4 or IPv6.
25 )"};
26  return _signature;
27  }
28 END_METHOD
29 
30 BEGIN_METHOD(network, Prefix)
31  const auto& signature() const {
32  static auto _signature =
33  Signature{.self = type::Network(), .result = type::Address(), .id = "prefix", .args = {}, .doc = R"(
34 Returns the network's prefix as a masked IP address.
35 )"};
36  return _signature;
37  }
38 END_METHOD
39 
40 BEGIN_METHOD(network, Length)
41  const auto& signature() const {
42  static auto _signature =
43  Signature{.self = type::Network(), .result = type::SignedInteger(64), .id = "length", .args = {}, .doc = R"(
44 Returns the length of the network's prefix.
45 )"};
46  return _signature;
47  }
48 END_METHOD
49 
50 } // namespace hilti::operator_
Definition: operator-registry.h:15