xref: /freebsd/crypto/openssl/doc/man3/BIO_connect.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimBIO_socket, BIO_bind, BIO_connect, BIO_listen, BIO_accept_ex, BIO_closesocket - BIO
6e71b7053SJung-uk Kimsocket communication setup routines
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 SYNOPSIS
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim #include <openssl/bio.h>
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim int BIO_socket(int domain, int socktype, int protocol, int options);
13e71b7053SJung-uk Kim int BIO_bind(int sock, const BIO_ADDR *addr, int options);
14e71b7053SJung-uk Kim int BIO_connect(int sock, const BIO_ADDR *addr, int options);
15e71b7053SJung-uk Kim int BIO_listen(int sock, const BIO_ADDR *addr, int options);
16e71b7053SJung-uk Kim int BIO_accept_ex(int accept_sock, BIO_ADDR *peer, int options);
17e71b7053SJung-uk Kim int BIO_closesocket(int sock);
18e71b7053SJung-uk Kim
19e71b7053SJung-uk Kim=head1 DESCRIPTION
20e71b7053SJung-uk Kim
21e71b7053SJung-uk KimBIO_socket() creates a socket in the domain B<domain>, of type
22e71b7053SJung-uk KimB<socktype> and B<protocol>.  Socket B<options> are currently unused,
23e71b7053SJung-uk Kimbut is present for future use.
24e71b7053SJung-uk Kim
25e71b7053SJung-uk KimBIO_bind() binds the source address and service to a socket and
26e71b7053SJung-uk Kimmay be useful before calling BIO_connect().  The options may include
27da327cd2SJung-uk KimB<BIO_SOCK_REUSEADDR>, which is described in L</FLAGS> below.
28e71b7053SJung-uk Kim
29e71b7053SJung-uk KimBIO_connect() connects B<sock> to the address and service given by
30e71b7053SJung-uk KimB<addr>.  Connection B<options> may be zero or any combination of
31e71b7053SJung-uk KimB<BIO_SOCK_KEEPALIVE>, B<BIO_SOCK_NONBLOCK> and B<BIO_SOCK_NODELAY>.
32e71b7053SJung-uk KimThe flags are described in L</FLAGS> below.
33e71b7053SJung-uk Kim
34e71b7053SJung-uk KimBIO_listen() has B<sock> start listening on the address and service
35e71b7053SJung-uk Kimgiven by B<addr>.  Connection B<options> may be zero or any
36e71b7053SJung-uk Kimcombination of B<BIO_SOCK_KEEPALIVE>, B<BIO_SOCK_NONBLOCK>,
37e71b7053SJung-uk KimB<BIO_SOCK_NODELAY>, B<BIO_SOCK_REUSEADDR> and B<BIO_SOCK_V6_ONLY>.
38e71b7053SJung-uk KimThe flags are described in L</FLAGS> below.
39e71b7053SJung-uk Kim
40e71b7053SJung-uk KimBIO_accept_ex() waits for an incoming connections on the given
41e71b7053SJung-uk Kimsocket B<accept_sock>.  When it gets a connection, the address and
42e71b7053SJung-uk Kimport of the peer gets stored in B<peer> if that one is non-NULL.
43e71b7053SJung-uk KimAccept B<options> may be zero or B<BIO_SOCK_NONBLOCK>, and is applied
44e71b7053SJung-uk Kimon the accepted socket.  The flags are described in L</FLAGS> below.
45e71b7053SJung-uk Kim
46e71b7053SJung-uk KimBIO_closesocket() closes B<sock>.
47e71b7053SJung-uk Kim
48e71b7053SJung-uk Kim=head1 FLAGS
49e71b7053SJung-uk Kim
50e71b7053SJung-uk Kim=over 4
51e71b7053SJung-uk Kim
52e71b7053SJung-uk Kim=item BIO_SOCK_KEEPALIVE
53e71b7053SJung-uk Kim
54e71b7053SJung-uk KimEnables regular sending of keep-alive messages.
55e71b7053SJung-uk Kim
56e71b7053SJung-uk Kim=item BIO_SOCK_NONBLOCK
57e71b7053SJung-uk Kim
5858f35182SJung-uk KimSets the socket to nonblocking mode.
59e71b7053SJung-uk Kim
60e71b7053SJung-uk Kim=item BIO_SOCK_NODELAY
61e71b7053SJung-uk Kim
62e71b7053SJung-uk KimCorresponds to B<TCP_NODELAY>, and disables the Nagle algorithm.  With
63e71b7053SJung-uk Kimthis set, any data will be sent as soon as possible instead of being
64e71b7053SJung-uk Kimbuffered until there's enough for the socket to send out in one go.
65e71b7053SJung-uk Kim
66e71b7053SJung-uk Kim=item BIO_SOCK_REUSEADDR
67e71b7053SJung-uk Kim
68e71b7053SJung-uk KimTry to reuse the address and port combination for a recently closed
69e71b7053SJung-uk Kimport.
70e71b7053SJung-uk Kim
71e71b7053SJung-uk Kim=item BIO_SOCK_V6_ONLY
72e71b7053SJung-uk Kim
73e71b7053SJung-uk KimWhen creating an IPv6 socket, make it only listen for IPv6 addresses
74e71b7053SJung-uk Kimand not IPv4 addresses mapped to IPv6.
75e71b7053SJung-uk Kim
76e71b7053SJung-uk Kim=back
77e71b7053SJung-uk Kim
78e71b7053SJung-uk KimThese flags are bit flags, so they are to be combined with the
79e71b7053SJung-uk KimC<|> operator, for example:
80e71b7053SJung-uk Kim
81e71b7053SJung-uk Kim BIO_connect(sock, addr, BIO_SOCK_KEEPALIVE | BIO_SOCK_NONBLOCK);
82e71b7053SJung-uk Kim
83e71b7053SJung-uk Kim=head1 RETURN VALUES
84e71b7053SJung-uk Kim
85e71b7053SJung-uk KimBIO_socket() returns the socket number on success or B<INVALID_SOCKET>
86e71b7053SJung-uk Kim(-1) on error.  When an error has occurred, the OpenSSL error stack
87e71b7053SJung-uk Kimwill hold the error data and errno has the system error.
88e71b7053SJung-uk Kim
89e71b7053SJung-uk KimBIO_bind(), BIO_connect() and BIO_listen() return 1 on success or 0 on error.
90e71b7053SJung-uk KimWhen an error has occurred, the OpenSSL error stack will hold the error
91e71b7053SJung-uk Kimdata and errno has the system error.
92e71b7053SJung-uk Kim
93e71b7053SJung-uk KimBIO_accept_ex() returns the accepted socket on success or
94e71b7053SJung-uk KimB<INVALID_SOCKET> (-1) on error.  When an error has occurred, the
95e71b7053SJung-uk KimOpenSSL error stack will hold the error data and errno has the system
96e71b7053SJung-uk Kimerror.
97e71b7053SJung-uk Kim
98e71b7053SJung-uk Kim=head1 SEE ALSO
99e71b7053SJung-uk Kim
100e71b7053SJung-uk KimL<BIO_ADDR(3)>
101e71b7053SJung-uk Kim
102610a21fdSJung-uk Kim=head1 HISTORY
103610a21fdSJung-uk Kim
104610a21fdSJung-uk KimBIO_gethostname(), BIO_get_port(), BIO_get_host_ip(),
105610a21fdSJung-uk KimBIO_get_accept_socket() and BIO_accept() were deprecated in OpenSSL 1.1.0.
106610a21fdSJung-uk KimUse the functions described above instead.
107610a21fdSJung-uk Kim
108e71b7053SJung-uk Kim=head1 COPYRIGHT
109e71b7053SJung-uk Kim
11058f35182SJung-uk KimCopyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
111e71b7053SJung-uk Kim
112*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
113e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
114e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
115e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
116e71b7053SJung-uk Kim
117e71b7053SJung-uk Kim=cut
118