5
BIO_s_connect, BIO_new_connect, BIO_set_conn_hostname, BIO_set_conn_port,
6
BIO_set_conn_ip, BIO_set_conn_int_port, BIO_get_conn_hostname,
7
BIO_get_conn_port, BIO_get_conn_ip, BIO_get_conn_int_port,
8
BIO_set_nbio, BIO_do_connect - connect BIO
12
#include <openssl/bio.h>
14
BIO_METHOD * BIO_s_connect(void);
16
BIO *BIO_new_connect(char *name);
18
long BIO_set_conn_hostname(BIO *b, char *name);
19
long BIO_set_conn_port(BIO *b, char *port);
20
long BIO_set_conn_ip(BIO *b, char *ip);
21
long BIO_set_conn_int_port(BIO *b, char *port);
22
char *BIO_get_conn_hostname(BIO *b);
23
char *BIO_get_conn_port(BIO *b);
24
char *BIO_get_conn_ip(BIO *b, dummy);
25
long BIO_get_conn_int_port(BIO *b, int port);
27
long BIO_set_nbio(BIO *b, long n);
29
int BIO_do_connect(BIO *b);
33
BIO_s_connect() returns the connect BIO method. This is a wrapper
34
round the platform's TCP/IP socket connection routines.
36
Using connect BIOs, TCP/IP connections can be made and data
37
transferred using only BIO routines. In this way any platform
38
specific operations are hidden by the BIO abstraction.
40
Read and write operations on a connect BIO will perform I/O
41
on the underlying connection. If no connection is established
42
and the port and hostname (see below) is set up properly then
43
a connection is established first.
45
Connect BIOs support BIO_puts() but not BIO_gets().
47
If the close flag is set on a connect BIO then any active
48
connection is shutdown and the socket closed when the BIO
51
Calling BIO_reset() on a connect BIO will close any active
52
connection and reset the BIO into a state where it can connect
53
to the same host again.
55
BIO_get_fd() places the underlying socket in B<c> if it is not NULL,
56
it also returns the socket . If B<c> is not NULL it should be of
59
BIO_set_conn_hostname() uses the string B<name> to set the hostname.
60
The hostname can be an IP address. The hostname can also include the
61
port in the form hostname:port . It is also acceptable to use the
62
form "hostname/any/other/path" or "hostname:port/any/other/path".
64
BIO_set_conn_port() sets the port to B<port>. B<port> can be the
65
numerical form or a string such as "http". A string will be looked
66
up first using getservbyname() on the host platform but if that
67
fails a standard table of port names will be used. Currently the
68
list is http, telnet, socks, https, ssl, ftp, gopher and wais.
70
BIO_set_conn_ip() sets the IP address to B<ip> using binary form,
71
that is four bytes specifying the IP address in big-endian form.
73
BIO_set_conn_int_port() sets the port using B<port>. B<port> should
76
BIO_get_conn_hostname() returns the hostname of the connect BIO or
77
NULL if the BIO is initialized but no hostname is set.
78
This return value is an internal pointer which should not be modified.
80
BIO_get_conn_port() returns the port as a string.
82
BIO_get_conn_ip() returns the IP address in binary form.
84
BIO_get_conn_int_port() returns the port as an int.
86
BIO_set_nbio() sets the non blocking I/O flag to B<n>. If B<n> is
87
zero then blocking I/O is set. If B<n> is 1 then non blocking I/O
88
is set. Blocking I/O is the default. The call to BIO_set_nbio()
89
should be made before the connection is established because
90
non blocking I/O is set during the connect process.
92
BIO_new_connect() combines BIO_new() and BIO_set_conn_hostname() into
93
a single call: that is it creates a new connect BIO with B<name>.
95
BIO_do_connect() attempts to connect the supplied BIO. It returns 1
96
if the connection was established successfully. A zero or negative
97
value is returned if the connection could not be established, the
98
call BIO_should_retry() should be used for non blocking connect BIOs
99
to determine if the call should be retried.
103
If blocking I/O is set then a non positive return value from any
104
I/O call is caused by an error condition, although a zero return
105
will normally mean that the connection was closed.
107
If the port name is supplied as part of the host name then this will
108
override any value set with BIO_set_conn_port(). This may be undesirable
109
if the application does not wish to allow connection to arbitrary
110
ports. This can be avoided by checking for the presence of the ':'
111
character in the passed hostname and either indicating an error or
112
truncating the string at that point.
114
The values returned by BIO_get_conn_hostname(), BIO_get_conn_port(),
115
BIO_get_conn_ip() and BIO_get_conn_int_port() are updated when a
116
connection attempt is made. Before any connection attempt the values
117
returned are those set by the application itself.
119
Applications do not have to call BIO_do_connect() but may wish to do
120
so to separate the connection process from other I/O processing.
122
If non blocking I/O is set then retries will be requested as appropriate.
124
It addition to BIO_should_read() and BIO_should_write() it is also
125
possible for BIO_should_io_special() to be true during the initial
126
connection process with the reason BIO_RR_CONNECT. If this is returned
127
then this is an indication that a connection attempt would block,
128
the application should then take appropriate action to wait until
129
the underlying socket has connected and retry the call.
131
BIO_set_conn_hostname(), BIO_set_conn_port(), BIO_set_conn_ip(),
132
BIO_set_conn_int_port(), BIO_get_conn_hostname(), BIO_get_conn_port(),
133
BIO_get_conn_ip(), BIO_get_conn_int_port(), BIO_set_nbio() and
134
BIO_do_connect() are macros.
138
BIO_s_connect() returns the connect BIO method.
140
BIO_get_fd() returns the socket or -1 if the BIO has not
143
BIO_set_conn_hostname(), BIO_set_conn_port(), BIO_set_conn_ip() and
144
BIO_set_conn_int_port() always return 1.
146
BIO_get_conn_hostname() returns the connected hostname or NULL is
149
BIO_get_conn_port() returns a string representing the connected
150
port or NULL if not set.
152
BIO_get_conn_ip() returns a pointer to the connected IP address in
153
binary form or all zeros if not set.
155
BIO_get_conn_int_port() returns the connected port or 0 if none was
158
BIO_set_nbio() always returns 1.
160
BIO_do_connect() returns 1 if the connection was successfully
161
established and 0 or -1 if the connection failed.
165
This is example connects to a webserver on the local host and attempts
166
to retrieve a page and copy the result to standard output.
172
ERR_load_crypto_strings();
173
cbio = BIO_new_connect("localhost:http");
174
out = BIO_new_fp(stdout, BIO_NOCLOSE);
175
if(BIO_do_connect(cbio) <= 0) {
176
fprintf(stderr, "Error connecting to server\n");
177
ERR_print_errors_fp(stderr);
180
BIO_puts(cbio, "GET / HTTP/1.0\n\n");
182
len = BIO_read(cbio, tmpbuf, 1024);
184
BIO_write(out, tmpbuf, len);