net: socket: fix for a341821ad89d57f43e719310368cef51660ef266

The former fix for socket initialization was broken. This fixes the
"fix" by using the right exit condition for the loops.