NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
ip_address.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef APPLICATIONS_STORAGE_STORAGE_COMMON_IP_ADDRESS_HPP_
27 #define APPLICATIONS_STORAGE_STORAGE_COMMON_IP_ADDRESS_HPP_
28 
29 #include <cstdint>
30 #include <string>
31 
32 namespace storage {
33 
34 /*
35  * Helper class to hold an ip address and port pair
36  */
37 class ip_address {
38 public:
39  /*
40  * Default destructor
41  */
42  ~ip_address() = default;
43 
44  /*
45  * Default constructor
46  */
47  ip_address() = default;
48 
49  /*
50  * Construct an ip address from the given values
51  *
52  * @throws std::bad_alloc: If memory cannot be allocated
53  *
54  * @value [in]: String to be parsed into an ip address and port
55  */
56  ip_address(std::string address, uint16_t port);
57 
58  /*
59  * Copy constructor
60  *
61  * @throws std::bad_alloc: if memory cannot be allocated
62  */
63  ip_address(ip_address const &) = default;
64 
65  /*
66  * Move constructor
67  */
68  ip_address(ip_address &&) noexcept = default;
69 
70  /*
71  * Copy Assignment operator
72  *
73  * @throws std::bad_alloc: if memory cannot be allocated
74  */
75  ip_address &operator=(ip_address const &) = default;
76 
77  /*
78  * Move Assignment operator
79  */
80  ip_address &operator=(ip_address &&) noexcept = default;
81 
82  /*
83  * Get the IP address
84  *
85  * @return: IP address
86  */
87  std::string const &get_address() const noexcept;
88 
89  /*
90  * Get the port number
91  *
92  * @return: port number
93  */
94  uint16_t get_port() const noexcept;
95 
96 private:
97  std::string m_addr{}; // IP address
98  uint16_t m_port{}; // Port number
99 };
100 
101 /*
102  * Parse an IP address and port from the given string representation
103  *
104  * @value [in]: the string to be parsed
105  * @return: The parsed IP address and port
106  *
107  * @throws std::runtime_error: if the provided string cannot be parsed
108  */
109 ip_address parse_ip_v4_address(char const *value);
110 
111 } /* namespace storage */
112 
113 #endif /* APPLICATIONS_STORAGE_STORAGE_COMMON_IP_ADDRESS_HPP_ */
uint16_t get_port() const noexcept
Definition: ip_address.cpp:45
ip_address(ip_address &&) noexcept=default
ip_address(ip_address const &)=default
std::string const & get_address() const noexcept
Definition: ip_address.cpp:40
type value
ip_address parse_ip_v4_address(char const *value)
Definition: ip_address.cpp:50