Manfred Schwarb <[EMAIL PROTECTED]> writes:

>> Interesting.  Is it really necessary to zero out sockaddr/sockaddr_in
>> before using it?  I see that some sources do it, and some don't.  I
>> was always under the impression that, as long as you fill the relevant
>> members (sin_family, sin_addr, sin_port), other initialization is not
>> necessary.  Was I mistaken, or is this something specific to FreeBSD?
>>
>> Do others have experience with this?
>
> e.g. look at http://cvs.tartarus.org/putty/unix/uxnet.c
>
> putty encountered the very same problem ...

Amazing.  This obviously doesn't show up when binding to remote
addresses, or it would have been noticed ages ago.

Thanks for the pointer.  This patch should fix the problem in the CVS
version:

2004-02-06  Hrvoje Niksic  <[EMAIL PROTECTED]>

        * connect.c (sockaddr_set_data): Zero out
        sockaddr_in/sockaddr_in6.  Apparently BSD-derived stacks need this
        when binding a socket to local address.

Index: src/connect.c
===================================================================
RCS file: /pack/anoncvs/wget/src/connect.c,v
retrieving revision 1.62
diff -u -r1.62 connect.c
--- src/connect.c       2003/12/12 14:14:53     1.62
+++ src/connect.c       2004/02/06 16:59:01
@@ -87,6 +87,7 @@
     case IPV4_ADDRESS:
       {
        struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+       xzero (*sin);
        sin->sin_family = AF_INET;
        sin->sin_port = htons (port);
        sin->sin_addr = ADDRESS_IPV4_IN_ADDR (ip);
@@ -96,6 +97,7 @@
     case IPV6_ADDRESS:
       {
        struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+       xzero (*sin6);
        sin6->sin6_family = AF_INET6;
        sin6->sin6_port = htons (port);
        sin6->sin6_addr = ADDRESS_IPV6_IN6_ADDR (ip);

Reply via email to