Skip to content

Commit

Permalink
Rename receiver and sender classes
Browse files Browse the repository at this point in the history
  • Loading branch information
R. Kaleta committed Jan 19, 2020
1 parent 1ee19e4 commit 066c325
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 32 deletions.
16 changes: 6 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ AlignConsecutiveMacros: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
Expand All @@ -37,7 +37,6 @@ ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: false
ForEachMacros: []
IncludeBlocks: Merge
IncludeCategories:
# C Standard library
Expand Down Expand Up @@ -67,7 +66,7 @@ IncludeCategories:
# All custom headers
- Regex: '^".*"'
Priority: 8
IncludeIsMainRegex: "$"
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
Expand All @@ -77,7 +76,6 @@ MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
NamespaceMacros: []
PointerAlignment: Middle
ReflowComments: false
SortIncludes: true
Expand All @@ -99,7 +97,5 @@ SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros: []
TabWidth: 4
TypenameMacros: []
UseTab: Never
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(Traceroute VERSION 1.0.191124)
project(Traceroute VERSION 1.1.200119)

# COMPILER
set(CMAKE_CXX_STANDARD 14)
Expand All @@ -9,9 +9,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unknown-pragmas")
include_directories(include)
set(SOURCES
src/IPAddress.cpp
src/ICMPReceiver.cpp
src/ICMPSender.cpp
src/ICMPController.cpp
src/SocketReceiver.cpp
src/SocketSender.cpp
src/traceroute.cpp)

# OUTPUT
Expand Down
11 changes: 6 additions & 5 deletions include/ICMPController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
#include <cstdlib>
#include <set>
#include <tuple>
#include "ICMPReceiver.hpp"
#include "ICMPSender.hpp"
#include "SocketReceiver.hpp"
#include "SocketSender.hpp"

class ICMPController
{
private:
const RawSocket & socket;
ICMPSender sender;
ICMPReceiver receiver;
SocketSender sender;
SocketReceiver receiver;

public:
explicit ICMPController(RawSocket & s)
: socket{s}, sender{ICMPSender(s)}, receiver{ICMPReceiver(s)}
: socket{s}, sender{SocketSender(s)}, receiver{SocketReceiver(s)}
{
}

Expand Down
8 changes: 4 additions & 4 deletions include/ICMPReceiver.hpp → include/SocketReceiver.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ICMP_RECEIVER_HPP_
#define ICMP_RECEIVER_HPP_
#ifndef SOCKET_RECEIVER_HPP_
#define SOCKET_RECEIVER_HPP_

#include <cstdlib>
#include <vector>
Expand All @@ -8,14 +8,14 @@
#include "IPAddress.hpp"
#include "RawSocket.hpp"

class ICMPReceiver
class SocketReceiver
{
private:
const RawSocket & socket;
sockaddr_in sender_address;

public:
explicit ICMPReceiver(RawSocket & s) : socket{s}, sender_address{}
explicit SocketReceiver(RawSocket & s) : socket{s}, sender_address{}
{
}

Expand Down
8 changes: 4 additions & 4 deletions include/ICMPSender.hpp → include/SocketSender.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ICMP_SENDER_HPP_
#define ICMP_SENDER_HPP_
#ifndef SOCKET_SENDER_HPP_
#define SOCKET_SENDER_HPP_

#include <cstdlib>
#include <cinttypes>
Expand All @@ -8,14 +8,14 @@
#include "IPAddress.hpp"
#include "RawSocket.hpp"

class ICMPSender
class SocketSender
{
private:
const RawSocket & socket;
sockaddr_in receiver_address;

public:
explicit ICMPSender(RawSocket & s) : socket{s}, receiver_address{}
explicit SocketSender(RawSocket & s) : socket{s}, receiver_address{}
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/ICMPReceiver.cpp → src/SocketReceiver.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "ICMPReceiver.hpp"
#include "SocketReceiver.hpp"
#include <cerrno>
#include <cstring>
#include <algorithm>
#include <string>

std::vector<uint8_t> ICMPReceiver::receive()
std::vector<uint8_t> SocketReceiver::receive()
{
socklen_t sender_size = sizeof(sender_address);
uint8_t msg_buf[IP_MAXPACKET];
Expand All @@ -18,7 +18,7 @@ std::vector<uint8_t> ICMPReceiver::receive()
return std::vector<uint8_t>(std::begin(msg_buf), std::begin(msg_buf) + msg_size);
}

IPAddress ICMPReceiver::take_address()
IPAddress SocketReceiver::take_address()
{
char ip_str[32];

Expand Down
6 changes: 3 additions & 3 deletions src/ICMPSender.cpp → src/SocketSender.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "ICMPSender.hpp"
#include "SocketSender.hpp"
#include <cerrno>
#include <cstring>
#include <string>

void ICMPSender::send(const void * msg_buf, int msg_size, uint16_t ttl)
void SocketSender::send(const void * msg_buf, int msg_size, uint16_t ttl)
{
setsockopt(socket.descriptor(), IPPROTO_IP, IP_TTL, &ttl, sizeof(uint16_t));

Expand All @@ -14,7 +14,7 @@ void ICMPSender::send(const void * msg_buf, int msg_size, uint16_t ttl)
throw SocketException(strerror(errno));
}

void ICMPSender::set_receiver(const IPAddress & addr)
void SocketSender::set_receiver(const IPAddress & addr)
{
receiver_address.sin_family = AF_INET;

Expand Down

0 comments on commit 066c325

Please sign in to comment.