From 73d33abc9776afbafbf28b2e28f0f90b8a07015a Mon Sep 17 00:00:00 2001 From: victoryang00 Date: Mon, 22 Jan 2024 05:44:24 +0000 Subject: [PATCH] init 2 connection --- bench/nas | 2 +- bench/redis | 2 +- gateway/main.cpp | 227 +++++++++++++++++++++--------------------- include/logging.h | 2 +- include/wamr.h | 1 + include/wamr_export.h | 1 + src/checkpoint.cpp | 50 +--------- src/wamr.cpp | 40 ++++++++ src/wamr_export.cpp | 40 ++++++++ test/tcp_client.c | 8 +- 10 files changed, 202 insertions(+), 171 deletions(-) diff --git a/bench/nas b/bench/nas index 3c5f581..fa64f5b 160000 --- a/bench/nas +++ b/bench/nas @@ -1 +1 @@ -Subproject commit 3c5f5819ed1f71b65defa1a4b44ab49d973b721d +Subproject commit fa64f5bdc12a1b19374b9a6c5b2443b9f5b9a175 diff --git a/bench/redis b/bench/redis index e8188bd..c42dbbc 160000 --- a/bench/redis +++ b/bench/redis @@ -1 +1 @@ -Subproject commit e8188bdb22f2f0551330d04af9ccddf45aca25bc +Subproject commit c42dbbc382b35d3fcc091569256248e287d61850 diff --git a/gateway/main.cpp b/gateway/main.cpp index 1aeb80f..4fe0618 100644 --- a/gateway/main.cpp +++ b/gateway/main.cpp @@ -29,15 +29,16 @@ int packets = 0; int client_fd; int fd; int new_fd; -std::vector backend_thread; +// assuming they are continuous +std::vector> tcp_pair; // server, server accept fd, client +std::vector recv_thread; +std::vector send_thread; +std::map> slept_tcp_pair; std::vector> forward_pair; +std::vector backend_thread; bool is_forward = false; int id = 0; struct mvvm_op_data *op_data; -/* TCP connection server to victim */ -TCPConnection *tcp_v_to_s; -TCPConnection *tcp_s_to_v; -ARPContext *arp_context; // Function to recalculate the IP checksum unsigned short in_cksum(unsigned short *buf, int len) { unsigned long sum = 0; @@ -289,46 +290,6 @@ void send_fin(std::string source_ip, int source_port, std::string dest_ip, int d CleanCrafter(); } -void ip_forward() { - std::system("/bin/echo 1 > /proc/sys/net/ipv4/ip_forward"); - std::system("/bin/echo 0 > /proc/sys/net/ipv4/conf/docker0/send_redirects"); - std::system("iptables --append FORWARD --in-interface docker0 --jump ACCEPT"); -} - -void start_block(const string &dst_ip, const string &src_ip, int dst_port, int src_port) { - - /* Delete the forwarding... */ - std::system("iptables --delete FORWARD --in-interface docker0 --jump ACCEPT"); - - /* Drop packets received from the spoofed connection */ - std::system(string("/sbin/iptables -A FORWARD -s " + dst_ip + " -d " + src_ip + " -p tcp --sport " + - StrPort(dst_port) + " --dport " + StrPort(src_port) + " -j DROP") - .c_str()); - - std::system(string("/sbin/iptables -A FORWARD -s " + src_ip + " -d " + dst_ip + " -p tcp --sport " + - StrPort(src_port) + " --dport " + StrPort(dst_port) + " -j DROP") - .c_str()); - - /* Append again the forwarding, so the victim can establish a new connection... */ - std::system("iptables --append FORWARD --in-interface docker0 --jump ACCEPT"); -} - -void clear_block(const string &dst_ip, const string &src_ip, int dst_port, int src_port) { - std::system("/bin/echo 0 > /proc/sys/net/ipv4/ip_forward"); - - std::system(string("/sbin/iptables -D FORWARD -s " + dst_ip + " -d " + src_ip + " -p tcp --sport " + - StrPort(dst_port) + " --dport " + StrPort(src_port) + " -j DROP") - .c_str()); - - std::system(string("/sbin/iptables -D FORWARD -s " + src_ip + " -d " + dst_ip + " -p tcp --sport " + - StrPort(src_port) + " --dport " + StrPort(dst_port) + " -j DROP") - .c_str()); -} - -void clear_forward() { - std::system("/bin/echo 0 > /proc/sys/net/ipv4/ip_forward"); - std::system("iptables --delete FORWARD --in-interface docker0 --jump ACCEPT"); -} void sigterm_handler(int sig) { struct pcap_stat stats {}; @@ -341,7 +302,6 @@ void sigterm_handler(int sig) { close(client_fd); close(fd); LOGV(INFO) << "Bye"; - clear_forward(); exit(0); } // int main(){ @@ -354,7 +314,7 @@ int main() { int opt = 1; ssize_t rc; int addrlen = sizeof(address); - char buffer[1024] = {0}; + char buffer[1024], buffer1[1024] = {0}; char errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program fp {}; // char filter_exp[] = ""; // The filter expression @@ -366,7 +326,6 @@ int main() { signal(SIGTERM, sigterm_handler); signal(SIGQUIT, sigterm_handler); signal(SIGINT, sigterm_handler); - ip_forward(); fd = socket(AF_INET, SOCK_STREAM, 0); // Create a socket @@ -426,7 +385,7 @@ int main() { if ((rc = recv(client_fd, buffer, sizeof(buffer), 0)) > 0) { memcpy(op_data, buffer, sizeof(*op_data)); switch (op_data->op) { - case MVVM_SOCK_SUSPEND: + case MVVM_SOCK_SUSPEND: { // suspend LOGV(ERROR) << "suspend"; @@ -464,57 +423,16 @@ int main() { if (!op_data->is_tcp) { send_fin(client_ip, client_port, server_ip, server_port, (char *)op_data); } else { - - /* Begin the spoofing */ - arp_context = ARPSpoofingReply(server_ip, client_ip, MVVM_SOCK_INTERFACE); - PrintARPContext(*arp_context); - // block the connection - start_block(client_ip, server_ip, client_port, server_port); - - /* TCP connection victim to server */ - tcp_v_to_s = new TCPConnection(server_ip, client_ip, client_port, server_port, - MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED); - tcp_s_to_v = new TCPConnection(client_ip, server_ip, server_port, client_port, - MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED); - /* Both connection are already established... */ - LOGV(ERROR) << "Connections synchronized "; - tcp_v_to_s->Sync(); - tcp_s_to_v->Sync(); - LOGV(ERROR) << "Connections synchronized finished"; - - new_fd = socket(AF_INET, SOCK_STREAM, 0); // Create a socket - - // Forcefully attaching socket to the port - if (setsockopt(new_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))) { - LOGV(ERROR) << "setsockopt"; - exit(EXIT_FAILURE); - } - - address.sin_family = AF_INET; - address.sin_port = htons(server_port); - // Convert IPv4 and IPv6 addresses from text to binary form - if (inet_pton(AF_INET, MVVM_SOCK_ADDR, &address.sin_addr) <= 0) { - LOGV(ERROR) << "Invalid address/ Address not supported"; - exit(EXIT_FAILURE); - } - - // Bind the socket to the network address and port - if (bind(new_fd, (struct sockaddr *)&address, sizeof(address)) < 0) { - LOGV(ERROR) << "bind failed" << errno; - exit(EXIT_FAILURE); - } - - // Start listening for connections - if (listen(new_fd, 3) < 0) { - LOGV(ERROR) << "listen"; - exit(EXIT_FAILURE); - } + // TODO remove the tcp connection + send_thread.pop_back(); + recv_thread.pop_back(); + auto p = tcp_pair.back(); + slept_tcp_pair[fmt::format("{}:{}", server_ip, server_port)] = p; } } - // send fin - break; - case MVVM_SOCK_RESUME: + } + case MVVM_SOCK_RESUME: { // resume LOGV(ERROR) << "resume"; auto tmp_tuple = forward_pair[forward_pair.size() - 1]; @@ -523,39 +441,120 @@ int main() { LOGV(ERROR) << "forward_pair[forward_pair.size()]" << std::get<0>(forward_pair[forward_pair.size() - 1]) << std::get<1>(forward_pair[forward_pair.size() - 1]); - socklen_t size = sizeof(address); - auto new_client = accept(new_fd, (struct sockaddr *)&address, &size); - LOGV(ERROR)<< "new_client" << new_client; - // for udp forward from source to remote - // stop keep_alive if (op_data->is_tcp) { + socklen_t size = sizeof(address); + auto new_client = accept(new_fd, (struct sockaddr *)&address, &size); // if is cl bool closed = false; - backend_thread.emplace_back([&]() { + recv_thread.emplace_back([&]() { + int new_server = std::get<1>(tcp_pair[tcp_pair.size() - 1]); while (!closed) { - auto payload = Payload(); - LOGV(ERROR) << payload.GetString(); - - tcp_v_to_s->Read(payload); - if (tcp_v_to_s->GetStatus() == TCPConnection::CLOSING) { - closed = true; - return; + if ((rc = recv(new_server, buffer1, sizeof(buffer1), 0)) > 0) { + send(new_client, buffer1, sizeof(buffer1), 0); } - send(new_client, payload.GetRawPointer(), sizeof(*payload.GetRawPointer()), 0); } }); - backend_thread.emplace_back([&]() { + recv_thread.emplace_back([&]() { + int new_server = std::get<1>(tcp_pair[tcp_pair.size() - 1]); while (!closed) { if ((rc = recv(new_client, buffer, sizeof(buffer), 0)) > 0) { LOGV(ERROR) << "recv" << buffer; - tcp_v_to_s->Send(((byte_ *)buffer), sizeof(buffer)); + send(new_server, buffer, sizeof(buffer), 0); } } }); } else is_forward = true; - sleep(1); break; } + case MVVM_SOCK_INIT: { + // init + LOGV(ERROR) << "init"; + if (op_data->addr[0][0].is_4) { + server_ip = fmt::format("{}.{}.{}.{}", op_data->addr[0][0].ip4[0], op_data->addr[0][0].ip4[1], + op_data->addr[0][0].ip4[2], op_data->addr[0][0].ip4[3]); + client_ip = fmt::format("{}.{}.{}.{}", op_data->addr[0][1].ip4[0], op_data->addr[0][1].ip4[1], + op_data->addr[0][1].ip4[2], op_data->addr[0][1].ip4[3]); + } else { + server_ip = + fmt::format("{:04x}:{:04x}:{:04x}:{:04x}:{:04x}:{:04x}:{:04x}:{:04x}", + op_data->addr[0][0].ip6[0], op_data->addr[0][0].ip6[1], op_data->addr[0][0].ip6[2], + op_data->addr[0][0].ip6[3], op_data->addr[0][0].ip6[4], op_data->addr[0][0].ip6[5], + op_data->addr[0][0].ip6[6], op_data->addr[0][0].ip6[7]); + client_ip = + fmt::format("{:04x}:{:04x}:{:04x}:{:04x}:{:04x}:{:04x}:{:04x}:{:04x}", + op_data->addr[0][1].ip6[0], op_data->addr[0][1].ip6[1], op_data->addr[0][1].ip6[2], + op_data->addr[0][1].ip6[3], op_data->addr[0][1].ip6[4], op_data->addr[0][1].ip6[5], + op_data->addr[0][1].ip6[6], op_data->addr[0][1].ip6[7]); + } + server_port = op_data->addr[0][0].port; + client_port = op_data->addr[0][1].port; + + LOGV(INFO) << "server_ip:" << server_ip << ":" << server_port << " client_ip:" << client_ip << ":" + << client_port; + + int server_fd = socket(AF_INET, SOCK_STREAM, 0); // Create a socket + + // Forcefully attaching socket to the port + if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))) { + LOGV(ERROR) << "setsockopt"; + exit(EXIT_FAILURE); + } + + address.sin_family = AF_INET; + address.sin_port = htons(server_port); + // Convert IPv4 and IPv6 addresses from text to binary form + if (inet_pton(AF_INET, MVVM_SOCK_ADDR, &address.sin_addr) <= 0) { + LOGV(ERROR) << "Invalid address/ Address not supported"; + exit(EXIT_FAILURE); + } + + // Bind the socket to the network address and port + if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) { + LOGV(ERROR) << "bind failed" << errno; + exit(EXIT_FAILURE); + } + + // Start listening for connections + if (listen(server_fd, 3) < 0) { + LOGV(ERROR) << "listen"; + exit(EXIT_FAILURE); + } + int new_server = + accept(new_fd, (struct sockaddr *)&address, (socklen_t *)&addrlen); // will be instantly consumed + + // Create a socket connect remote + int new_client = socket(AF_INET, SOCK_STREAM, 0); + // Convert IPv4 and IPv6 addresses from text to binary form + if (inet_pton(AF_INET, server_ip.c_str(), &address.sin_addr) <= 0) { + LOGV(ERROR) << "Invalid address/ Address not supported"; + exit(EXIT_FAILURE); + } + + if (connect(new_client, (struct sockaddr *)&address, sizeof(address)) == -1) { + LOGV(ERROR) << "connect failed " << errno; + close(new_client); + exit(EXIT_FAILURE); + } + LOGV(ERROR) << "new_client " << new_client; + bool closed = false; + send_thread.emplace_back([&]() { + while (!closed) { + if ((rc = recv(new_server, buffer1, sizeof(buffer1), 0)) > 0) { + send(new_client, buffer1, sizeof(buffer1), 0); + } + } + }); + recv_thread.emplace_back([&]() { + while (!closed) { + if ((rc = recv(new_client, buffer, sizeof(buffer), 0)) > 0) { + send(new_server, buffer, sizeof(buffer), 0); + } + } + }); + tcp_pair.emplace_back(server_fd, new_server, new_client); + break; + } + } } } } diff --git a/include/logging.h b/include/logging.h index 14c6997..43023ec 100644 --- a/include/logging.h +++ b/include/logging.h @@ -121,7 +121,7 @@ fmt::color level2color(LogLevel level); #define LOGV_ERROR LOG_IF(BH_LOG_LEVEL_ERROR) #define LOGV_FATAL LOG_IF(BH_LOG_LEVEL_FATAL) -enum opcode { MVVM_SOCK_SUSPEND = 0, MVVM_SOCK_RESUME = 1, MVVM_SOCK_FIN = 2 }; +enum opcode { MVVM_SOCK_SUSPEND = 0, MVVM_SOCK_RESUME = 1, MVVM_SOCK_INIT = 2, MVVM_SOCK_FIN = 2 }; struct mvvm_op_data { enum opcode op; bool is_tcp; diff --git a/include/wamr.h b/include/wamr.h index 392c082..c0b8f40 100644 --- a/include/wamr.h +++ b/include/wamr.h @@ -40,6 +40,7 @@ class WAMRInstance { std::map>>> fd_map_{}; // add offset to pair->tuple, 3rd param 'int' std::map socket_fd_map_{}; + SocketAddrPool local_addr{}; // lwcp is LightWeight CheckPoint size_t ready = 0; std::mutex as_mtx; diff --git a/include/wamr_export.h b/include/wamr_export.h index 8c9d451..e175a04 100644 --- a/include/wamr_export.h +++ b/include/wamr_export.h @@ -25,6 +25,7 @@ void insert_sock_recv_from_data(uint32_t, uint8 *, uint32, uint16_t, __wasi_addr void replay_sock_recv_from_data(uint32_t, uint8 **, unsigned long *, __wasi_addr_t *); void insert_socket(int, int, int, int); void update_socket_fd_address(int, struct SocketAddrPool *); +void init_gateway(struct SocketAddrPool *address); void set_tcp(); void insert_lock(char const *, int); void insert_sem(char const *, int); diff --git a/src/checkpoint.cpp b/src/checkpoint.cpp index 8406d4b..76daee7 100644 --- a/src/checkpoint.cpp +++ b/src/checkpoint.cpp @@ -46,50 +46,8 @@ void serialize_to_file(WASMExecEnv *instance) { auto tmp_ip6 = fmt::format("{}:{}:{}:{}:{}:{}:{}:{}", src_addr.ip6[0], src_addr.ip6[1], src_addr.ip6[2], src_addr.ip6[3], src_addr.ip6[4], src_addr.ip6[5], src_addr.ip6[6], src_addr.ip6[7]); - if (src_addr.port == 0) { - src_addr.is_4 = true; - } if (src_addr.is_4 && tmp_ip4 == "0.0.0.0" || !src_addr.is_4 && tmp_ip6 == "0:0:0:0:0:0:0:0") { - struct ifaddrs *ifaddr, *ifa; - int family, s; - char host[NI_MAXHOST]; - - if (getifaddrs(&ifaddr) == -1) { - LOGV(ERROR) << "getifaddrs"; - exit(EXIT_FAILURE); - } - - for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == nullptr) - continue; - - if (ifa->ifa_addr->sa_family == AF_INET && src_addr.is_4) { - // IPv4 - auto *ipv4 = (struct sockaddr_in *)ifa->ifa_addr; - uint32_t ip = ntohl(ipv4->sin_addr.s_addr); - if (is_ip_in_cidr(MVVM_SOCK_ADDR, MVVM_SOCK_MASK, ip)) { - // Extract IPv4 address - src_addr.ip4[0] = (ip >> 24) & 0xFF; - src_addr.ip4[1] = (ip >> 16) & 0xFF; - src_addr.ip4[2] = (ip >> 8) & 0xFF; - src_addr.ip4[3] = ip & 0xFF; - } - - } else if (ifa->ifa_addr->sa_family == AF_INET6 && !src_addr.is_4) { - // IPv6 - auto *ipv6 = (struct sockaddr_in6 *)ifa->ifa_addr; - src_addr.is_4 = false; - // Extract IPv6 address - const auto *bytes = (const uint8_t *)ipv6->sin6_addr.s6_addr; - if (is_ipv6_in_cidr(MVVM_SOCK_ADDR6, MVVM_SOCK_MASK6, &ipv6->sin6_addr)) { - for (int i = 0; i < 16; i += 2) { - src_addr.ip6[i / 2] = (bytes[i] << 8) + bytes[i + 1]; - } - } - } - } - - freeifaddrs(ifaddr); + src_addr = wamr->local_addr; } LOGV(INFO) << "addr: " << fmt::format("{}.{}.{}.{}", src_addr.ip4[0], src_addr.ip4[1], src_addr.ip4[2], src_addr.ip4[3]) @@ -110,14 +68,12 @@ void serialize_to_file(WASMExecEnv *instance) { if ((tmp_ip4 == "0.0.0.0" || tmp_ip6 == "0:0:0:0:0:0:0:0") && !wamr->op_data.is_tcp) { if (sock_data.socketSentToData.dest_addr.ip.is_4 && tmp_ip4 == "0.0.0.0" || !sock_data.socketSentToData.dest_addr.ip.is_4 && tmp_ip6 == "0:0:0:0:0:0:0:0") { - wamr->op_data.addr[idx][1].is_4 = sock_data.socketRecvFromDatas[0].src_addr.ip.is_4; std::memcpy(wamr->op_data.addr[idx][1].ip4, sock_data.socketRecvFromDatas[0].src_addr.ip.ip4, sizeof(sock_data.socketRecvFromDatas[0].src_addr.ip.ip4)); std::memcpy(wamr->op_data.addr[idx][1].ip6, sock_data.socketRecvFromDatas[0].src_addr.ip.ip6, sizeof(sock_data.socketRecvFromDatas[0].src_addr.ip.ip6)); wamr->op_data.addr[idx][1].port = sock_data.socketRecvFromDatas[0].src_addr.port; - } else { wamr->op_data.addr[idx][1].is_4 = sock_data.socketSentToData.dest_addr.ip.is_4; std::memcpy(wamr->op_data.addr[idx][1].ip4, sock_data.socketSentToData.dest_addr.ip.ip4, @@ -127,9 +83,9 @@ void serialize_to_file(WASMExecEnv *instance) { wamr->op_data.addr[idx][1].port = sock_data.socketSentToData.dest_addr.port; } } else { - unsigned int size_ =sizeof(sockaddr_in); + unsigned int size_ = sizeof(sockaddr_in); sockaddr_in *ss = (sockaddr_in *)malloc(size_); - wamr->invoke_sock_getsockname(tmp_fd, (sockaddr**)&ss, &size_); + wamr->invoke_sock_getsockname(tmp_fd, (sockaddr **)&ss, &size_); if (ss->sin_family <= AF_INET) { auto *ipv4 = (struct sockaddr_in *)ss; uint32_t ip = ntohl(ipv4->sin_addr.s_addr); diff --git a/src/wamr.cpp b/src/wamr.cpp index d0e5c46..21b3681 100644 --- a/src/wamr.cpp +++ b/src/wamr.cpp @@ -78,6 +78,46 @@ WAMRInstance::WAMRInstance(const char *wasm_path, bool is_jit) : is_jit(is_jit) LOGV(ERROR) << fmt::format("Load wasm module failed. error: {}", error_buf); throw; } + struct ifaddrs *ifaddr, *ifa; + int family, s; + char host[NI_MAXHOST]; + + if (getifaddrs(&ifaddr) == -1) { + LOGV(ERROR) << "getifaddrs"; + exit(EXIT_FAILURE); + } + + for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == nullptr) + continue; + + if (ifa->ifa_addr->sa_family == AF_INET) { + // IPv4 + auto *ipv4 = (struct sockaddr_in *)ifa->ifa_addr; + uint32_t ip = ntohl(ipv4->sin_addr.s_addr); + if (is_ip_in_cidr(MVVM_SOCK_ADDR, MVVM_SOCK_MASK, ip)) { + // Extract IPv4 address + local_addr.ip4[0] = (ip >> 24) & 0xFF; + local_addr.ip4[1] = (ip >> 16) & 0xFF; + local_addr.ip4[2] = (ip >> 8) & 0xFF; + local_addr.ip4[3] = ip & 0xFF; + } + + } else if (ifa->ifa_addr->sa_family == AF_INET6) { + // IPv6 + auto *ipv6 = (struct sockaddr_in6 *)ifa->ifa_addr; + // Extract IPv6 address + const auto *bytes = (const uint8_t *)ipv6->sin6_addr.s6_addr; + if (is_ipv6_in_cidr(MVVM_SOCK_ADDR6, MVVM_SOCK_MASK6, &ipv6->sin6_addr)) { + for (int i = 0; i < 16; i += 2) { + local_addr.ip6[i / 2] = (bytes[i] << 8) + bytes[i + 1]; + } + } + } + } + local_addr.is_4 = true; + + freeifaddrs(ifaddr); } bool WAMRInstance::load_wasm_binary(const char *wasm_path, char **buffer_ptr) { diff --git a/src/wamr_export.cpp b/src/wamr_export.cpp index 1591453..c8df236 100644 --- a/src/wamr_export.cpp +++ b/src/wamr_export.cpp @@ -223,6 +223,46 @@ void update_socket_fd_address(int fd, SocketAddrPool *address) { } } +void init_gateway(SocketAddrPool *address) { + // tell gateway to keep alive the server + struct sockaddr_in addr {}; + int fd = 0; + ssize_t rc; + wamr->op_data.op = MVVM_SOCK_INIT; + wamr->op_data.addr[0][0] = wamr->local_addr; + std::memcpy(&wamr->op_data.addr[0][1], address, sizeof(SocketAddrPool)); + + // Create a socket + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + LOGV(ERROR) << "socket error"; + throw std::runtime_error("socket error"); + } + + addr.sin_family = AF_INET; + addr.sin_port = htons(MVVM_SOCK_PORT); + + // Convert IPv4 and IPv6 addresses from text to binary form + if (inet_pton(AF_INET, MVVM_SOCK_ADDR, &addr.sin_addr) <= 0) { + LOGV(ERROR) << "AF_INET not supported"; + exit(EXIT_FAILURE); + } + // Connect to the server + if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + LOGV(ERROR) << "Connection Failed " << errno; + exit(EXIT_FAILURE); + } + + LOGV(INFO) << "Connected successfully"; + rc = send(fd, &wamr->op_data, sizeof(struct mvvm_op_data), 0); + if (rc == -1) { + LOGV(ERROR) << "send error"; + exit(EXIT_FAILURE); + } + + // Clean up + close(fd); +} + void insert_lock(char const *, int) {} void insert_sem(char const *, int) {} void remove_lock(char const *) {} diff --git a/test/tcp_client.c b/test/tcp_client.c index 73a9d0c..0c58da7 100644 --- a/test/tcp_client.c +++ b/test/tcp_client.c @@ -21,12 +21,6 @@ static void init_sockaddr_inet(struct sockaddr_in *addr) { addr->sin_port = htons(1234); addr->sin_addr.s_addr = my_inet_addr("172.17.0.2"); } -static void init_sockaddr_inet1(struct sockaddr_in *addr) { - /* 127.0.0.1:1234 */ - addr->sin_family = AF_INET; - addr->sin_port = htons(1234); - addr->sin_addr.s_addr = my_inet_addr("172.17.0.1"); -} static void init_sockaddr_inet6(struct sockaddr_in6 *addr) { /* [::1]:1234 */ addr->sin6_family = AF_INET6; @@ -38,7 +32,7 @@ void init_connect(int socket_fd) { struct sockaddr_storage server_address = {0}; int len = sizeof(struct sockaddr_in); - init_sockaddr_inet1((struct sockaddr_in *)&server_address); + init_sockaddr_inet((struct sockaddr_in *)&server_address); printf("[Client] Create socket\n"); // s_(af, SOCK_STREAM, 0,socket_fd);