0

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;
}
p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35
  • `ACK` packet should acknowledge sequence number sent by server – user7860670 Oct 22 '19 at 08:00
  • What is server's sequence number in SYN-ACK packet? Only if this value is '0' ack=1 value of your ACK packet is correct. – Roberto Caboni Oct 22 '19 at 08:09
  • Yeah, thx for pointing me out in right direction. The problem was that i was debugging in wireshark and i thought that the relative number of seq and ack is the real one(its stupid that i didnt notice that the binary isnt the same as the decimal relative number). – pavel gos Oct 22 '19 at 11:03

0 Answers0