[RDY] fix TCP connection (issue #870)

This fixes the broken TCP connection. It does not change the functions used to copy the IP address. Maybe there are some more improvements to be made here as described in issue #870.
I've touched on this before (yet can't find it in the original issue, I thought I had commented on it before somewhere though... #870). I agree with you. Since this code is basically owned by @tarruda, I'd like to hear what he has to say.