Do the socket initialization in a helper function.

Signed-off-by: Thiago Farina <tfarina@chromium.org>