2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
29#ifndef IPADDRESS_ERRORS_HPP
30#define IPADDRESS_ERRORS_HPP
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
117
118
119
120
121
122
123
124
125 template <
typename FirstArg,
typename... Args>
126 explicit error(
error_code code,
const FirstArg& arg,
const Args&... args) : std::runtime_error(concatenate(arg, args...)), _code(code) {
130
131
132
133
134
135 explicit error(
error_code code,
const std::string& message) : std::runtime_error(message), _code(code) {
139
140
141
142
143
144 explicit error(
error_code code,
const char* message) : std::runtime_error(message), _code(code) {
148
149
150
151
161 template <
typename... Args>
162 static std::string concatenate(
const Args&... args) {
163 std::ostringstream ss;
168 template <
typename FirstArg,
typename... Args>
169 static void concat(std::ostringstream& out,
const FirstArg& arg,
const Args&... args) {
170 print(out, arg) <<
' ';
171 concat(out, args...);
174 template <
typename FirstArg>
175 static void concat(std::ostringstream& out,
const FirstArg& arg) {
179 template <
typename T>
180 static std::ostringstream& print(std::ostringstream& out,
const T& arg) {
185 static std::ostringstream& print(std::ostringstream& out,
const symbol& arg);
187 template <
typename T, size_t N>
188 static std::ostringstream& print(std::ostringstream& out,
const T (&str)[N]);
194
195
196
197
198
199
200
201
202
206
207
208
209
210
211
212
213
214 template <
typename FirstArg,
typename... Args>
219
220
221
222
223
228
229
230
231
232
238
239
240
241
242
243
244
245
246
250
251
252
253
254
255
256
257
258 template <
typename FirstArg,
typename... Args>
263
264
265
266
267
272
273
274
275
276
282
283
284
285
286
287
288
289
290
291
292
293
294
295
297#ifndef IPADDRESS_NO_EXCEPTIONS
301#ifndef IPADDRESS_NO_EXCEPTIONS
303 size_t max_len = length;
307 for (size_t i = 0; i < max_len; ++i) {
319 throw parse_error(code,
"empty mask in address", str);
321 throw parse_error(code,
"is not a valid netmask in address", str);
323 throw parse_error(code,
"netmask pattern mixes zeroes & ones in address", str);
325 throw parse_error(code,
"has host bits set in address", str);
327 throw parse_error(code,
"only one '/' permitted in address", str);
329 throw parse_error(code,
"input string is too long", str);
331 throw parse_error(code,
"empty octet", value,
"in address", str);
333 throw parse_error(code,
"expected 4 octets in", str);
335 throw parse_error(code,
"leading zeros are not permitted in octet", value,
"of address", str);
337 throw parse_error(code,
"in octet", value,
"of address", str,
"more 3 characters");
339 throw parse_error(code,
"in octet", value,
"of address", str,
"has invalid symbol");
341 throw parse_error(code,
"octet", value,
"of address", str,
"exceeded 255");
343 throw parse_error(code,
"least 3 parts in address", str);
345 throw parse_error(code,
"most 8 colons permitted in address", str);
347 throw parse_error(code,
"in part", value,
"of address", str,
"more 4 characters");
349 throw parse_error(code,
"in part", value,
"of address", str,
"has invalid symbols");
351 throw parse_error(code,
"at most one '::' permitted in address", str);
353 throw parse_error(code,
"at leading ':' only permitted as part of '::' in address", str);
355 throw parse_error(code,
"at trailing ':' only permitted as part of '::' in address", str);
357 throw parse_error(code,
"expected at most 7 other parts with '::' in address", str);
359 throw parse_error(code,
"exactly 8 parts expected without '::' in address", str);
361 throw parse_error(code,
"scope id is too long in address", str);
363 throw parse_error(code,
"invalid scope id in address", str);
373 throw logic_error(code
, "cannot set prefixlen_diff and new_prefix");
377 throw parse_error(code,
"unexpected next unicode symbol",
error::symbol { value },
"in string", str);
379 throw parse_error(code,
"incorrect sequence of bytes in unicode encoding for string", str);
384 if (IPADDRESS_IS_CONST_EVALUATED(length)) {
385 const auto _err =
int(code) / (
int(code) -
int(code));
The primary exception class used by the IP address library.
Definition errors.hpp:114
error_code code() const noexcept
Returns the error code associated with this error.
Definition errors.hpp:152
error(error_code code, const char *message)
Constructs an error with a code and a message C-string.
Definition errors.hpp:144
error(error_code code, const std::string &message)
Constructs an error with a code and a message string.
Definition errors.hpp:135
error(error_code code, const FirstArg &arg, const Args &... args)
Constructs an error with a code and a concatenated message from multiple arguments.
Definition errors.hpp:126
Exception for logical errors in IP address operations.
Definition errors.hpp:247
logic_error(error_code code, const std::string &message)
Constructs a logic error with a code and a message string.
Definition errors.hpp:268
logic_error(error_code code, const char *message)
Constructs a logic error with a code and a message C-string.
Definition errors.hpp:277
logic_error(error_code code, const FirstArg &arg, const Args &... args)
Constructs a logic error with a code and a concatenated message from multiple arguments.
Definition errors.hpp:259
Exception for errors encountered during IP address parsing.
Definition errors.hpp:203
parse_error(error_code code, const FirstArg &arg, const Args &... args)
Constructs a parsing error with a code and a concatenated message from multiple arguments.
Definition errors.hpp:215
parse_error(error_code code, const std::string &message)
Constructs a parsing error with a code and a message string.
Definition errors.hpp:224
parse_error(error_code code, const char *message)
Constructs a parsing error with a code and a message C-string.
Definition errors.hpp:233
#define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS
Definition config.hpp:93
#define IPADDRESS_EXPORT
Definition config.hpp:42
#define IPADDRESS_NODISCARD
Definition config.hpp:98
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:112
#define IPADDRESS_NAMESPACE
Definition config.hpp:38
#define IPADDRESS_NOEXCEPT
Definition config.hpp:89
constexpr inline void raise_error(error_code code, uint32_t value, const T *address, size_t length)
Raises an error with a specific error code and additional context.
Definition errors.hpp:300
error_code
Enumeration of error codes for IP address parsing and validation.
Definition errors.hpp:52
@ cannot_set_prefixlen_diff_and_new_prefix
Both prefix length difference and new prefix cannot be set simultaneously.
@ trailing_colon_only_permitted_as_part_of_double_colon
A trailing colon is only permitted as part of a double colon.
@ octet_has_invalid_symbol
An octet contains characters other than digits, which are invalid.
@ invalid_version
The IP address version does not match the expected version.
@ unexpected_symbol
The input string contains an unexpected character.
@ empty_address
The IP address string is empty when it should contain a valid address.
@ exactly_8_parts_expected_without_double_colon
Without a double colon, exactly eight parts are expected.
@ leading_colon_only_permitted_as_part_of_double_colon
A leading colon is only permitted as part of a double colon.
@ octet_exceeded_255
An octet's value exceeds the maximum allowed value of 255.
@ invalid_scope_id
The scope ID in the IPv6 address is invalid.
@ string_is_too_long
Input string is too long.
@ not_contained_network
The network is not a subnet of the other network as expected.
@ most_one_double_colon_permitted
More than one double colon is present in the IPv6 address.
@ wrong_encoding_sequence
Incorrect byte sequence in Unicode encoding.
@ part_has_invalid_symbol
A part of the IPv6 address contains invalid characters.
@ leading_0_are_not_permitted
Leading zeroes are not permitted in any octet of the IPv4 address.
@ empty_octet
An octet in the IPv4 address is empty when it should contain a numeric value.
@ new_prefix_must_be_shorter
The new prefix length must be shorter for the operation being performed.
@ no_error
Indicates the absence of any errors.
@ scope_id_is_too_long
The scope ID in the IPv6 address exceeds the maximum length.
@ empty_netmask
The netmask portion of the address is empty when it should specify a valid netmask.
@ invalid_prefixlen_diff
The difference in prefix length is invalid for the operation being performed.
@ new_prefix_must_be_longer
The new prefix length must be longer for the operation being performed.
@ part_is_more_4_chars
A part of the IPv6 address contains more than four characters.
@ has_host_bits_set
The address has host bits set when they are expected to be clear.
@ only_one_slash_permitted
Only one slash character is permitted, used to separate the address from the netmask.
@ octet_more_3_characters
An octet contains more than three characters, exceeding the maximum allowed.
@ most_8_colons_permitted
The IPv6 address contains more than the maximum allowed number of colons.
@ least_3_parts
The IPv6 address contains fewer than the minimum required parts.
@ expected_4_octets
The IPv4 address does not contain the expected four octets.
@ expected_at_most_7_other_parts_with_double_colon
With a double colon present, at most seven other parts are expected.
@ netmask_pattern_mixes_zeroes_and_ones
The netmask contains an invalid pattern of zeroes and ones.
@ invalid_netmask
The provided netmask is not valid according to standard netmask formatting rules.