Permalink
Browse files

Fix server.c for OSX

Memset the whole of addr to zero and add sin_len on OSX.
GitHub issue #51.
  • Loading branch information...
1 parent 03bca0a commit 6051d8b0c8f0caf47ddd3853e83b698870674a53 @nicolasff committed Jul 19, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 server.c
View
5 server.c
@@ -25,10 +25,13 @@ socket_setup(const char *ip, short port) {
struct sockaddr_in addr;
int fd, ret;
+ memset(&addr, 0, sizeof(addr));
+#if defined __APPLE__ && defined __MACH__
+ addr.sin_len = sizeof(struct sockaddr_in);
+#endif
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
- memset(&(addr.sin_addr), 0, sizeof(addr.sin_addr));
addr.sin_addr.s_addr = inet_addr(ip);
/* this sad list of tests could use a Maybe monad... */

1 comment on commit 6051d8b

@andrebraga

Thanks! But it might be better to test for BSD, this is not Apple-specific :)

Please sign in to comment.