TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
configurers_utils.hpp
Go to the documentation of this file.
1 /**
2  * @file configurers_utils.hpp
3  *
4  * @author Lucas Haug <lucas.haug@thuneratz.org>
5  *
6  * @brief Configurers utilitary funtions
7  *
8  * @date 06/2021
9  *
10  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
11  *
12  */
13 
14 #include <string>
15 #include <sstream>
16 
17 /*****************************************
18  * Public Constants
19  *****************************************/
20 
21 #define MIN_UNICAST_ADDRESS "127.0.0.0"
22 #define MAX_UNICAST_ADDRESS "127.255.255.255"
23 
24 #define MIN_MULTICAST_ADDRESS "224.0.0.0"
25 #define MAX_MULTICAST_ADDRESS "239.255.255.255"
26 
27 #define INVALID_ADDRESS "0.0.0.0"
28 
29 namespace travesim {
30 /*****************************************
31  * Public Types
32  *****************************************/
33 
34 /**
35  * @brief Type used to validate a IP string
36  */
38  VALID, /**< Valid IP address */
39  INVALID_FORMAT, /**< Wrong formatted IP string */
40  INVALID_NUMBERS, /**< The numbers on the ip are not representable by 8 bits */
41  OUT_OF_RANGE /**< The IP is not in the specified range */
42 };
43 
44 /*****************************************
45  * Public Funtions Prototypes
46  *****************************************/
47 
48 /**
49  * @brief Converts a IPv4 in a string to a array of unsigned integers,
50  * where the most significant byte of the IP address is in the
51  * position 0 and the last significant in the position 3.
52  *
53  * @note Expects IPv4 in the quad-dotted notation.
54  *
55  * @param ip_string IPv4 string to be converted
56  * @param ip_uint Pointer where to store the converted IPv4
57  *
58  * @return true if the conversion was successful, false otherwise
59  */
60 bool ipv4_string_to_uint(std::string ip_string, uint* ip_uint);
61 
62 /**
63  * @brief Checks if a IP is valid and is in the specified range
64  *
65  * @note Expects IPv4 in the quad-dotted notation.
66  *
67  * @param ip IP string to be converted
68  * @param min_ip Minimum IP interval value
69  * @param max_ip Maximum IP interval value
70  *
71  * @return @ref IPValidation
72  */
73 IPValidation check_valid_ip(std::string ip, std::string min_ip, std::string max_ip);
74 
75 /**
76  * @brief Get the error msg based on the validation type
77  *
78  * @param error Which error to get the message
79  *
80  * @return std::string representing the error
81  */
82 std::string get_error_msg(IPValidation error);
83 } // namespace travesim
bool ipv4_string_to_uint(std::string ip_string, uint *ip_uint)
Converts a IPv4 in a string to a array of unsigned integers, where the most significant byte of the I...
IPValidation
Type used to validate a IP string.
std::string get_error_msg(IPValidation error)
Get the error msg based on the validation type.
IPValidation check_valid_ip(std::string ip, std::string min_ip, std::string max_ip)
Checks if a IP is valid and is in the specified range.