<div dir="ltr">Hi,<div>Thanks Michael. I'll check if your proposal fits my requirement.</div><div><br></div><div>Regards,</div><div>Sanjaya</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 10, 2018 at 7:55 PM, Michael Richardson <span dir="ltr"><<a href="mailto:mcr@sandelman.ca" target="_blank">mcr@sandelman.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
Sanjaya Joshi <<a href="mailto:joshi.sanjaya@gmail.com">joshi.sanjaya@gmail.com</a>> wrote:<br>
    > Is there a BIO family of API that OpenSSL provides to bind to a<br>
    > specific source IP address before creating a socket connection (using<br>
    > for e.g. BIO_new_connect()) ?<br>
<br>
</span>I think not... BIO_new_connect() allocates the BIO, and so there isn't any<br>
state to set up before you call that.<br>
<br>
I've had to add a place to store the sockaddr to the DGRAM method in order to<br>
make DTLS work the way I want it, and it could be extended to TCP sockets I<br>
think, but not using the flow that you are using.<br>
<br>
However, you can provide the FD to the SSL context using BIO_set_fd()<br>
and SSL_set_bio():<br>
<br>
    BIO_set_fd(inbio, connectedfd, BIO_NOCLOSE);<br>
    SSL_set_bio(ssl, inbio, outbio);<br>
<br>
Then you can set up the connectedfd any way you want, calling bind() before<br>
connect.  That means that you might have to parse the host/IP + port<br>
yourself, but getaddrinfo() can do that for you, and<br>
          int BIO_lookup(const char *host, const char *service,<br>
                         enum BIO_lookup_type lookup_type,<br>
                         int family, int socktype, BIO_ADDRINFO **res);<br>
<br>
wraps it all nicely for you.<br>
<span class=""><br>
    > My application does not need to rely on the kernel-provided source IP<br>
    > address and hence the need for this.<br>
<br>
</span>Just remember to test with IPv6 Link-Local addresses, because they do<br>
matter, and they are hard to get right from userspace.<br>
(And if you aren't doing IPv6 testing, then you probably shouldn't be<br>
creating new code)<br>
<br>
--<br>
]               Never tell me the odds!                 | ipv6 mesh networks [<br>
]   Michael Richardson, Sandelman Software Works        | network architect  [<br>
]     <a href="mailto:mcr@sandelman.ca">mcr@sandelman.ca</a>  <a href="http://www.sandelman.ca/" rel="noreferrer" target="_blank">http://www.sandelman.ca/</a>        |   ruby on rails    [<br>
<br>
<br>--<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/<wbr>mailman/listinfo/openssl-users</a><br>
<br></blockquote></div><br></div>