From cca24cb5b42eed1653807edbb922670bfb23ab2c Mon Sep 17 00:00:00 2001 From: Chion Tang Date: Sat, 16 Jun 2018 13:45:09 +0800 Subject: [PATCH] feat: SYN flag only --- src/client.c | 7 ++++++- src/common.c | 4 +++- src/server.c | 7 ++++++- src/trans_packet.c | 25 +++++++++++++++++-------- src/trans_packet.h | 1 + 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/client.c b/src/client.c index 5fe31fc..7de627c 100644 --- a/src/client.c +++ b/src/client.c @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) { vector_init(&open_connections_vector); if (argc < 5) { - printf("Usage: kcpraw_client SERVER_IP SERVER_PORT LISTEN_IP LISTEN_PORT [--mode MODE] [--key KEY] [--noseq] [--nobpf]\n"); + printf("Usage: kcpraw_client SERVER_IP SERVER_PORT LISTEN_IP LISTEN_PORT [--mode MODE] [--key KEY] [--noseq] [--syn-only] [--nobpf]\n"); exit(1); } @@ -178,12 +178,17 @@ int main(int argc, char* argv[]) { packetinfo.on_packet_recv = on_packet_recv; packetinfo.is_server = 0; packetinfo.disable_seq_update = 0; + packetinfo.syn_only = 0; for (int i=0; isource_ip, inet_ntoa(to_addr)); - if (tcph->syn == 1 && tcph->ack == 0 && tcph->psh == 0) { + if ((!packetinfo->syn_only) && tcph->syn == 1 && tcph->ack == 0 && tcph->psh == 0) { // Server replies SYN + ACK (packetinfo->state).seq = 1; (packetinfo->state).ack = 1; @@ -176,7 +176,7 @@ void check_packet_recv(struct packet_info* packetinfo) { #endif #ifndef SERVER - if (tcph->syn == 1 && tcph->ack == 1 && tcph->psh == 0) { + if ((!packetinfo->syn_only) && tcph->syn == 1 && tcph->ack == 1 && tcph->psh == 0) { //Client replies first ACK (packetinfo->state).seq = 1; (packetinfo->state).ack = 1; @@ -311,12 +311,21 @@ int send_packet(struct packet_info* packetinfo, char* source_payload, int source tcph->seq = htonl((packetinfo->state).seq); tcph->ack_seq = htonl((packetinfo->state).ack); tcph->doff = 5; //tcp header size - tcph->fin=0; - tcph->syn=0; - tcph->rst=0; - tcph->psh=1; - tcph->ack=1; - tcph->urg=0; + if (packetinfo->syn_only) { + tcph->fin=0; + tcph->syn=1; + tcph->rst=0; + tcph->psh=0; + tcph->ack=0; + tcph->urg=0; + } else { + tcph->fin=0; + tcph->syn=0; + tcph->rst=0; + tcph->psh=1; + tcph->ack=1; + tcph->urg=0; + } tcph->window = htons(129600); tcph->check = 0; //leave checksum 0 now, filled later by pseudo header tcph->urg_ptr = 0; diff --git a/src/trans_packet.h b/src/trans_packet.h index 03a4d76..abd8d8a 100644 --- a/src/trans_packet.h +++ b/src/trans_packet.h @@ -20,6 +20,7 @@ struct packet_info { int is_server; struct trans_packet_state state; int disable_seq_update; + int syn_only; }; int packet_send_sd;