Skip to content

Fix compilation with gcc 13.3, fmt 11.0.0 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ project(mstack LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

# find_package (glog REQUIRED)
find_package(fmt REQUIRED)
find_package (glog REQUIRED)

add_compile_options(-g)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)


# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRC)

add_executable(mstack main.cpp)

target_link_libraries (mstack glog gflags fmt pthread m)
target_link_libraries(mstack glog::glog fmt::fmt pthread m)
1 change: 1 addition & 0 deletions include/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int init_logger(int argc, char* argv[]) {

gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
return 0;
}

void init_stack(int argc, char* argv[]) {
Expand Down
1 change: 1 addition & 0 deletions include/arp_cache.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <optional>
#include <unordered_map>

#include "ipv4_addr.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/defination.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ std::string state_to_string(int state) {
case TCP_TIME_WAIT:
return "TCP_TIME_WAIT";
}
return "UNKNOWN";
}
}; // namespace mstack
2 changes: 1 addition & 1 deletion include/ipv4_addr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ipv4_addr_t {
void produce(uint8_t*& ptr) { utils::produce<uint32_t>(ptr, _ipv4); }

friend std::ostream& operator<<(std::ostream& out, ipv4_addr_t ipv4) {
out << utils::format("%u.%u.%u.%u", (ipv4._ipv4 >> 24) & 0xFF,
out << utils::format("{}.{}.{}.{}", (ipv4._ipv4 >> 24) & 0xFF,
(ipv4._ipv4 >> 16) & 0xFF, (ipv4._ipv4 >> 8) & 0xFF,
(ipv4._ipv4 >> 0) & 0xFF);
return out;
Expand Down
4 changes: 3 additions & 1 deletion include/mac_addr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ struct mac_addr_t {
std::copy(std::begin(other.mac), std::end(other.mac),
std::begin(mac));
}
return *this;
}

mac_addr_t& operator=(mac_addr_t&& other) {
std::swap(mac, other.mac);
return *this;
};

mac_addr_t(std::array<uint8_t, 6> other) {
Expand Down Expand Up @@ -67,7 +69,7 @@ struct mac_addr_t {
friend std::ostream& operator<<(std::ostream& out,
const mac_addr_t& m) {
using u = uint32_t;
out << utils::format("%02X:%02X:%02X:%02X:%02X:%02X",
out << utils::format("{:X}:{:X}:{:X}:{:X}:{:X}:{:X}",
u(m.mac[0]), u(m.mac[1]), u(m.mac[2]),
u(m.mac[3]), u(m.mac[4]), u(m.mac[5]));
return out;
Expand Down
3 changes: 3 additions & 0 deletions include/socket_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class socket_manager {
listeners[fd] = listener;
auto& tcb_manager = tcb_manager::instance();
tcb_manager.listen_port(listener->local_info.value(), listener);
return 0;
};

int accept(int fd) {
Expand Down Expand Up @@ -87,6 +88,7 @@ class socket_manager {
raw_packet r_packet =
std::move(socket->tcb.value()->receive_queue.pop_front().value());
r_packet.buffer->export_data(reinterpret_cast<uint8_t*>(buf), len);
return 0;
}

int write(int fd, char* buf, int& len) {
Expand All @@ -98,6 +100,7 @@ class socket_manager {
std::make_unique<base_packet>(reinterpret_cast<uint8_t*>(buf), len);
raw_packet r_packet = {.buffer = std::move(out_buffer)};
socket->tcb.value()->send_queue.push_back(std::move(r_packet));
return 0;
}
};
}; // namespace mstack
4 changes: 4 additions & 0 deletions include/tcp_transmit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class tcp_transmit {
if (in_tcp.ACK == 1) {
return true;
}

return false;
}

static bool tcp_handle_listen_state(std::shared_ptr<tcb_t> in_tcb,
Expand Down Expand Up @@ -336,6 +338,8 @@ class tcp_transmit {
}
}
}

return false;
}

static void tcp_in(std::shared_ptr<tcb_t> in_tcb, tcp_packet_t& in_packet) {
Expand Down
10 changes: 5 additions & 5 deletions include/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <fmt/printf.h>
#include <fmt/ostream.h>

#include <cstdint>
#include <cstdio>
Expand All @@ -9,7 +9,7 @@ namespace utils {
template <typename... A>
inline std::string format(std::string format, A&&... a) {
std::ostringstream os;
::fmt::fprintf(os, format, std::forward<A>(a)...);
fmt::print(os, format, std::forward<A>(a)...);
return os.str();
}

Expand All @@ -21,14 +21,14 @@ inline static int run_cmd(std::string fmt, A&&... a) {
}

static int set_interface_route(std::string dev, std::string cidr) {
return run_cmd("ip route add dev %s %s", dev, cidr);
return run_cmd("ip route add dev {} {}", dev, cidr);
}

static int set_interface_address(std::string dev, std::string cidr) {
return run_cmd("ip address add dev %s local %s", dev, cidr);
return run_cmd("ip address add dev {} local {}", dev, cidr);
}

static int set_interface_up(std::string dev) { return run_cmd("ip link set dev %s up", dev); }
static int set_interface_up(std::string dev) { return run_cmd("ip link set dev {} up", dev); }

uint32_t ntoh(uint32_t value) {
return (value & 0x000000FFU) << 24 | (value & 0x0000FF00U) << 8 |
Expand Down