Please help debug my socket code!

Joe Nelson joe at
Thu Feb 14 06:44:55 UTC 2019

Ioannis Nompelis wrote:
> You fork() a child to handle the incoming connection first. Good. The
> child goes into a reactive mode, receiving several commands and
> responding back with 3-letter codes and some text. Fine.

One thing techieb0y pointed out is that I should queue the child PIDs
and waitpid(2) for them on exit in my parent process to avoid zombie
processes. I had a pesky zombie process on the frostbyte server from
some of my experiments. I'll add that code to the program.

> Where is the new port that is associated with pasvfd communicated back
> to the client? (This is a protocol issue.) Is it happening in line 251
> here?
>          fprintf(conn, "227 Entering Passive Mode %s\n", pasv_desc);

That's exactly right.

Another complication we discovered in the pairing session tonight was
that the IP address reported is which is fine to bind on, but
not right for the client to connect to. Have to modify the code to
getsockname() on the socket that accept() returns rather than the one
used in bind().

> I recommend that you sit on two terminals with CURL and type in all of
> what you expect of the client and talk to your server.

I ended up exercising it with an ftp client, and using tcpdump and
wireshark to see what was going on.

More information about the Friends mailing list