I am trying to implement raw tcp connections to send query to whois server. After i send syn packet server replies with syn/ack(then my pc send rst packet, but firewall rule solved this problem). After that i send ack packet with seq = 1(first packet has seq set to 0) and ack vlaue set to one(plus i set flags to ACK). The problem is that server ignores that ack packet... Sometimes it resends few more syn/acks, sometimes it sends nothing after my ack packet(ingoring whois query packet as well...). I think the problem is somewhere in my ack packet implementation, but i cannt find out where... Any help or tips would be appreciated :)
void create_tcp_header(struct tcphdr *tcph, unsigned short source_port, unsigned short destination_port, int syn, int fin, int seq, int ack)
{
if (ack == 1)
{
tcph->ack = htonl(ack);
tcph->th_flags |= TH_ACK;
}
else
{
tcph->ack = 0;
}
tcph->syn = syn;
tcph->rst = 0;
tcph->source = source_port;
tcph->dest = destination_port;
tcph->urg = 0;
tcph->fin = fin;
tcph->psh = 0;
tcph->window = htons(TCP_MAXWIN);
tcph->urg_ptr = 0;
tcph->seq = htonl(seq);
tcph->ack_seq = htonl(seq);
tcph->doff = 5;
tcph->check = 0;
}