Use the correct size for sockaddr_storage, otherwise it won't work on mac os x. Also use some cleaner code