1 .\" $OpenBSD: BIO_s_connect.3,v 1.8 2018/03/21 06:09:37 schwarze Exp $
2 .\" OpenSSL 186bb907 Apr 13 11:05:13 2015 -0700
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2015 The OpenSSL Project. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in
16 .\" the documentation and/or other materials provided with the
19 .\" 3. All advertising materials mentioning features or use of this
20 .\" software must display the following acknowledgment:
21 .\" "This product includes software developed by the OpenSSL Project
22 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\" endorse or promote products derived from this software without
26 .\" prior written permission. For written permission, please contact
27 .\" openssl-core@openssl.org.
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\" nor may "OpenSSL" appear in their names without prior written
31 .\" permission of the OpenSSL Project.
33 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\" "This product includes software developed by the OpenSSL Project
36 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .Dd $Mdocdate: March 21 2018 $
57 .Nm BIO_set_conn_hostname ,
58 .Nm BIO_set_conn_port ,
60 .Nm BIO_set_conn_int_port ,
61 .Nm BIO_get_conn_hostname ,
62 .Nm BIO_get_conn_port ,
64 .Nm BIO_get_conn_int_port ,
79 .Fo BIO_set_conn_hostname
94 .Fo BIO_set_conn_int_port
99 .Fo BIO_get_conn_hostname
103 .Fo BIO_get_conn_port
112 .Fo BIO_get_conn_int_port
127 returns the connect BIO method.
128 This is a wrapper around the platform's TCP/IP socket connection routines.
130 Using connect BIOs, TCP/IP connections can be made and data
131 transferred using only BIO routines.
132 In this way any platform specific operations
133 are hidden by the BIO abstraction.
135 Read and write operations on a connect BIO will perform I/O
136 on the underlying connection.
137 If no connection is established and the port and hostname (see below)
138 is set up properly, then a connection is established first.
145 If the close flag is set on a connect BIO, then any active connection
146 is shutdown and the socket closed when the BIO is freed.
150 on a connect BIO will close any active connection and reset the BIO
151 into a state where it can connect to the same host again.
154 places the underlying socket in
158 and also returns the socket.
166 .Fn BIO_set_conn_hostname
170 The hostname can be an IP address.
171 The hostname can also include the port in the form
172 .Ar hostname : Ns Ar port .
173 It is also acceptable to use the forms
174 .Ar hostname Ns / Ns Pa any/other/path
176 .Ar hostname : Ns Ar port Ns / Ns Pa any/other/path .
178 .Fn BIO_set_conn_port
182 is looked up as a service using
186 sets the IP address to
188 using binary form i.e. four bytes specifying the IP address
191 .Fn BIO_set_conn_int_port
199 .Fn BIO_get_conn_hostname
200 returns the hostname of the connect BIO or
202 if the BIO is initialized but no hostname is set.
203 This return value is an internal pointer which should not be modified.
205 .Fn BIO_get_conn_port
206 returns the port as a string.
207 This return value is an internal pointer which should not be modified.
210 returns the IP address in binary form.
212 .Fn BIO_get_conn_int_port
213 returns the port as an
217 sets the non-blocking I/O flag to
221 is zero then blocking I/O is set.
224 is 1 then non-blocking I/O is set.
225 Blocking I/O is the default.
228 should be made before the connection is established
229 because non-blocking I/O is set during the connect process.
235 .Fn BIO_set_conn_hostname
237 It creates a new connect BIO with
241 attempts to connect the supplied BIO.
242 It returns 1 if the connection was established successfully.
243 A zero or negative value is returned if the connection
244 could not be established.
246 .Xr BIO_should_retry 3
247 should be used for non-blocking connect BIOs
248 to determine if the call should be retried.
250 If blocking I/O is set then a non-positive return value from any
251 I/O call is caused by an error condition, although a zero return
252 will normally mean that the connection was closed.
254 If the port name is supplied as part of the host name then this will
255 override any value set with
256 .Fn BIO_set_conn_port .
257 This may be undesirable if the application does not wish to allow
258 connection to arbitrary ports.
259 This can be avoided by checking for the presence of the
261 character in the passed hostname and either indicating an error
262 or truncating the string at that point.
264 The values returned by
265 .Fn BIO_get_conn_hostname ,
266 .Fn BIO_get_conn_port ,
267 .Fn BIO_get_conn_ip ,
269 .Fn BIO_get_conn_int_port
270 are updated when a connection attempt is made.
271 Before any connection attempt the values returned
272 are those set by the application itself.
274 Applications do not have to call
276 but may wish to do so to separate the connection process
277 from other I/O processing.
279 If non-blocking I/O is set,
280 then retries will be requested as appropriate.
283 .Xr BIO_should_read 3
285 .Xr BIO_should_write 3
286 it is also possible for
287 .Xr BIO_should_io_special 3
288 to be true during the initial connection process with the reason
290 If this is returned, it is an indication
291 that a connection attempt would block.
292 The application should then take appropriate action to wait
293 until the underlying socket has connected and retry the call.
295 .Fn BIO_set_conn_hostname ,
296 .Fn BIO_set_conn_port ,
297 .Fn BIO_set_conn_ip ,
298 .Fn BIO_set_conn_int_port ,
299 .Fn BIO_get_conn_hostname ,
300 .Fn BIO_get_conn_port ,
301 .Fn BIO_get_conn_ip ,
302 .Fn BIO_get_conn_int_port ,
309 returns the connect BIO method.
312 returns the socket or -1 if the BIO has not been initialized.
314 .Fn BIO_set_conn_hostname ,
315 .Fn BIO_set_conn_port ,
316 .Fn BIO_set_conn_ip ,
318 .Fn BIO_set_conn_int_port
321 .Fn BIO_get_conn_hostname
322 returns the connected hostname or
326 .Fn BIO_get_conn_port
327 returns a string representing the connected port or
332 returns a pointer to the connected IP address in binary form
333 or all zeros if not set.
335 .Fn BIO_get_conn_int_port
336 returns the connected port or 0 if none was set.
342 returns 1 if the connection was successfully
343 established and 0 or -1 if the connection failed.
345 This example connects to a webserver on the local host and attempts
346 to retrieve a page and copy the result to standard output.
347 .Bd -literal -offset 2n
352 ERR_load_crypto_strings();
353 cbio = BIO_new_connect("localhost:http");
354 out = BIO_new_fp(stdout, BIO_NOCLOSE);
355 if (BIO_do_connect(cbio) <= 0) {
356 fprintf(stderr, "Error connecting to server\en");
357 ERR_print_errors_fp(stderr);
360 BIO_puts(cbio, "GET / HTTP/1.0\en\en");
362 len = BIO_read(cbio, tmpbuf, 1024);
365 BIO_write(out, tmpbuf, len);
374 .Fn BIO_new_connect ,
378 appeared in SSLeay 0.8.1b or earlier.
379 .Fn BIO_set_conn_hostname ,
380 .Fn BIO_set_conn_port ,
381 .Fn BIO_set_conn_ip ,
382 .Fn BIO_set_conn_int_port ,
383 .Fn BIO_get_conn_hostname ,
384 .Fn BIO_get_conn_port ,
385 .Fn BIO_get_conn_ip ,
387 .Fn BIO_get_conn_int_port
388 first appeared in SSLeay 0.9.0.
389 All these functions have been available since