update libressl to v2.7.4
[unleashed.git] / lib / libcrypto / man / BIO_s_connect.3
blob66cfff0daa182ddc7bf5d9e165d55e3f12cbb275
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
3 .\"
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2015 The OpenSSL Project.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\"
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
17 .\"    distribution.
18 .\"
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/)"
23 .\"
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.
28 .\"
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.
32 .\"
33 .\" 6. Redistributions of any form whatsoever must retain the following
34 .\"    acknowledgment:
35 .\"    "This product includes software developed by the OpenSSL Project
36 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 .\"
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.
50 .\"
51 .Dd $Mdocdate: March 21 2018 $
52 .Dt BIO_S_CONNECT 3
53 .Os
54 .Sh NAME
55 .Nm BIO_s_connect ,
56 .Nm BIO_new_connect ,
57 .Nm BIO_set_conn_hostname ,
58 .Nm BIO_set_conn_port ,
59 .Nm BIO_set_conn_ip ,
60 .Nm BIO_set_conn_int_port ,
61 .Nm BIO_get_conn_hostname ,
62 .Nm BIO_get_conn_port ,
63 .Nm BIO_get_conn_ip ,
64 .Nm BIO_get_conn_int_port ,
65 .Nm BIO_set_nbio ,
66 .Nm BIO_do_connect
67 .Nd connect BIO
68 .Sh SYNOPSIS
69 .In openssl/bio.h
70 .Ft BIO_METHOD *
71 .Fo BIO_s_connect
72 .Fa void
73 .Fc
74 .Ft BIO *
75 .Fo BIO_new_connect
76 .Fa "char *name"
77 .Fc
78 .Ft long
79 .Fo BIO_set_conn_hostname
80 .Fa "BIO *b"
81 .Fa "char *name"
82 .Fc
83 .Ft long
84 .Fo BIO_set_conn_port
85 .Fa "BIO *b"
86 .Fa "char *port"
87 .Fc
88 .Ft long
89 .Fo BIO_set_conn_ip
90 .Fa "BIO *b"
91 .Fa "char *ip"
92 .Fc
93 .Ft long
94 .Fo BIO_set_conn_int_port
95 .Fa "BIO *b"
96 .Fa "char *port"
97 .Fc
98 .Ft char *
99 .Fo BIO_get_conn_hostname
100 .Fa "BIO *b"
102 .Ft char *
103 .Fo BIO_get_conn_port
104 .Fa "BIO *b"
106 .Ft char *
107 .Fo BIO_get_conn_ip
108 .Fa "BIO *b"
109 .Fa "dummy"
111 .Ft long
112 .Fo BIO_get_conn_int_port
113 .Fa "BIO *b"
114 .Fa "int port"
116 .Ft long
117 .Fo BIO_set_nbio
118 .Fa "BIO *b"
119 .Fa "long n"
121 .Ft int
122 .Fo BIO_do_connect
123 .Fa "BIO *b"
125 .Sh DESCRIPTION
126 .Fn BIO_s_connect
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.
140 Connect BIOs support
141 .Xr BIO_puts 3
142 but not
143 .Xr BIO_gets 3 .
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.
148 Calling
149 .Xr BIO_reset 3
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.
153 .Xr BIO_get_fd 3
154 places the underlying socket in
155 .Fa c
156 if it is not
157 .Dv NULL
158 and also returns the socket.
160 .Fa c
161 is not
162 .Dv NULL
163 it should be of type
164 .Vt "int *" .
166 .Fn BIO_set_conn_hostname
167 uses the string
168 .Fa name
169 to set the 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
179 sets the port to
180 .Fa port .
181 .Fa port
182 is looked up as a service using
183 .Xr getaddrinfo 3
185 .Fn BIO_set_conn_ip
186 sets the IP address to
187 .Fa ip
188 using binary form i.e. four bytes specifying the IP address
189 in big-endian form.
191 .Fn BIO_set_conn_int_port
192 sets the port using
193 .Fa port .
194 .Fa port
195 should
196 be of type
197 .Vt "int *" .
199 .Fn BIO_get_conn_hostname
200 returns the hostname of the connect BIO or
201 .Dv NULL
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.
209 .Fn BIO_get_conn_ip
210 returns the IP address in binary form.
212 .Fn BIO_get_conn_int_port
213 returns the port as an
214 .Vt int .
216 .Fn BIO_set_nbio
217 sets the non-blocking I/O flag to
218 .Fa n .
220 .Fa n
221 is zero then blocking I/O is set.
223 .Fa n
224 is 1 then non-blocking I/O is set.
225 Blocking I/O is the default.
226 The call to
227 .Fn BIO_set_nbio
228 should be made before the connection is established
229 because non-blocking I/O is set during the connect process.
231 .Fn BIO_new_connect
232 combines
233 .Xr BIO_new 3
235 .Fn BIO_set_conn_hostname
236 into a single call.
237 It creates a new connect BIO with
238 .Fa name .
240 .Fn BIO_do_connect
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.
245 The call
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
260 .Sq \&:
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
275 .Fn BIO_do_connect
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.
282 In addition to
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
289 .Dv BIO_RR_CONNECT .
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 ,
303 .Fn BIO_set_nbio ,
305 .Fn BIO_do_connect
306 are macros.
307 .Sh RETURN VALUES
308 .Fn BIO_s_connect
309 returns the connect BIO method.
311 .Xr BIO_get_fd 3
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
319 always return 1.
321 .Fn BIO_get_conn_hostname
322 returns the connected hostname or
323 .Dv NULL
324 if none is set.
326 .Fn BIO_get_conn_port
327 returns a string representing the connected port or
328 .Dv NULL
329 if not set.
331 .Fn BIO_get_conn_ip
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.
338 .Fn BIO_set_nbio
339 always returns 1.
341 .Fn BIO_do_connect
342 returns 1 if the connection was successfully
343 established and 0 or -1 if the connection failed.
344 .Sh EXAMPLES
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
348 BIO *cbio, *out;
349 int len;
350 char tmpbuf[1024];
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);
358         /* whatever ... */
360 BIO_puts(cbio, "GET / HTTP/1.0\en\en");
361 for(;;) {
362         len = BIO_read(cbio, tmpbuf, 1024);
363         if (len <= 0)
364                 break;
365         BIO_write(out, tmpbuf, len);
367 BIO_free(cbio);
368 BIO_free(out);
370 .Sh SEE ALSO
371 .Xr BIO_new 3
372 .Sh HISTORY
373 .Fn BIO_s_connect ,
374 .Fn BIO_new_connect ,
375 .Fn BIO_set_nbio ,
377 .Fn BIO_do_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
390 .Ox 2.4 .