fix socket calls and missing binding of socket used on fd 2