Skip to content
This repository
Browse code

Fix server.c for OSX

Memset the whole of addr to zero and add sin_len on OSX.
GitHub issue #51.
  • Loading branch information...
commit 6051d8b0c8f0caf47ddd3853e83b698870674a53 1 parent 03bca0a
Nicolas Favre-Felix authored

Showing 1 changed file with 4 additions and 1 deletion. Show diff stats Hide diff stats

  1. +4 1 server.c
5 server.c
@@ -25,10 +25,13 @@ socket_setup(const char *ip, short port) {
25 25 struct sockaddr_in addr;
26 26 int fd, ret;
27 27
  28 + memset(&addr, 0, sizeof(addr));
  29 +#if defined __APPLE__ && defined __MACH__
  30 + addr.sin_len = sizeof(struct sockaddr_in);
  31 +#endif
28 32 addr.sin_family = AF_INET;
29 33 addr.sin_port = htons(port);
30 34
31   - memset(&(addr.sin_addr), 0, sizeof(addr.sin_addr));
32 35 addr.sin_addr.s_addr = inet_addr(ip);
33 36
34 37 /* this sad list of tests could use a Maybe monad... */

1 comment on commit 6051d8b

André Braga

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

Please sign in to comment.
Something went wrong with that request. Please try again.