BIO_connect.pod 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. =pod
  2. =head1 NAME
  3. BIO_socket, BIO_bind, BIO_connect, BIO_listen, BIO_accept_ex, BIO_closesocket - BIO
  4. socket communication setup routines
  5. =head1 SYNOPSIS
  6. #include <openssl/bio.h>
  7. int BIO_socket(int domain, int socktype, int protocol, int options);
  8. int BIO_bind(int sock, const BIO_ADDR *addr, int options);
  9. int BIO_connect(int sock, const BIO_ADDR *addr, int options);
  10. int BIO_listen(int sock, const BIO_ADDR *addr, int options);
  11. int BIO_accept_ex(int accept_sock, BIO_ADDR *peer, int options);
  12. int BIO_closesocket(int sock);
  13. =head1 DESCRIPTION
  14. BIO_socket() creates a socket in the domain B<domain>, of type
  15. B<socktype> and B<protocol>. Socket B<options> are currently unused,
  16. but is present for future use.
  17. BIO_bind() binds the source address and service to a socket and
  18. may be useful before calling BIO_connect(). The options may include
  19. B<BIO_SOCK_REUSEADDR>, which is described in L</FLAGS> below.
  20. BIO_connect() connects B<sock> to the address and service given by
  21. B<addr>. Connection B<options> may be zero or any combination of
  22. B<BIO_SOCK_KEEPALIVE>, B<BIO_SOCK_NONBLOCK> and B<BIO_SOCK_NODELAY>.
  23. The flags are described in L</FLAGS> below.
  24. BIO_listen() has B<sock> start listening on the address and service
  25. given by B<addr>. Connection B<options> may be zero or any
  26. combination of B<BIO_SOCK_KEEPALIVE>, B<BIO_SOCK_NONBLOCK>,
  27. B<BIO_SOCK_NODELAY>, B<BIO_SOCK_REUSEADDR> and B<BIO_SOCK_V6_ONLY>.
  28. The flags are described in L</FLAGS> below.
  29. BIO_accept_ex() waits for an incoming connections on the given
  30. socket B<accept_sock>. When it gets a connection, the address and
  31. port of the peer gets stored in B<peer> if that one is non-NULL.
  32. Accept B<options> may be zero or B<BIO_SOCK_NONBLOCK>, and is applied
  33. on the accepted socket. The flags are described in L</FLAGS> below.
  34. BIO_closesocket() closes B<sock>.
  35. =head1 FLAGS
  36. =over 4
  37. =item BIO_SOCK_KEEPALIVE
  38. Enables regular sending of keep-alive messages.
  39. =item BIO_SOCK_NONBLOCK
  40. Sets the socket to nonblocking mode.
  41. =item BIO_SOCK_NODELAY
  42. Corresponds to B<TCP_NODELAY>, and disables the Nagle algorithm. With
  43. this set, any data will be sent as soon as possible instead of being
  44. buffered until there's enough for the socket to send out in one go.
  45. =item BIO_SOCK_REUSEADDR
  46. Try to reuse the address and port combination for a recently closed
  47. port.
  48. =item BIO_SOCK_V6_ONLY
  49. When creating an IPv6 socket, make it only listen for IPv6 addresses
  50. and not IPv4 addresses mapped to IPv6.
  51. =item BIO_SOCK_TFO
  52. Enables TCP Fast Open on the socket. Uses appropriate APIs on
  53. supported operating systems, including Linux, macOS and FreeBSD. Can
  54. be used with BIO_connect(), BIO_set_conn_mode(), BIO_set_bind_mode(),
  55. and BIO_listen().
  56. On Linux kernels before 4.14, use BIO_set_conn_address() to specify
  57. the peer address before starting the TLS handshake.
  58. =back
  59. These flags are bit flags, so they are to be combined with the
  60. C<|> operator, for example:
  61. BIO_connect(sock, addr, BIO_SOCK_KEEPALIVE | BIO_SOCK_NONBLOCK);
  62. =head1 RETURN VALUES
  63. BIO_socket() returns the socket number on success or B<INVALID_SOCKET>
  64. (-1) on error. When an error has occurred, the OpenSSL error stack
  65. will hold the error data and errno has the system error.
  66. BIO_bind(), BIO_connect() and BIO_listen() return 1 on success or 0 on error.
  67. When an error has occurred, the OpenSSL error stack will hold the error
  68. data and errno has the system error.
  69. BIO_accept_ex() returns the accepted socket on success or
  70. B<INVALID_SOCKET> (-1) on error. When an error has occurred, the
  71. OpenSSL error stack will hold the error data and errno has the system
  72. error.
  73. =head1 SEE ALSO
  74. L<BIO_ADDR(3)>
  75. =head1 HISTORY
  76. BIO_gethostname(), BIO_get_port(), BIO_get_host_ip(),
  77. BIO_get_accept_socket() and BIO_accept() were deprecated in OpenSSL 1.1.0.
  78. Use the functions described above instead.
  79. =head1 COPYRIGHT
  80. Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
  81. Licensed under the Apache License 2.0 (the "License"). You may not use
  82. this file except in compliance with the License. You can obtain a copy
  83. in the file LICENSE in the source distribution or at
  84. L<https://www.openssl.org/source/license.html>.
  85. =cut