| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | =pod | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NAME | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 04:38:08 +08:00
										 |  |  | BIO_s_accept, BIO_set_accept_name, BIO_set_accept_port, BIO_get_accept_name, | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_get_accept_port, BIO_new_accept, BIO_set_nbio_accept, BIO_set_accept_bios, | 
					
						
							| 
									
										
										
										
											2018-01-10 03:18:24 +08:00
										 |  |  | BIO_get_peer_name, BIO_get_peer_port, | 
					
						
							|  |  |  | BIO_get_accept_ip_family, BIO_set_accept_ip_family, | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_set_bind_mode, BIO_get_bind_mode, BIO_do_accept - accept BIO | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 SYNOPSIS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #include <openssl/bio.h> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-20 00:32:14 +08:00
										 |  |  |  const BIO_METHOD *BIO_s_accept(void); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  |  long BIO_set_accept_name(BIO *b, char *name); | 
					
						
							|  |  |  |  char *BIO_get_accept_name(BIO *b); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 18:53:02 +08:00
										 |  |  |  long BIO_set_accept_port(BIO *b, char *port); | 
					
						
							| 
									
										
										
										
											2000-10-20 06:02:21 +08:00
										 |  |  |  char *BIO_get_accept_port(BIO *b); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  BIO *BIO_new_accept(char *host_port); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-20 06:02:21 +08:00
										 |  |  |  long BIO_set_nbio_accept(BIO *b, int n); | 
					
						
							|  |  |  |  long BIO_set_accept_bios(BIO *b, char *bio); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-10 03:18:24 +08:00
										 |  |  |  char *BIO_get_peer_name(BIO *b); | 
					
						
							|  |  |  |  char *BIO_get_peer_port(BIO *b); | 
					
						
							|  |  |  |  long BIO_get_accept_ip_family(BIO *b); | 
					
						
							|  |  |  |  long BIO_set_accept_ip_family(BIO *b, long family); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-20 06:02:21 +08:00
										 |  |  |  long BIO_set_bind_mode(BIO *b, long mode); | 
					
						
							| 
									
										
										
										
											2015-11-01 22:47:41 +08:00
										 |  |  |  long BIO_get_bind_mode(BIO *b); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-20 06:02:21 +08:00
										 |  |  |  int BIO_do_accept(BIO *b); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 DESCRIPTION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BIO_s_accept() returns the accept BIO method. This is a wrapper | 
					
						
							|  |  |  | round the platform's TCP/IP socket accept routines. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-20 06:02:21 +08:00
										 |  |  | Using accept BIOs, TCP/IP connections can be accepted and data | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | transferred using only BIO routines. In this way any platform | 
					
						
							|  |  |  | specific operations are hidden by the BIO abstraction. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Read and write operations on an accept BIO will perform I/O | 
					
						
							|  |  |  | on the underlying connection. If no connection is established | 
					
						
							|  |  |  | and the port (see below) is set up properly then the BIO | 
					
						
							|  |  |  | waits for an incoming connection. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Accept BIOs support BIO_puts() but not BIO_gets(). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If the close flag is set on an accept BIO then any active | 
					
						
							|  |  |  | connection on that chain is shutdown and the socket closed when | 
					
						
							|  |  |  | the BIO is freed. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-20 23:51:06 +08:00
										 |  |  | Calling BIO_reset() on an accept BIO will close any active | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | connection and reset the BIO into a state where it awaits another | 
					
						
							|  |  |  | incoming connection. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BIO_get_fd() and BIO_set_fd() can be called to retrieve or set | 
					
						
							| 
									
										
										
										
											2015-08-18 03:21:33 +08:00
										 |  |  | the accept socket. See L<BIO_s_fd(3)> | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_set_accept_name() uses the string B<name> to set the accept | 
					
						
							|  |  |  | name. The name is represented as a string of the form "host:port", | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | where "host" is the interface to use and "port" is the port. | 
					
						
							| 
									
										
										
										
											2016-02-03 06:40:34 +08:00
										 |  |  | The host can be "*" or empty which is interpreted as meaning | 
					
						
							| 
									
										
										
										
											2016-03-20 23:51:06 +08:00
										 |  |  | any interface.  If the host is an IPv6 address, it has to be | 
					
						
							| 
									
										
										
										
											2016-02-03 06:40:34 +08:00
										 |  |  | enclosed in brackets, for example "[::1]:https".  "port" has the | 
					
						
							| 
									
										
										
										
											2016-08-04 18:53:02 +08:00
										 |  |  | same syntax as the port specified in BIO_set_conn_port() for | 
					
						
							| 
									
										
										
										
											2016-02-03 06:40:34 +08:00
										 |  |  | connect BIOs, that is it can be a numerical port string or a | 
					
						
							|  |  |  | string to lookup using getservbyname() and a string table. | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 18:53:02 +08:00
										 |  |  | BIO_set_accept_port() uses the string B<port> to set the accept | 
					
						
							|  |  |  | port.  "port" has the same syntax as the port specified in | 
					
						
							|  |  |  | BIO_set_conn_port() for connect BIOs, that is it can be a numerical | 
					
						
							|  |  |  | port string or a string to lookup using getservbyname() and a string | 
					
						
							|  |  |  | table. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_new_accept() combines BIO_new() and BIO_set_accept_name() into | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | a single call: that is it creates a new accept BIO with port | 
					
						
							|  |  |  | B<host_port>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BIO_set_nbio_accept() sets the accept socket to blocking mode | 
					
						
							|  |  |  | (the default) if B<n> is 0 or non blocking mode if B<n> is 1. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BIO_set_accept_bios() can be used to set a chain of BIOs which | 
					
						
							|  |  |  | will be duplicated and prepended to the chain when an incoming | 
					
						
							| 
									
										
										
										
											2016-05-20 20:11:46 +08:00
										 |  |  | connection is received. This is useful if, for example, a | 
					
						
							| 
									
										
										
										
											2000-09-17 05:21:01 +08:00
										 |  |  | buffering or SSL BIO is required for each connection. The | 
					
						
							|  |  |  | chain of BIOs must not be freed after this call, they will | 
					
						
							|  |  |  | be automatically freed when the accept BIO is freed. | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | BIO_set_bind_mode() and BIO_get_bind_mode() set and retrieve | 
					
						
							| 
									
										
										
										
											2016-07-09 00:55:45 +08:00
										 |  |  | the current bind mode. If B<BIO_BIND_NORMAL> (the default) is set | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | then another socket cannot be bound to the same port. If | 
					
						
							| 
									
										
										
										
											2016-07-09 00:55:45 +08:00
										 |  |  | B<BIO_BIND_REUSEADDR> is set then other sockets can bind to the | 
					
						
							|  |  |  | same port. If B<BIO_BIND_REUSEADDR_IF_UNUSED> is set then and | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | attempt is first made to use BIO_BIN_NORMAL, if this fails | 
					
						
							|  |  |  | and the port is not in use then a second attempt is made | 
					
						
							| 
									
										
										
										
											2016-07-09 00:55:45 +08:00
										 |  |  | using B<BIO_BIND_REUSEADDR>. | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | BIO_do_accept() serves two functions. When it is first | 
					
						
							|  |  |  | called, after the accept BIO has been setup, it will attempt | 
					
						
							|  |  |  | to create the accept socket and bind an address to it. Second | 
					
						
							|  |  |  | and subsequent calls to BIO_do_accept() will await an incoming | 
					
						
							| 
									
										
										
										
											2000-10-12 09:50:33 +08:00
										 |  |  | connection, or request a retry in non blocking mode. | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 NOTES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | When an accept BIO is at the end of a chain it will await an | 
					
						
							|  |  |  | incoming connection before processing I/O calls. When an accept | 
					
						
							|  |  |  | BIO is not at then end of a chain it passes I/O calls to the next | 
					
						
							|  |  |  | BIO in the chain. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | When a connection is established a new socket BIO is created for | 
					
						
							| 
									
										
										
										
											2000-09-16 23:39:28 +08:00
										 |  |  | the connection and appended to the chain. That is the chain is now | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | accept->socket. This effectively means that attempting I/O on | 
					
						
							|  |  |  | an initial accept socket will await an incoming connection then | 
					
						
							|  |  |  | perform I/O on it. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If any additional BIOs have been set using BIO_set_accept_bios() | 
					
						
							|  |  |  | then they are placed between the socket and the accept BIO, | 
					
						
							|  |  |  | that is the chain will be accept->otherbios->socket. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If a server wishes to process multiple connections (as is normally | 
					
						
							|  |  |  | the case) then the accept BIO must be made available for further | 
					
						
							|  |  |  | incoming connections. This can be done by waiting for a connection and | 
					
						
							|  |  |  | then calling: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  connection = BIO_pop(accept); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | After this call B<connection> will contain a BIO for the recently | 
					
						
							|  |  |  | established connection and B<accept> will now be a single BIO | 
					
						
							|  |  |  | again which can be used to await further incoming connections. | 
					
						
							|  |  |  | If no further connections will be accepted the B<accept> can | 
					
						
							|  |  |  | be freed using BIO_free(). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If only a single connection will be processed it is possible to | 
					
						
							|  |  |  | perform I/O using the accept BIO itself. This is often undesirable | 
					
						
							|  |  |  | however because the accept BIO will still accept additional incoming | 
					
						
							|  |  |  | connections. This can be resolved by using BIO_pop() (see above) | 
					
						
							|  |  |  | and freeing up the accept BIO after the initial connection. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 18:31:26 +08:00
										 |  |  | If the underlying accept socket is nonblocking and BIO_do_accept() is | 
					
						
							| 
									
										
										
										
											2000-10-12 09:50:33 +08:00
										 |  |  | called to await an incoming connection it is possible for | 
					
						
							|  |  |  | BIO_should_io_special() with the reason BIO_RR_ACCEPT. If this happens | 
					
						
							|  |  |  | then it is an indication that an accept attempt would block: the application | 
					
						
							|  |  |  | should take appropriate action to wait until the underlying socket has | 
					
						
							|  |  |  | accepted a connection and retry the call. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_set_accept_name(), BIO_get_accept_name(), BIO_set_accept_port(), | 
					
						
							|  |  |  | BIO_get_accept_port(), BIO_set_nbio_accept(), BIO_set_accept_bios(), | 
					
						
							| 
									
										
										
										
											2018-01-10 03:18:24 +08:00
										 |  |  | BIO_get_peer_name(), BIO_get_peer_port(), | 
					
						
							|  |  |  | BIO_get_accept_ip_family(), BIO_set_accept_ip_family(), | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_set_bind_mode(), BIO_get_bind_mode() and BIO_do_accept() are macros. | 
					
						
							| 
									
										
										
										
											2000-10-20 06:02:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | =head1 RETURN VALUES | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 00:28:08 +08:00
										 |  |  | BIO_do_accept(), | 
					
						
							| 
									
										
										
										
											2016-08-03 23:31:46 +08:00
										 |  |  | BIO_set_accept_name(), BIO_set_accept_port(), BIO_set_nbio_accept(), | 
					
						
							| 
									
										
										
										
											2018-01-10 03:18:24 +08:00
										 |  |  | BIO_set_accept_bios(), BIO_set_accept_ip_family(), and BIO_set_bind_mode() | 
					
						
							|  |  |  | return 1 for success and 0 or -1 for failure. | 
					
						
							| 
									
										
										
										
											2015-08-28 00:28:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 05:04:32 +08:00
										 |  |  | BIO_get_accept_name() returns the accept name or NULL on error. | 
					
						
							| 
									
										
										
										
											2018-01-10 03:18:24 +08:00
										 |  |  | BIO_get_peer_name() returns the peer name or NULL on error. | 
					
						
							| 
									
										
										
										
											2016-08-04 18:53:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-10 03:18:24 +08:00
										 |  |  | BIO_get_accept_port() returns the accept port as a string or NULL on error. | 
					
						
							|  |  |  | BIO_get_peer_port() returns the peer port as a string or NULL on error. | 
					
						
							|  |  |  | BIO_get_accept_ip_family() returns the IP family or -1 on error. | 
					
						
							| 
									
										
										
										
											2015-08-28 00:28:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | BIO_get_bind_mode() returns the set of B<BIO_BIND> flags, or -1 on failure. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BIO_new_accept() returns a BIO or NULL on error. | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-16 02:26:08 +08:00
										 |  |  | =head1 EXAMPLES | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | This example accepts two connections on port 4444, sends messages | 
					
						
							|  |  |  | down each and finally closes both down. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  BIO *abio, *cbio, *cbio2; | 
					
						
							| 
									
										
										
										
											2016-02-10 00:52:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  /* First call to BIO_accept() sets up accept BIO */ | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  |  abio = BIO_new_accept("4444"); | 
					
						
							|  |  |  |  if (BIO_do_accept(abio) <= 0) { | 
					
						
							|  |  |  |      fprintf(stderr, "Error setting up accept\n"); | 
					
						
							|  |  |  |      ERR_print_errors_fp(stderr); | 
					
						
							|  |  |  |      exit(1); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  /* Wait for incoming connection */ | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  |  if (BIO_do_accept(abio) <= 0) { | 
					
						
							|  |  |  |      fprintf(stderr, "Error accepting connection\n"); | 
					
						
							|  |  |  |      ERR_print_errors_fp(stderr); | 
					
						
							|  |  |  |      exit(1); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  } | 
					
						
							|  |  |  |  fprintf(stderr, "Connection 1 established\n"); | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  /* Retrieve BIO for connection */ | 
					
						
							|  |  |  |  cbio = BIO_pop(abio); | 
					
						
							|  |  |  |  BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n"); | 
					
						
							|  |  |  |  fprintf(stderr, "Sent out data on connection 1\n"); | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  /* Wait for another connection */ | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  |  if (BIO_do_accept(abio) <= 0) { | 
					
						
							|  |  |  |      fprintf(stderr, "Error accepting connection\n"); | 
					
						
							|  |  |  |      ERR_print_errors_fp(stderr); | 
					
						
							|  |  |  |      exit(1); | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  } | 
					
						
							|  |  |  |  fprintf(stderr, "Connection 2 established\n"); | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  /* Close accept BIO to refuse further connections */ | 
					
						
							|  |  |  |  cbio2 = BIO_pop(abio); | 
					
						
							|  |  |  |  BIO_free(abio); | 
					
						
							|  |  |  |  BIO_puts(cbio2, "Connection 2: Sending out Data on second\n"); | 
					
						
							|  |  |  |  fprintf(stderr, "Sent out data on connection 2\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  BIO_puts(cbio, "Connection 1: Second connection established\n"); | 
					
						
							| 
									
										
										
										
											2016-05-21 08:52:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 01:31:47 +08:00
										 |  |  |  /* Close the two established connections */ | 
					
						
							|  |  |  |  BIO_free(cbio); | 
					
						
							|  |  |  |  BIO_free(cbio2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-18 23:44:05 +08:00
										 |  |  | =head1 COPYRIGHT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-06 20:22:30 +08:00
										 |  |  | Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-05-18 23:44:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-06 21:04:44 +08:00
										 |  |  | Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 23:44:05 +08:00
										 |  |  | this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  | in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  | L<https://www.openssl.org/source/license.html>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =cut |