BIO_s_connect.3ossl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "BIO_S_CONNECT 3ossl"
  136. .TH BIO_S_CONNECT 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. BIO_s_connect, BIO_new_connect,
  143. BIO_set_conn_hostname, BIO_set_conn_port,
  144. BIO_set_conn_address, BIO_set_conn_ip_family,
  145. BIO_get_conn_hostname, BIO_get_conn_port,
  146. BIO_get_conn_address, BIO_get_conn_ip_family,
  147. BIO_set_nbio, BIO_set_sock_type, BIO_get_sock_type, BIO_get0_dgram_bio,
  148. BIO_do_connect \- connect BIO
  149. .SH "SYNOPSIS"
  150. .IX Header "SYNOPSIS"
  151. .Vb 1
  152. \& #include <openssl/bio.h>
  153. \&
  154. \& const BIO_METHOD *BIO_s_connect(void);
  155. \&
  156. \& BIO *BIO_new_connect(const char *name);
  157. \&
  158. \& long BIO_set_conn_hostname(BIO *b, char *name);
  159. \& long BIO_set_conn_port(BIO *b, char *port);
  160. \& long BIO_set_conn_address(BIO *b, BIO_ADDR *addr);
  161. \& long BIO_set_conn_ip_family(BIO *b, long family);
  162. \& const char *BIO_get_conn_hostname(BIO *b);
  163. \& const char *BIO_get_conn_port(BIO *b);
  164. \& const BIO_ADDR *BIO_get_conn_address(BIO *b);
  165. \& const long BIO_get_conn_ip_family(BIO *b);
  166. \&
  167. \& long BIO_set_nbio(BIO *b, long n);
  168. \&
  169. \& int BIO_set_sock_type(BIO *b, int sock_type);
  170. \& int BIO_get_sock_type(BIO *b);
  171. \& int BIO_get0_dgram_bio(BIO *B, BIO **dgram_bio);
  172. \&
  173. \& long BIO_do_connect(BIO *b);
  174. .Ve
  175. .SH "DESCRIPTION"
  176. .IX Header "DESCRIPTION"
  177. \&\fBBIO_s_connect()\fR returns the connect \s-1BIO\s0 method. This is a wrapper
  178. round the platform's \s-1TCP/IP\s0 socket connection routines.
  179. .PP
  180. Using connect BIOs, \s-1TCP/IP\s0 connections can be made and data
  181. transferred using only \s-1BIO\s0 routines. In this way any platform
  182. specific operations are hidden by the \s-1BIO\s0 abstraction.
  183. .PP
  184. Read and write operations on a connect \s-1BIO\s0 will perform I/O
  185. on the underlying connection. If no connection is established
  186. and the port and hostname (see below) is set up properly then
  187. a connection is established first.
  188. .PP
  189. Connect BIOs support \fBBIO_puts()\fR and \fBBIO_gets()\fR.
  190. .PP
  191. If the close flag is set on a connect \s-1BIO\s0 then any active
  192. connection is shutdown and the socket closed when the \s-1BIO\s0
  193. is freed.
  194. .PP
  195. Calling \fBBIO_reset()\fR on a connect \s-1BIO\s0 will close any active
  196. connection and reset the \s-1BIO\s0 into a state where it can connect
  197. to the same host again.
  198. .PP
  199. \&\fBBIO_new_connect()\fR combines \fBBIO_new()\fR and \fBBIO_set_conn_hostname()\fR into
  200. a single call: that is it creates a new connect \s-1BIO\s0 with hostname \fBname\fR.
  201. .PP
  202. \&\fBBIO_set_conn_hostname()\fR uses the string \fBname\fR to set the hostname.
  203. The hostname can be an \s-1IP\s0 address; if the address is an IPv6 one, it
  204. must be enclosed with brackets \f(CW\*(C`[\*(C'\fR and \f(CW\*(C`]\*(C'\fR.
  205. The hostname can also include the port in the form hostname:port;
  206. see \fBBIO_parse_hostserv\fR\|(3) and \fBBIO_set_conn_port()\fR for details.
  207. .PP
  208. \&\fBBIO_set_conn_port()\fR sets the port to \fBport\fR. \fBport\fR can be the
  209. numerical form or a service string such as \*(L"http\*(R", which
  210. will be mapped to a port number using the system function \fBgetservbyname()\fR.
  211. .PP
  212. \&\fBBIO_set_conn_address()\fR sets the address and port information using
  213. a \s-1\fBBIO_ADDR\s0\fR\|(3ssl).
  214. .PP
  215. \&\fBBIO_set_conn_ip_family()\fR sets the \s-1IP\s0 family.
  216. .PP
  217. \&\fBBIO_get_conn_hostname()\fR returns the hostname of the connect \s-1BIO\s0 or
  218. \&\s-1NULL\s0 if the \s-1BIO\s0 is initialized but no hostname is set.
  219. This return value is an internal pointer which should not be modified.
  220. .PP
  221. \&\fBBIO_get_conn_port()\fR returns the port as a string.
  222. This return value is an internal pointer which should not be modified.
  223. .PP
  224. \&\fBBIO_get_conn_address()\fR returns the address information as a \s-1BIO_ADDR.\s0
  225. This return value is an internal pointer which should not be modified.
  226. .PP
  227. \&\fBBIO_get_conn_ip_family()\fR returns the \s-1IP\s0 family of the connect \s-1BIO.\s0
  228. .PP
  229. \&\fBBIO_set_nbio()\fR sets the non blocking I/O flag to \fBn\fR. If \fBn\fR is
  230. zero then blocking I/O is set. If \fBn\fR is 1 then non blocking I/O
  231. is set. Blocking I/O is the default. The call to \fBBIO_set_nbio()\fR
  232. should be made before the connection is established because
  233. non blocking I/O is set during the connect process.
  234. .PP
  235. \&\fBBIO_do_connect()\fR attempts to connect the supplied \s-1BIO.\s0
  236. This performs an \s-1SSL/TLS\s0 handshake as far as supported by the \s-1BIO.\s0
  237. For non-SSL BIOs the connection is done typically at \s-1TCP\s0 level.
  238. If domain name resolution yields multiple \s-1IP\s0 addresses all of them are tried
  239. after \fBconnect()\fR failures.
  240. The function returns 1 if the connection was established successfully.
  241. A zero or negative value is returned if the connection could not be established.
  242. The call \fBBIO_should_retry()\fR should be used for non blocking connect BIOs
  243. to determine if the call should be retried.
  244. If a connection has already been established this call has no effect.
  245. .PP
  246. \&\fBBIO_set_sock_type()\fR can be used to set a socket type value as would be passed in
  247. a call to \fBsocket\fR\|(2). The only currently supported values are \fB\s-1SOCK_STREAM\s0\fR (the
  248. default) and \fB\s-1SOCK_DGRAM\s0\fR. If \fB\s-1SOCK_DGRAM\s0\fR is configured, the connection
  249. created is a \s-1UDP\s0 datagram socket handled via \fBBIO_s_datagram\fR\|(3).
  250. I/O calls such as \fBBIO_read\fR\|(3) and \fBBIO_write\fR\|(3) are forwarded transparently
  251. to an internal \fBBIO_s_datagram\fR\|(3) instance. The created \fBBIO_s_datagram\fR\|(3)
  252. instance can be retrieved using \fBBIO_get0_dgram_bio()\fR if desired, which writes
  253. a pointer to the \fBBIO_s_datagram\fR\|(3) instance to \fI*dgram_bio\fR. The lifetime
  254. of the internal \fBBIO_s_datagram\fR\|(3) is managed by \fBBIO_s_connect()\fR and does not
  255. need to be freed by the caller.
  256. .PP
  257. \&\fBBIO_get_sock_type()\fR retrieves the value set using \fBBIO_set_sock_type()\fR.
  258. .SH "NOTES"
  259. .IX Header "NOTES"
  260. If blocking I/O is set then a non positive return value from any
  261. I/O call is caused by an error condition, although a zero return
  262. will normally mean that the connection was closed.
  263. .PP
  264. If the port name is supplied as part of the hostname then this will
  265. override any value set with \fBBIO_set_conn_port()\fR. This may be undesirable
  266. if the application does not wish to allow connection to arbitrary
  267. ports. This can be avoided by checking for the presence of the ':'
  268. character in the passed hostname and either indicating an error or
  269. truncating the string at that point.
  270. .PP
  271. The values returned by \fBBIO_get_conn_hostname()\fR, \fBBIO_get_conn_address()\fR,
  272. and \fBBIO_get_conn_port()\fR are updated when a connection attempt is made.
  273. Before any connection attempt the values returned are those set by the
  274. application itself.
  275. .PP
  276. Applications do not have to call \fBBIO_do_connect()\fR but may wish to do
  277. so to separate the connection process from other I/O processing.
  278. .PP
  279. If non blocking I/O is set then retries will be requested as appropriate.
  280. .PP
  281. It addition to \fBBIO_should_read()\fR and \fBBIO_should_write()\fR it is also
  282. possible for \fBBIO_should_io_special()\fR to be true during the initial
  283. connection process with the reason \s-1BIO_RR_CONNECT.\s0 If this is returned
  284. then this is an indication that a connection attempt would block,
  285. the application should then take appropriate action to wait until
  286. the underlying socket has connected and retry the call.
  287. .PP
  288. \&\fBBIO_set_conn_hostname()\fR, \fBBIO_set_conn_port()\fR, \fBBIO_get_conn_hostname()\fR,
  289. \&\fBBIO_set_conn_address()\fR, \fBBIO_get_conn_port()\fR, \fBBIO_get_conn_address()\fR,
  290. \&\fBBIO_set_conn_ip_family()\fR, \fBBIO_get_conn_ip_family()\fR,
  291. \&\fBBIO_set_nbio()\fR, and \fBBIO_do_connect()\fR are macros.
  292. .SH "RETURN VALUES"
  293. .IX Header "RETURN VALUES"
  294. \&\fBBIO_s_connect()\fR returns the connect \s-1BIO\s0 method.
  295. .PP
  296. \&\fBBIO_set_conn_address()\fR, \fBBIO_set_conn_port()\fR, and \fBBIO_set_conn_ip_family()\fR
  297. return 1 or <=0 if an error occurs.
  298. .PP
  299. \&\fBBIO_set_conn_hostname()\fR returns 1 on success and <=0 on failure.
  300. .PP
  301. \&\fBBIO_get_conn_address()\fR returns the address information or \s-1NULL\s0 if none
  302. was set.
  303. .PP
  304. \&\fBBIO_get_conn_hostname()\fR returns the connected hostname or \s-1NULL\s0 if
  305. none was set.
  306. .PP
  307. \&\fBBIO_get_conn_ip_family()\fR returns the address family or \-1 if none was set.
  308. .PP
  309. \&\fBBIO_get_conn_port()\fR returns a string representing the connected
  310. port or \s-1NULL\s0 if not set.
  311. .PP
  312. \&\fBBIO_set_nbio()\fR returns 1 or <=0 if an error occurs.
  313. .PP
  314. \&\fBBIO_do_connect()\fR returns 1 if the connection was successfully
  315. established and <=0 if the connection failed.
  316. .PP
  317. \&\fBBIO_set_sock_type()\fR returns 1 on success or 0 on failure.
  318. .PP
  319. \&\fBBIO_get_sock_type()\fR returns a socket type or 0 if the call is not supported.
  320. .PP
  321. \&\fBBIO_get0_dgram_bio()\fR returns 1 on success or 0 on failure.
  322. .SH "EXAMPLES"
  323. .IX Header "EXAMPLES"
  324. This is example connects to a webserver on the local host and attempts
  325. to retrieve a page and copy the result to standard output.
  326. .PP
  327. .Vb 3
  328. \& BIO *cbio, *out;
  329. \& int len;
  330. \& char tmpbuf[1024];
  331. \&
  332. \& cbio = BIO_new_connect("localhost:http");
  333. \& out = BIO_new_fp(stdout, BIO_NOCLOSE);
  334. \& if (BIO_do_connect(cbio) <= 0) {
  335. \& fprintf(stderr, "Error connecting to server\en");
  336. \& ERR_print_errors_fp(stderr);
  337. \& exit(1);
  338. \& }
  339. \& BIO_puts(cbio, "GET / HTTP/1.0\en\en");
  340. \& for (;;) {
  341. \& len = BIO_read(cbio, tmpbuf, 1024);
  342. \& if (len <= 0)
  343. \& break;
  344. \& BIO_write(out, tmpbuf, len);
  345. \& }
  346. \& BIO_free(cbio);
  347. \& BIO_free(out);
  348. .Ve
  349. .SH "SEE ALSO"
  350. .IX Header "SEE ALSO"
  351. \&\s-1\fBBIO_ADDR\s0\fR\|(3), \fBBIO_parse_hostserv\fR\|(3)
  352. .SH "HISTORY"
  353. .IX Header "HISTORY"
  354. \&\fBBIO_set_conn_int_port()\fR, \fBBIO_get_conn_int_port()\fR, \fBBIO_set_conn_ip()\fR, and \fBBIO_get_conn_ip()\fR
  355. were removed in OpenSSL 1.1.0.
  356. Use \fBBIO_set_conn_address()\fR and \fBBIO_get_conn_address()\fR instead.
  357. .PP
  358. Connect BIOs support \fBBIO_gets()\fR since OpenSSL 3.2.
  359. .SH "COPYRIGHT"
  360. .IX Header "COPYRIGHT"
  361. Copyright 2000\-2023 The OpenSSL Project Authors. All Rights Reserved.
  362. .PP
  363. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  364. this file except in compliance with the License. You can obtain a copy
  365. in the file \s-1LICENSE\s0 in the source distribution or at
  366. <https://www.openssl.org/source/license.html>.