>       From: [email protected] On Behalf Of Manish Jain
>       Sent: Thursday, 17 November, 2011 00:30

>       I am new to openssl and trying to create a demo client 
> and server which use SSL v3. But the server, for some reason 
> I cannot figure out, always refuses connections wth the client 
> reporting errno as ECONNREFUSED. 
        
<snip>
>           sockaddr_in addr;
>   
>           int sock = socket(AF_INET, SOCK_STREAM, 0);
>           sockaddr_in sin;
>           int val = 1;
            
>           memset((char *)&addr, 0, sizeof(addr));
>           addr.sin_addr.s_addr=INADDR_ANY;
>           addr.sin_family = AF_INET;
>           addr.sin_port = htons(PORT);
>           setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
            
>           bind(sock, (sockaddr *) &sin, sizeof(sin));
<snip>

You're filling in addr, but then binding to sin, 
which is uninitialized and probably contains zero 
or else stack garbage, either way not what you want.

Aside: you don't need to cast (char*)&addr for memset 
since C switched to void* in 1989. However, you do need 
(sockaddr*)&a_sockaddr_in (or other sockaddr_x types),
since those are not special the way void is.


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [email protected]

Reply via email to