Skip to content

Commit a56a381

Browse files
added operator~ to DNS::Ip class
1 parent be77afb commit a56a381

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
33

44
# Find a suitable compiler, and declare the version and language.
5-
project(DNS-CPP VERSION 1.3.2 LANGUAGES CXX)
5+
project(DNS-CPP VERSION 1.3.3 LANGUAGES CXX)
66

77
# All artefacts should end up at the root of the build dir for convenience
88
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ INCLUDE_DIR = ${PREFIX}/include
33
LIBRARY_DIR = ${PREFIX}/lib
44
export LIBRARY_NAME = dnscpp
55
export SONAME = 1.3
6-
export VERSION = 1.3.2
6+
export VERSION = 1.3.3
77

88
all:
99
$(MAKE) -C src all

include/dnscpp/ip.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ class Ip
340340
{
341341
return any();
342342
}
343+
344+
/**
345+
* Inverse operator
346+
* @return Ip
347+
*/
348+
Ip operator~() const;
343349

344350
/**
345351
* Bitwise assignment OR operator (x |= y)

src/ip.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,37 @@ Ip &Ip::operator=(const struct in6_addr *ip)
228228
return *this;
229229
}
230230

231+
/**
232+
* Inverse operator
233+
* @return Ip
234+
*/
235+
Ip Ip::operator~() const
236+
{
237+
// implementation depends on ip version
238+
if (_version == 6)
239+
{
240+
// get the address
241+
auto address = _data.ipv6;
242+
243+
// iterate over the entire address
244+
for (unsigned i = 0; i < 16; ++i) address.s6_addr[i] = ~address.s6_addr[i];
245+
246+
// construct a new ip
247+
return DNS::Ip(address);
248+
}
249+
else
250+
{
251+
// get the address
252+
auto address = _data.ipv4;
253+
254+
// ipv4 can use a single cpu operation
255+
address.s_addr = ~address.s_addr;
256+
257+
// construct a new ip
258+
return DNS::Ip(address);
259+
}
260+
}
261+
231262
/**
232263
* Bitwise assignment OR operator (x |= y)
233264
* @param that The other IP

0 commit comments

Comments
 (0)