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 {
11 namespace operator_ {
12 
13 STANDARD_OPERATOR_2(network, Equal, type::Bool(), type::Network(), type::Network(), "Compares two network values.")
14 STANDARD_OPERATOR_2(network, Unequal, type::Bool(), type::Network(), type::Network(), "Compares two network values.")
15 STANDARD_OPERATOR_2(network, In, type::Bool(), type::Address(), type::Network(),
16  "Returns true if the address is part of the network range.")
17 
18 BEGIN_METHOD(network, Family)
19  auto signature() const {
20  return Signature{.self = type::Network(),
21  .result = builder::typeByID("hilti::AddressFamily"),
22  .id = "family",
23  .args = {},
24  .doc = R"(
25 Returns the protocol family of the network, which can be IPv4 or IPv6.
26 )"};
27  }
28 END_METHOD
29 
30 BEGIN_METHOD(network, Prefix)
31  auto signature() const {
32  return Signature{.self = type::Network(), .result = type::Address(), .id = "prefix", .args = {}, .doc = R"(
33 Returns the network's prefix as a masked IP address.
34 )"};
35  }
36 END_METHOD
37 
38 BEGIN_METHOD(network, Length)
39  auto signature() const {
40  return Signature{.self = type::Network(),
41  .result = type::SignedInteger(64),
42  .id = "length",
43  .args = {},
44  .doc = R"(
45 Returns the length of the network's prefix.
46 )"};
47  }
48 END_METHOD
49 
50 } // namespace operator_
51 } // namespace hilti