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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
116
117
118
119
120
121
122
123
124 template <
typename FirstArg,
typename... Args>
125 explicit error(
error_code code,
const FirstArg& arg,
const Args&... args) : std::runtime_error(concatenate(arg, args...)), _code(code) {
129
130
131
132
133
134 explicit error(
error_code code,
const std::string& message) : std::runtime_error(message), _code(code) {
138
139
140
141
142
143 explicit error(
error_code code,
const char* message) : std::runtime_error(message), _code(code) {
147
148
149
150
160 template <
typename... Args>
161 static std::string concatenate(
const Args&... args) {
162 std::ostringstream ss;
167 template <
typename FirstArg,
typename... Args>
168 static void concat(std::ostringstream& out,
const FirstArg& arg,
const Args&... args) {
169 print(out, arg) <<
' ';
170 concat(out, args...);
173 template <
typename FirstArg>
174 static void concat(std::ostringstream& out,
const FirstArg& arg) {
178 template <
typename T>
179 static std::ostringstream& print(std::ostringstream& out,
const T& arg) {
184 static std::ostringstream& print(std::ostringstream& out,
const symbol& arg);
186 template <
typename T, size_t N>
187 static std::ostringstream& print(std::ostringstream& out,
const T (&str)[N]);
193
194
195
196
197
198
199
200
201
205
206
207
208
209
210
211
212
213 template <
typename FirstArg,
typename... Args>
218
219
220
221
222
227
228
229
230
231
237
238
239
240
241
242
243
244
245
249
250
251
252
253
254
255
256
257 template <
typename FirstArg,
typename... Args>
262
263
264
265
266
271
272
273
274
275
281
282
283
284
285
286
287
288
289
290
291
292
293
294
296#ifndef IPADDRESS_NO_EXCEPTIONS
300#ifndef IPADDRESS_NO_EXCEPTIONS
302 size_t max_len = length;
306 for (size_t i = 0; i < max_len; ++i) {
318 throw parse_error(code,
"empty mask in address", str);
320 throw parse_error(code,
"is not a valid netmask in address", str);
322 throw parse_error(code,
"netmask pattern mixes zeroes & ones in address", str);
324 throw parse_error(code,
"has host bits set in address", str);
326 throw parse_error(code,
"only one '/' permitted in address", str);
328 throw parse_error(code,
"input string is too long", str);
330 throw parse_error(code,
"unexpected next unicode symbol",
error::symbol { value },
"in string", str);
332 throw parse_error(code,
"incorrect sequence of bytes in unicode encoding for string", str);
334 throw parse_error(code,
"empty octet", value,
"in address", str);
336 throw parse_error(code,
"expected 4 octets in", str);
338 throw parse_error(code,
"leading zeros are not permitted in octet", value,
"of address", str);
340 throw parse_error(code,
"in octet", value,
"of address", str,
"more 3 characters");
342 throw parse_error(code,
"in octet", value,
"of address", str,
"has invalid symbol");
344 throw parse_error(code,
"octet", value,
"of address", str,
"exceeded 255");
346 throw parse_error(code,
"least 3 parts in address", str);
348 throw parse_error(code,
"most 8 colons permitted in address", str);
350 throw parse_error(code,
"in part", value,
"of address", str,
"more 4 characters");
352 throw parse_error(code,
"in part", value,
"of address", str,
"has invalid symbols");
354 throw parse_error(code,
"at most one '::' permitted in address", str);
356 throw parse_error(code,
"at leading ':' only permitted as part of '::' in address", str);
358 throw parse_error(code,
"at trailing ':' only permitted as part of '::' in address", str);
360 throw parse_error(code,
"expected at most 7 other parts with '::' in address", str);
362 throw parse_error(code,
"exactly 8 parts expected without '::' in address", str);
364 throw parse_error(code,
"scope id is too long in address", str);
366 throw parse_error(code,
"invalid scope id in address", str);
376 throw logic_error(code
, "cannot set prefixlen_diff and new_prefix");
380 throw logic_error(code
, "last address must be greater than first");
385 if (IPADDRESS_IS_CONST_EVALUATED(length)) {
386 const auto _err =
int(code) / (
int(code) -
int(code));
The primary exception class used by the IP address library.
Definition errors.hpp:113
error_code code() const noexcept
Returns the error code associated with this error.
Definition errors.hpp:151
error(error_code code, const char *message)
Constructs an error with a code and a message C-string.
Definition errors.hpp:143
error(error_code code, const std::string &message)
Constructs an error with a code and a message string.
Definition errors.hpp:134
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:125
Exception for logical errors in IP address operations.
Definition errors.hpp:246
logic_error(error_code code, const std::string &message)
Constructs a logic error with a code and a message string.
Definition errors.hpp:267
logic_error(error_code code, const char *message)
Constructs a logic error with a code and a message C-string.
Definition errors.hpp:276
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:258
Exception for errors encountered during IP address parsing.
Definition errors.hpp:202
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:214
parse_error(error_code code, const std::string &message)
Constructs a parsing error with a code and a message string.
Definition errors.hpp:223
parse_error(error_code code, const char *message)
Constructs a parsing error with a code and a message C-string.
Definition errors.hpp:232
#define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS
Definition config.hpp:96
#define IPADDRESS_EXPORT
Definition config.hpp:45
#define IPADDRESS_NODISCARD
Definition config.hpp:101
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:115
#define IPADDRESS_NAMESPACE
Definition config.hpp:41
#define IPADDRESS_NOEXCEPT
Definition config.hpp:92
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:299
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.
@ last_address_must_be_greater_than_first
The last IP address in the range must be greater than the first IP address.
@ 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.