From: jacob Date: Tue, 3 Feb 2004 14:47:43 +0000 (+0000) Subject: Patch from Theo Markettos: apparently "BSD-derived IP stacks fall over when X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/d2c2927496535d8d67042980001fadede5e19b99 Patch from Theo Markettos: apparently "BSD-derived IP stacks fall over when trying to bind to the localhost interface with a sockaddr_in which has non-zero sin_zero fields." Zero sockaddr_in (and sockaddr_in6) before any use. git-svn-id: svn://svn.tartarus.org/sgt/putty@3793 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/unix/uxnet.c b/unix/uxnet.c index cbe67306..46b619bd 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -434,6 +434,11 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline, else localport = 0; /* just use port 0 (ie kernel picks) */ + /* BSD IP stacks need sockaddr_in zeroed before filling in */ + memset(&a,'\0',sizeof(struct sockaddr_in)); +#ifdef IPV6 + memset(&a6,'\0',sizeof(struct sockaddr_in6)); +#endif /* Loop round trying to bind */ while (1) { int retcode; @@ -574,7 +579,12 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)); + /* BSD IP stacks need sockaddr_in zeroed before filling in */ + memset(&a,'\0',sizeof(struct sockaddr_in)); #ifdef IPV6 +#if 0 + memset(&a6,'\0',sizeof(struct sockaddr_in6)); +#endif hints.ai_flags = AI_NUMERICHOST; hints.ai_family = AF_UNSPEC; hints.ai_socktype = 0;