2

I'm having an issue with a tcp handshake that I can't find the answer to anywhere else.

I have a program running on my local device that posts data to port 50000. In a terminal on the same machine, I use netcat to connect to the port. However, while using tcpdump and wireshark, I can see that the SYN packets are sent but the SYN/ACK packets are never sent in response. My iptables have no rules for connections, and the default policy for all chains is to accept the connection. This happens every time I try to connect, and so far I can't see why the server is not responding to the SYN packets.

Austin
  • 41
  • 6
  • What is listening on port 50000? – Michael Hampton Jan 15 '19 at 20:34
  • I have a C program that creates a socket and listens to port 50000. nc localhost 50000 is used to connect to the port. This command sends the SYN packets, and since it doesn't get a response it retransmits them. – Austin Jan 15 '19 at 20:35
  • Your program needs to `accept()` the connection. It sounds like it is not doing so for some reason. You can get help debugging your program on our sister site, [so]. – Michael Hampton Jan 15 '19 at 20:36
  • `I can see that the SYN packets are sent but the SYN/ACK packets are never sent in response` - Is the SYN being received? It sounds like you're troubleshooting this from only one side. – joeqwerty Jan 15 '19 at 20:37
  • @MichaelHampton you're right, accept() needs to run. From what I've seen this takes place after the handshake is complete, so it appears I'm not even getting to this point. – Austin Jan 15 '19 at 20:41
  • @joeqwerty is there a tool you recommend to see if the packet was received? All I know how to use is wireshark and I am very new at it. – Austin Jan 15 '19 at 20:42
  • It's unclear to me if your client and server are both on the same host. – kasperd Jan 15 '19 at 22:00
  • @kasperd user has stated: "[...] program running on my local device [...] In a terminal on the same machine, I use netcat to connect to the port" so user must be going over localhost using server and netcat on the same machine. @austin - if you create a `netcat` in listening mode on that port and then connect to it with a `netcat` in client mode and sending some data does that work? – Anon Jan 16 '19 at 05:33
  • @Anon I have been able to get it to work using two netcat terminals. The problem only seems to happen when the program is running. I've looked through the code and run it on another machine and it doesn't appear to be an issue with anything on the program's side of things. Also, I've just run netstat and it shows that port 50000 is in listening mode when the program is running. – Austin Jan 16 '19 at 13:02

1 Answers1

2

I fixed it. To my dismay, it actually was a code issue. We set our listen() backlog size to 0, causing any attempted connection to fail. In the case of TCP this meant retransmitting the packets. Don't know how this worked on one machine and not the other, but now they both work. Thanks for the comments everyone.

Austin
  • 41
  • 6