Please help debug my socket code!

Ioannis Nompelis nompelis at nobelware.com
Thu Feb 14 14:14:55 UTC 2019


I looked up techieb0y. I think I have met him at the Hack Factory. Is he on
this list?

> 
> > 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.
>

Ha! I accept full credit Joe! It was obvious, given that everything looked
correct, that the client was not getting the right information it needed to
re-connect. Had I any knowledge of the actual FTP protocol, I might have had
a chance at actually finding the problem without running the code at all.
(Big honour badge there, he?)

 
> Another complication we discovered in the pairing session tonight was
> that the IP address reported is 0.0.0.0 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().
>

#MeThinks that bind()ing to 0.0.0.0 is equivalent to listening on all
interfaces -- I could be wrong. For an outgoing connection, this is not
meaningful to begin with, but it is a valid address, albeit not routed
to properly.

Regarding the second part, on getsockname() on the second socket, this is
a very confusing part of sockets IP (TCP and DGRAM) programming for a lot
of people, and this including my younger self about 20 years ago. There is
more than once socket (or more than two, for that matter) when serving TCP
connections. Studying the TCP specification stack I never really did. But
now I know enough to not have too many issues when programming it.

ON an unrelated but related topic, I have found that there were a lot of "not
very good" tutorials on OpenSSL. So I put together a pair of demos (server-
client and web-fetch) using OpenSSL that are trying to be very intuitive
and verbose: https://github.com/nompelis/INSSL But if you are doing anything
more serious, take Sam's advice and use CURL for everything.



More information about the Friends mailing list