views:

282

answers:

3

Hi there, I'm building my own webserver based on a tutorial. I have found a simple way to initiate a TCP connection and send one segment of http data (the webserver will run on a microcontroller, so it will be very small)

Anyway, the following is the sequence I need to go through:

  1. receive SYN

  2. send SYN,ACK

  3. receive ACK (the connection is now established)

  4. receive ACK with HTTP GET command

  5. send ACK

  6. send FIN,ACK with HTTP data (e.g 200 OK)

  7. receive FIN,ACK <- I don't recieve this packet!

  8. send ACK

Everything works fine until I send my acknowledgement and HTTP 200 OK message. The client won't send an acknowledgement to those two packages and thus no webpage is being displayed. I've added a pcap file of the sequence how I recorded it with wireshark.

Pcap file: http://cl.ly/5f5 (now it's the right data)

All sequence and acknowledgement numbers are correct, checksum are ok. Flags are also right. I have no idea what is going wrong.

+1  A: 

I think that step 6. should be just FIN, without ACK. What packet from the client are you ACKing at that place? Also I don't see why 4. should be an ACK instead of just a normal data packet - the client ACKed the connection at 3.

This diagram on TCP states might help.

Anders Abel
I don't have any influence on number 4, that's the client (in this case windows xp with firefox). However, I tried using just the FIN flag on step 6. but it won't matter.Could it have something to do with delayed acknowledgements?
Evert
In practice, essentially all TCP packets are also ACKs - the ACK sequence #/window size fields are always present in the header, so whenever you're sending some data it makes sense to "piggyback" the current ack information.
David Gelhar
A: 

WireShark says (of the FIN packet):

Broken TCP: The acknowledge field is nonzero while the ACK flag is not set

I don't know for sure that's what's causing your problem, but if WireShark doesn't like that packet, maybe the client doesn't either. So, it should be FIN+ACK, or you should set the acknowledge field to 0.

If that doesn't solve it, you might also try sending the data first, then a separate FIN packet. It's valid to include data with the FIN, but it's more common to send the FIN by itself (as seen in the other pcap trace you posted earlier).

Also, you should probably be setting the PUSH flag in the packet with the 200 OK

Finally, I don't see any retransmission attempts for the FIN packet - is that because you stopped the capture right away?

David Gelhar
Correct, I've tried playing with those flags, that's why it's incorrect in this capture. I've reverted it to psh/ack.I've build a seperate fin packet and transmitted it to the client. The client responds with fin/ack but with a wrong acknowledgement number (still 1). It looks like the client didn't saw the HTTP packet, otherwise the acknowledgement number would be the number of bytes I have sent in the http 200 OK packet right? I wonder what's causing this?You're right about the fin packet retransmission. I stopped it right away.
Evert
A: 

The IP length field was consequently counting 8 bits too much. I made a mistake in my calculations. Everythings works like a charm now!

Evert