Skip to content

Commit d6b6279

Browse files
author
Artiom N.
committed
Mostly style fixes
1 parent 34b48b8 commit d6b6279

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

src/book01/ch04/cpp/ping/ping.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ class PingPacket
104104

105105
public:
106106
// Zero packet constructor. Need for recv.
107-
explicit PingPacket(size_t packet_size = ping_packet_size) : data_buffer_(packet_size, 0)
107+
// cppcheck-suppress noExplicitConstructor
108+
PingPacket(size_t packet_size = ping_packet_size) : data_buffer_(packet_size, 0) // NOLINT
108109
{
109110
assert(data_buffer_.size() >= sizeof(icmphdr));
110111
}
111112

112-
explicit PingPacket(uint16_t packet_id, uint16_t packet_sequence_number, size_t packet_size = ping_packet_size)
113+
PingPacket(uint16_t packet_id, uint16_t packet_sequence_number, size_t packet_size = ping_packet_size)
113114
{
114115
create_new_packet(packet_id, packet_sequence_number, packet_size);
115116
}
@@ -119,7 +120,7 @@ class PingPacket
119120
assert(data_buffer_.size() >= sizeof(icmphdr));
120121
}
121122

122-
explicit PingPacket(const BufferType::const_iterator &start, const BufferType::const_iterator &end)
123+
PingPacket(const BufferType::const_iterator &start, const BufferType::const_iterator &end)
123124
: data_buffer_{start, end}
124125
{
125126
assert(data_buffer_.size() >= sizeof(icmphdr));

src/book01/ch11/cpp/sockdiag/sock_diag.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void print_diag(const inet_diag_msg *diag, unsigned int len)
7373
throw std::system_error(errno, std::generic_category(), "short response");
7474
}
7575

76-
if (diag->idiag_family != AF_INET && diag->idiag_family != AF_INET6)
76+
if (AF_INET != diag->idiag_family && AF_INET6 != diag->idiag_family)
7777
{
7878
throw std::logic_error("unexpected protocol family");
7979
}
@@ -219,7 +219,7 @@ void print_responses(int fd)
219219
}
220220
}
221221

222-
if (h->nlmsg_type != SOCK_DIAG_BY_FAMILY)
222+
if (SOCK_DIAG_BY_FAMILY != h->nlmsg_type)
223223
{
224224
throw std::system_error(errno, std::generic_category(), "unexpected nlmsg_type");
225225
}

src/book01/ch17/cpp/mailslot/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C"
99

1010
int main()
1111
{
12-
const LPCTSTR slot_name = TEXT("\\\\.\\mailslot\\test_mailslot");
12+
const LPCTSTR slot_name = TEXT(R"(\\.\mailslot\test_mailslot)");
1313
HANDLE h_slot =
1414
CreateFile(slot_name, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
1515

src/book01/ch22/cpp/pcap_sniffer/packet_printer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#include <iostream>
55
#include <string>
66

7+
#if !defined(ETHERTYPE_IP)
8+
constexpr auto ETHERTYPE_IP = 0x0800;
9+
#endif
10+
11+
#if !defined(ETHERTYPE_IPV6)
12+
constexpr auto ETHERTYPE_IPV6 = 0x86DD;
13+
#endif
714

815
// Ethernet headers are always exactly 14 bytes.
916
constexpr auto SIZE_ETHERNET = 14;
@@ -219,7 +226,7 @@ void PacketPrinter::got_packet(u_char *args, const pcap_pkthdr *header, const u_
219226

220227
switch (ntohs(ethernet->ether_type))
221228
{
222-
case 0x0800:
229+
case ETHERTYPE_IP:
223230
{
224231
std::cout << " IPv4 protocol" << std::endl;
225232
proto_addr.resize(INET_ADDRSTRLEN);
@@ -241,7 +248,7 @@ void PacketPrinter::got_packet(u_char *args, const pcap_pkthdr *header, const u_
241248
dst = &ip->ip_dst;
242249
break;
243250
}
244-
case 0x86DD:
251+
case ETHERTYPE_IPV6:
245252
{
246253
std::cout << " IPv6 protocol" << std::endl;
247254
proto_addr.resize(INET6_ADDRSTRLEN);

src/book01/ch23/cpp/tun_example/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C"
2525
#include <string>
2626

2727

28-
int perform_ioctl(int fd, const int call_id, void *result, const std::string &msg)
28+
int perform_ioctl(int fd, int call_id, void *result, const std::string &msg)
2929
{
3030
const auto ioctl_res = ioctl(fd, call_id, result);
3131
if (-1 == ioctl_res)

src/book02/ch01/python/client-to-client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
continue
2828

2929
while True:
30-
data = f'I\'am {sock.getsockname()} ' \
31-
f'sending data to ' f'{sock.getpeername()}'
30+
data = f'I\'am {sock.getsockname()} sending data to {sock.getpeername()}'
3231
print(f'Sending "{data}"')
3332
sock.send(data.encode())
3433
print('Receiving...')

src/book02/ch03/python/mt_server/mt-file-server1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def send_file_to_the_client(c_sock: socket.socket):
120120
except BaseException as e:
121121
print(e)
122122
result = False
123+
123124
c_sock.close()
124125
print(f'Client with tid = {current_thread().name} [{current_thread().native_id}] exiting...')
125126
return result

0 commit comments

Comments
 (0)