Please help debug my socket code!

Joe Nelson joe at begriffs.com
Thu Feb 14 06:38:45 UTC 2019


> Hey all, I've been stuck on a bug for a few nights now, wondering if
> you can help me figure out what's wrong.

I did some pair programming tonight with techieb0y [0] at the Hack
Factory tonight and we figured out the problem. That guy really knows
Unix internals, holy crap.

The actual bug was pretty dumb. After the client sends PASV, the server
returns six comma-separated numbers: the four numbers in an IPv4
address, and the port separated into low and high bytes. I had swapped
the order of those port bytes, so the client then tried connecting to a
port I wasn't listening on.

The `lsof` and equivalent BSD `fstat` saved the day, because they showed
exactly what ports the server was binding to per socket file descriptor,
and those numbers were not matching what I was reporting to the client.

[0]: https://github.com/techieb0y


More information about the Friends mailing list