split socket functions into sock.c