diff --git a/.clang-format b/.clang-format index f0a4e8d..f59f803 100644 --- a/.clang-format +++ b/.clang-format @@ -1,22 +1,25 @@ -# VERSION 9 +# VERSION 11 AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false AlignConsecutiveDeclarations: false AlignConsecutiveMacros: false AlignEscapedNewlines: DontAlign -AlignOperands: true +AlignOperands: Align AlignTrailingComments: false AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes @@ -35,42 +38,42 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 8 Cpp11BracedListStyle: true +DeriveLineEnding: false DerivePointerAlignment: false FixNamespaceComments: false IncludeBlocks: Merge IncludeCategories: - # C Standard library - - Regex: '^|' - Priority: 1 # C standard library (C++ style) - - Regex: '^' - Priority: 2 + - Regex: '^' + Priority: 1 # C standard library (C style) - - Regex: '^<(std(arg|def|int|io)|assert|(u|w)char|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|string|time|wctype)\.h>' + - Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|uchar|wchar|wctype)\.h>' + Priority: 1 + # Standard headers (C++ style) + - Regex: '^<[a-z_]+>' Priority: 2 - # C++ standard library: input-output, exceptions, memory, threads - - Regex: '^<(ios(fwd)?|(i|o|io|f|s)stream|streambuf|iomanip|exception|stdexcept|system_error|new|memory|atomic|thread|(shared_)?mutex|future|condition_variable)>' + # Standard headers (C style) + - Regex: '^<[a-z_]+\.(h|hpp)>' Priority: 3 - # C++ standard library: algorithms, containers, strings - - Regex: '^<(algorithm|array|bitset|deque|iterator|(forward_|initializer_)?list|(unordered_)?map|queue|(unordered_)?set|stack|string|tuple|vector)>' - Priority: 4 - # C++ standard library: utilities, numerics, types - - Regex: '^<(complex|chrono|functional|limits|locale|numeric|random|ratio|regex|type(info|index|_traits)|valarray)>' + # All other headers (C style) + - Regex: '^<.+\.(h|hpp)>' Priority: 5 # All other headers (C++ style) - - Regex: '^<.*>' - Priority: 6 - # All other headers (C style) - - Regex: '^<.*\.(h|hpp)>' - Priority: 7 + - Regex: '^<.+>' + Priority: 4 # All custom headers - - Regex: '^".*"' - Priority: 8 + - Regex: '^".+"' + Priority: 6 IncludeIsMainRegex: '$' +IncludeIsMainSourceRegex: '$' +IndentCaseBlocks: true IndentCaseLabels: true +IndentExternBlock: NoIndent +IndentGotoLabels: false IndentPPDirectives: None IndentWidth: 4 IndentWrappedFunctionNames: true +InsertTrailingCommas: None KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' MacroBlockEnd: '' @@ -89,6 +92,8 @@ SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: Never SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 SpacesInAngles: false diff --git a/.gitignore b/.gitignore index 60c0a32..561b0f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,13 @@ # [ C / C++ ] -# C++ / CMake output +# C / C++ / CMake output bin/ build/ dist/ -# CLion -.idea -cmake-build-debug/ - # Visual Studio Code .vscode *.code-workspace + +# CLion +.idea +cmake-build-debug/ diff --git a/README.md b/README.md index e53f94f..13a118f 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,15 @@ General: + Linux-based operating system \ *((Debian testing))* + C++ compiler \ - *((APT package `g++`, 9.2.+))* + *((APT package `g++`, 10.2.+))* + [CMake](https://cmake.org/) \ - *((APT package `cmake`, 3.15.+))* + *((APT package `cmake`, 3.18.+))* + [GNU Make](https://www.gnu.org/software/make) \ - *((APT package `make`, 4.2.+))* + *((APT package `make`, 4.3.+))* ### Automated formatting -+ [Clang-format](https://releases.llvm.org/9.0.0/tools/clang/docs/ClangFormat.html) \ - *((APT package `clang-format`, 9.0.+))* ++ [Clang-format](https://releases.llvm.org/11.0.0/tools/clang/docs/ClangFormat.html) \ + *((APT package `clang-format`, 11.+))* ----- diff --git a/include/IPAddress.hpp b/include/IPAddress.hpp index 0844d46..bf85d6d 100644 --- a/include/IPAddress.hpp +++ b/include/IPAddress.hpp @@ -1,8 +1,8 @@ #ifndef IP_ADDRESS_HPP_ #define IP_ADDRESS_HPP_ -#include #include +#include #include #include #include diff --git a/include/RawSocket.hpp b/include/RawSocket.hpp index 159361a..d2db5d1 100644 --- a/include/RawSocket.hpp +++ b/include/RawSocket.hpp @@ -1,8 +1,8 @@ #ifndef RAW_SOCKET_HPP_ #define RAW_SOCKET_HPP_ -#include #include +#include #include #include #include @@ -18,15 +18,15 @@ struct SocketException : public std::logic_error class RawSocket { public: - explicit RawSocket(int protocol) : descr{socket(AF_INET, SOCK_RAW, protocol)} + explicit RawSocket(int protocol) : descriptor_{socket(AF_INET, SOCK_RAW, protocol)} { - if(descr < 0) + if(descriptor_ < 0) throw SocketException(strerror(errno)); } ~RawSocket() { - close(descr); + close(descriptor_); } RawSocket(const RawSocket & r) = delete; @@ -36,11 +36,11 @@ class RawSocket int descriptor() const { - return descr; + return descriptor_; } private: - int descr; + int descriptor_; }; #endif diff --git a/include/SocketSender.hpp b/include/SocketSender.hpp index c2fd445..1ac9169 100644 --- a/include/SocketSender.hpp +++ b/include/SocketSender.hpp @@ -1,8 +1,8 @@ #ifndef SOCKET_SENDER_HPP_ #define SOCKET_SENDER_HPP_ -#include #include +#include #include #include #include "IPAddress.hpp" diff --git a/src/ICMPController.cpp b/src/ICMPController.cpp index 571fcea..f59a8c2 100644 --- a/src/ICMPController.cpp +++ b/src/ICMPController.cpp @@ -20,7 +20,7 @@ uint16_t count_checksum(const uint16_t * hdr, int length) sum = (sum >> 16U) + (sum & 0xFFFFU); - return (uint16_t)(~(sum + (sum >> 16U))); + return static_cast(~(sum + (sum >> 16U))); } icmphdr prepare_icmp(uint16_t id, uint16_t seq) diff --git a/src/IPAddress.cpp b/src/IPAddress.cpp index abb91c3..82eb146 100644 --- a/src/IPAddress.cpp +++ b/src/IPAddress.cpp @@ -1,8 +1,8 @@ #include "IPAddress.hpp" -#include -#include #include +#include #include +#include std::vector split(const std::string & st) { @@ -62,9 +62,8 @@ IPAddress::operator std::string() const std::vector IPAddress::quadruple() const { - return std::vector({(address & 0xFF000000U) >> 24U, - (address & 0x00FF0000U) >> 16U, (address & 0x0000FF00U) >> 8U, - address & 0x000000FFU}); + return {(address & 0xFF000000U) >> 24U, (address & 0x00FF0000U) >> 16U, + (address & 0x0000FF00U) >> 8U, address & 0x000000FFU}; } std::ostream & operator<<(std::ostream & os, const IPAddress & a) @@ -72,6 +71,5 @@ std::ostream & operator<<(std::ostream & os, const IPAddress & a) std::vector q = a.quadruple(); os << q[0] << "." << q[1] << "." << q[2] << "." << q[3]; - return os; } diff --git a/src/SocketReceiver.cpp b/src/SocketReceiver.cpp index 2c69427..a177222 100644 --- a/src/SocketReceiver.cpp +++ b/src/SocketReceiver.cpp @@ -10,7 +10,7 @@ std::vector SocketReceiver::receive() uint8_t msg_buf[IP_MAXPACKET]; ssize_t msg_size = recvfrom(socket.descriptor(), msg_buf, IP_MAXPACKET, MSG_DONTWAIT, - (sockaddr *)&sender_address, &sender_size); + reinterpret_cast(&sender_address), &sender_size); if(msg_size < 0) throw SocketException(strerror(errno)); diff --git a/src/SocketSender.cpp b/src/SocketSender.cpp index 7ef14d0..86add1c 100644 --- a/src/SocketSender.cpp +++ b/src/SocketSender.cpp @@ -7,8 +7,9 @@ void SocketSender::send(const void * msg_buf, int msg_size, uint16_t ttl) { setsockopt(socket.descriptor(), IPPROTO_IP, IP_TTL, &ttl, sizeof(uint16_t)); - ssize_t sent_size = sendto(socket.descriptor(), msg_buf, msg_size, 0, - (sockaddr *)&receiver_address, sizeof(receiver_address)); + ssize_t sent_size = + sendto(socket.descriptor(), msg_buf, msg_size, 0, + reinterpret_cast(&receiver_address), sizeof(receiver_address)); if(sent_size < 0) throw SocketException(strerror(errno)); diff --git a/src/traceroute.cpp b/src/traceroute.cpp index 44c69e0..7ccdb83 100644 --- a/src/traceroute.cpp +++ b/src/traceroute.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include #include #include @@ -30,7 +30,6 @@ int main(int argc, char * argv[]) if(argc < 2) { std::cerr << "No destination IP specified."; - return 1; }