Rewrite with safer code

safe wrapper on gethostbyname()
sock_listener()
sock_connector()