diff options
Diffstat (limited to 'src/lib/libcrypto/man/BIO_s_connect.3')
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_connect.3 | 332 |
1 files changed, 332 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/BIO_s_connect.3 b/src/lib/libcrypto/man/BIO_s_connect.3 new file mode 100644 index 0000000000..960400e853 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_connect.3 | |||
| @@ -0,0 +1,332 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_CONNECT 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_connect , | ||
| 6 | .Nm BIO_new_connect , | ||
| 7 | .Nm BIO_set_conn_hostname , | ||
| 8 | .Nm BIO_set_conn_port , | ||
| 9 | .Nm BIO_set_conn_ip , | ||
| 10 | .Nm BIO_set_conn_int_port , | ||
| 11 | .Nm BIO_get_conn_hostname , | ||
| 12 | .Nm BIO_get_conn_port , | ||
| 13 | .Nm BIO_get_conn_ip , | ||
| 14 | .Nm BIO_get_conn_int_port , | ||
| 15 | .Nm BIO_set_nbio , | ||
| 16 | .Nm BIO_do_connect | ||
| 17 | .Nd connect BIO | ||
| 18 | .Sh SYNOPSIS | ||
| 19 | .In openssl/bio.h | ||
| 20 | .Ft BIO_METHOD * | ||
| 21 | .Fo BIO_s_connect | ||
| 22 | .Fa void | ||
| 23 | .Fc | ||
| 24 | .Ft BIO * | ||
| 25 | .Fo BIO_new_connect | ||
| 26 | .Fa "char *name" | ||
| 27 | .Fc | ||
| 28 | .Ft long | ||
| 29 | .Fo BIO_set_conn_hostname | ||
| 30 | .Fa "BIO *b" | ||
| 31 | .Fa "char *name" | ||
| 32 | .Fc | ||
| 33 | .Ft long | ||
| 34 | .Fo BIO_set_conn_port | ||
| 35 | .Fa "BIO *b" | ||
| 36 | .Fa "char *port" | ||
| 37 | .Fc | ||
| 38 | .Ft long | ||
| 39 | .Fo BIO_set_conn_ip | ||
| 40 | .Fa "BIO *b" | ||
| 41 | .Fa "char *ip" | ||
| 42 | .Fc | ||
| 43 | .Ft long | ||
| 44 | .Fo BIO_set_conn_int_port | ||
| 45 | .Fa "BIO *b" | ||
| 46 | .Fa "char *port" | ||
| 47 | .Fc | ||
| 48 | .Ft char * | ||
| 49 | .Fo BIO_get_conn_hostname | ||
| 50 | .Fa "BIO *b" | ||
| 51 | .Fc | ||
| 52 | .Ft char * | ||
| 53 | .Fo BIO_get_conn_port | ||
| 54 | .Fa "BIO *b" | ||
| 55 | .Fc | ||
| 56 | .Ft char * | ||
| 57 | .Fo BIO_get_conn_ip | ||
| 58 | .Fa "BIO *b" | ||
| 59 | .Fa "dummy" | ||
| 60 | .Fc | ||
| 61 | .Ft long | ||
| 62 | .Fo BIO_get_conn_int_port | ||
| 63 | .Fa "BIO *b" | ||
| 64 | .Fa "int port" | ||
| 65 | .Fc | ||
| 66 | .Ft long | ||
| 67 | .Fo BIO_set_nbio | ||
| 68 | .Fa "BIO *b" | ||
| 69 | .Fa "long n" | ||
| 70 | .Fc | ||
| 71 | .Ft int | ||
| 72 | .Fo BIO_do_connect | ||
| 73 | .Fa "BIO *b" | ||
| 74 | .Fc | ||
| 75 | .Sh DESCRIPTION | ||
| 76 | .Fn BIO_s_connect | ||
| 77 | returns the connect BIO method. | ||
| 78 | This is a wrapper around the platform's TCP/IP socket connection routines. | ||
| 79 | .Pp | ||
| 80 | Using connect BIOs, TCP/IP connections can be made and data | ||
| 81 | transferred using only BIO routines. | ||
| 82 | In this way any platform specific operations | ||
| 83 | are hidden by the BIO abstraction. | ||
| 84 | .Pp | ||
| 85 | Read and write operations on a connect BIO will perform I/O | ||
| 86 | on the underlying connection. | ||
| 87 | If no connection is established and the port and hostname (see below) | ||
| 88 | is set up properly, then a connection is established first. | ||
| 89 | .Pp | ||
| 90 | Connect BIOs support | ||
| 91 | .Xr BIO_puts 3 | ||
| 92 | but not | ||
| 93 | .Xr BIO_gets 3 . | ||
| 94 | .Pp | ||
| 95 | If the close flag is set on a connect BIO, then any active connection | ||
| 96 | is shutdown and the socket closed when the BIO is freed. | ||
| 97 | .Pp | ||
| 98 | Calling | ||
| 99 | .Xr BIO_reset 3 | ||
| 100 | on a connect BIO will close any active connection and reset the BIO | ||
| 101 | into a state where it can connect to the same host again. | ||
| 102 | .Pp | ||
| 103 | .Xr BIO_get_fd 3 | ||
| 104 | places the underlying socket in | ||
| 105 | .Fa c | ||
| 106 | if it is not | ||
| 107 | .Dv NULL , | ||
| 108 | it also returns the socket. | ||
| 109 | If | ||
| 110 | .Fa c | ||
| 111 | is not | ||
| 112 | .Dv NULL | ||
| 113 | it should be of type | ||
| 114 | .Vt "int *" . | ||
| 115 | .Pp | ||
| 116 | .Fn BIO_set_conn_hostname | ||
| 117 | uses the string | ||
| 118 | .Fa name | ||
| 119 | to set the hostname. | ||
| 120 | The hostname can be an IP address. | ||
| 121 | The hostname can also include the port in the form | ||
| 122 | .Ar hostname : Ns Ar port . | ||
| 123 | It is also acceptable to use the forms | ||
| 124 | .Ar hostname Ns / Ns Pa any/other/path | ||
| 125 | or | ||
| 126 | .Ar hostname : Ns Ar port Ns / Ns Pa any/other/path . | ||
| 127 | .Pp | ||
| 128 | .Fn BIO_set_conn_port | ||
| 129 | sets the port to | ||
| 130 | .Fa port . | ||
| 131 | .Fa port | ||
| 132 | can be the numerical form or a string such as | ||
| 133 | .Cm http . | ||
| 134 | A string will be looked up first using | ||
| 135 | .Xr getservbyname 3 | ||
| 136 | on the host platform, but if that fails | ||
| 137 | a built-in table of port names will be used. | ||
| 138 | Currently the list is | ||
| 139 | .Cm http , | ||
| 140 | .Cm telnet , | ||
| 141 | .Cm socks , | ||
| 142 | .Cm https , | ||
| 143 | .Cm ssl , | ||
| 144 | .Cm ftp , | ||
| 145 | .Cm gopher , | ||
| 146 | and | ||
| 147 | .Cm wais . | ||
| 148 | .Pp | ||
| 149 | .Fn BIO_set_conn_ip | ||
| 150 | sets the IP address to | ||
| 151 | .Fa ip | ||
| 152 | using binary form, that is four bytes specifying the IP address | ||
| 153 | in big-endian form. | ||
| 154 | .Pp | ||
| 155 | .Fn BIO_set_conn_int_port | ||
| 156 | sets the port using | ||
| 157 | .Fa port . | ||
| 158 | .Fa port | ||
| 159 | should | ||
| 160 | be of type | ||
| 161 | .Vt "int *" . | ||
| 162 | .Pp | ||
| 163 | .Fn BIO_get_conn_hostname | ||
| 164 | returns the hostname of the connect BIO or | ||
| 165 | .Dv NULL | ||
| 166 | if the BIO is initialized but no hostname is set. | ||
| 167 | This return value is an internal pointer which should not be modified. | ||
| 168 | .Pp | ||
| 169 | .Fn BIO_get_conn_port | ||
| 170 | returns the port as a string. | ||
| 171 | .Pp | ||
| 172 | .Fn BIO_get_conn_ip | ||
| 173 | returns the IP address in binary form. | ||
| 174 | .Pp | ||
| 175 | .Fn BIO_get_conn_int_port | ||
| 176 | returns the port as an | ||
| 177 | .Vt int . | ||
| 178 | .Pp | ||
| 179 | .Fn BIO_set_nbio | ||
| 180 | sets the non blocking I/O flag to | ||
| 181 | .Fa n . | ||
| 182 | If | ||
| 183 | .Fa n | ||
| 184 | is zero then blocking I/O is set. | ||
| 185 | If | ||
| 186 | .Fa n | ||
| 187 | is 1 then non blocking I/O is set. | ||
| 188 | Blocking I/O is the default. | ||
| 189 | The call to | ||
| 190 | .Fn BIO_set_nbio | ||
| 191 | should be made before the connection is established | ||
| 192 | because non blocking I/O is set during the connect process. | ||
| 193 | .Pp | ||
| 194 | .Fn BIO_new_connect | ||
| 195 | combines | ||
| 196 | .Xr BIO_new 3 | ||
| 197 | and | ||
| 198 | .Fn BIO_set_conn_hostname | ||
| 199 | into a single call. | ||
| 200 | It creates a new connect BIO with | ||
| 201 | .Fa name . | ||
| 202 | .Pp | ||
| 203 | .Fn BIO_do_connect | ||
| 204 | attempts to connect the supplied BIO. | ||
| 205 | It returns 1 if the connection was established successfully. | ||
| 206 | A zero or negative value is returned if the connection | ||
| 207 | could not be established. | ||
| 208 | The call | ||
| 209 | .Xr BIO_should_retry 3 | ||
| 210 | should be used for non blocking connect BIOs | ||
| 211 | to determine if the call should be retried. | ||
| 212 | .Sh NOTES | ||
| 213 | If blocking I/O is set then a non positive return value from any | ||
| 214 | I/O call is caused by an error condition, although a zero return | ||
| 215 | will normally mean that the connection was closed. | ||
| 216 | .Pp | ||
| 217 | If the port name is supplied as part of the host name then this will | ||
| 218 | override any value set with | ||
| 219 | .Fn BIO_set_conn_port . | ||
| 220 | This may be undesirable if the application does not wish to allow | ||
| 221 | connection to arbitrary ports. | ||
| 222 | This can be avoided by checking for the presence of the | ||
| 223 | .Sq \&: | ||
| 224 | character in the passed hostname and either indicating an error | ||
| 225 | or truncating the string at that point. | ||
| 226 | .Pp | ||
| 227 | The values returned by | ||
| 228 | .Fn BIO_get_conn_hostname , | ||
| 229 | .Fn BIO_get_conn_port , | ||
| 230 | .Fn BIO_get_conn_ip , | ||
| 231 | and | ||
| 232 | .Fn BIO_get_conn_int_port | ||
| 233 | are updated when a connection attempt is made. | ||
| 234 | Before any connection attempt the values returned | ||
| 235 | are those set by the application itself. | ||
| 236 | .Pp | ||
| 237 | Applications do not have to call | ||
| 238 | .Fn BIO_do_connect | ||
| 239 | but may wish to do so to separate the connection process | ||
| 240 | from other I/O processing. | ||
| 241 | .Pp | ||
| 242 | If non-blocking I/O is set, | ||
| 243 | then retries will be requested as appropriate. | ||
| 244 | .Pp | ||
| 245 | It addition to | ||
| 246 | .Xr BIO_should_read 3 | ||
| 247 | and | ||
| 248 | .Xr BIO_should_write 3 | ||
| 249 | it is also possible for | ||
| 250 | .Xr BIO_should_io_special 3 | ||
| 251 | to be true during the initial connection process with the reason | ||
| 252 | .Dv BIO_RR_CONNECT . | ||
| 253 | If this is returned, it is an indication | ||
| 254 | that a connection attempt would block. | ||
| 255 | The application should then take appropriate action to wait | ||
| 256 | until the underlying socket has connected and retry the call. | ||
| 257 | .Pp | ||
| 258 | .Fn BIO_set_conn_hostname , | ||
| 259 | .Fn BIO_set_conn_port , | ||
| 260 | .Fn BIO_set_conn_ip , | ||
| 261 | .Fn BIO_set_conn_int_port , | ||
| 262 | .Fn BIO_get_conn_hostname , | ||
| 263 | .Fn BIO_get_conn_port , | ||
| 264 | .Fn BIO_get_conn_ip , | ||
| 265 | .Fn BIO_get_conn_int_port , | ||
| 266 | .Fn BIO_set_nbio , | ||
| 267 | and | ||
| 268 | .Fn BIO_do_connect | ||
| 269 | are macros. | ||
| 270 | .Sh RETURN VALUES | ||
| 271 | .Fn BIO_s_connect | ||
| 272 | returns the connect BIO method. | ||
| 273 | .Pp | ||
| 274 | .Xr BIO_get_fd 3 | ||
| 275 | returns the socket or -1 if the BIO has not been initialized. | ||
| 276 | .Pp | ||
| 277 | .Fn BIO_set_conn_hostname , | ||
| 278 | .Fn BIO_set_conn_port , | ||
| 279 | .Fn BIO_set_conn_ip , | ||
| 280 | and | ||
| 281 | .Fn BIO_set_conn_int_port | ||
| 282 | always return 1. | ||
| 283 | .Pp | ||
| 284 | .Fn BIO_get_conn_hostname | ||
| 285 | returns the connected hostname or | ||
| 286 | .Dv NULL | ||
| 287 | if none is set. | ||
| 288 | .Pp | ||
| 289 | .Fn BIO_get_conn_port | ||
| 290 | returns a string representing the connected port or | ||
| 291 | .Dv NULL | ||
| 292 | if not set. | ||
| 293 | .Pp | ||
| 294 | .Fn BIO_get_conn_ip | ||
| 295 | returns a pointer to the connected IP address in binary form | ||
| 296 | or all zeros if not set. | ||
| 297 | .Pp | ||
| 298 | .Fn BIO_get_conn_int_port | ||
| 299 | returns the connected port or 0 if none was set. | ||
| 300 | .Pp | ||
| 301 | .Fn BIO_set_nbio | ||
| 302 | always returns 1. | ||
| 303 | .Pp | ||
| 304 | .Fn BIO_do_connect | ||
| 305 | returns 1 if the connection was successfully | ||
| 306 | established and 0 or -1 if the connection failed. | ||
| 307 | .Sh EXAMPLES | ||
| 308 | This example connects to a webserver on the local host and attempts | ||
| 309 | to retrieve a page and copy the result to standard output. | ||
| 310 | .Bd -literal -offset 2n | ||
| 311 | BIO *cbio, *out; | ||
| 312 | int len; | ||
| 313 | char tmpbuf[1024]; | ||
| 314 | |||
| 315 | ERR_load_crypto_strings(); | ||
| 316 | cbio = BIO_new_connect("localhost:http"); | ||
| 317 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | ||
| 318 | if (BIO_do_connect(cbio) <= 0) { | ||
| 319 | fprintf(stderr, "Error connecting to server\en"); | ||
| 320 | ERR_print_errors_fp(stderr); | ||
| 321 | /* whatever ... */ | ||
| 322 | } | ||
| 323 | BIO_puts(cbio, "GET / HTTP/1.0\en\en"); | ||
| 324 | for(;;) { | ||
| 325 | len = BIO_read(cbio, tmpbuf, 1024); | ||
| 326 | if (len <= 0) | ||
| 327 | break; | ||
| 328 | BIO_write(out, tmpbuf, len); | ||
| 329 | } | ||
| 330 | BIO_free(cbio); | ||
| 331 | BIO_free(out); | ||
| 332 | .Ed | ||
