---
name: "libressl-BIO_accept"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BIO_accept"
---

# libressl-BIO\_accept(3)

wrappers for socket operations

## NAME

**BIO\_get\_host\_ip**, **BIO\_get\_port**, **BIO\_get\_accept\_socket**, **BIO\_accept**, **BIO\_sock\_error**, **BIO\_sock\_non\_fatal\_error**, **BIO\_sock\_should\_retry**, **BIO\_socket\_nbio**, **BIO\_set\_tcp\_ndelay** – wrappers for socket operations

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bio.h\>**

*int*\

**BIO\_get\_host\_ip**(*const char \*hostname*, *unsigned char \*in\_addr\_buffer*);

*int*\

**BIO\_get\_port**(*const char \*servname*, *unsigned short \*port*);

*int*\

**BIO\_get\_accept\_socket**(*char \*host\_port*, *int bind\_mode*);

*int*\

**BIO\_accept**(*int socket*, *char \*\*addr*);

*int*\

**BIO\_sock\_error**(*int socket*);

*int*\

**BIO\_sock\_non\_fatal\_error**(*int errnum*);

*int*\

**BIO\_sock\_should\_retry**(*int retval*);

*int*\

**BIO\_socket\_nbio**(*int socket*, *int mode*);

*int*\

**BIO\_set\_tcp\_ndelay**(*int socket*, *int on*);

## DESCRIPTION

**BIO\_get\_host\_ip**() looks up one IPv4 address for the given *hostname* using [getaddrinfo(3)](/getaddrinfo/3.md) and writes the first returned IPv4 address into \**in\_addr\_buffer*. The caller is responsible for providing a buffer that is at least **sizeof**(*in\_addr\_t*) bytes long. After a successful call, the caller needs to cast *in\_addr\_buffer* to (*in\_addr\_t* *\**).

**BIO\_get\_port**() looks up *servname* in the [services(5)](/services/5.md) database using [getaddrinfo(3)](/getaddrinfo/3.md) and stores the associated port number at the location specified by the *port* argument.

**BIO\_get\_accept\_socket**() creates an IPv4 TCP socket and [listen(2)](/listen/2.md)s for incoming connections. The string *host\_port* is parsed. If it contains a colon, the substring before the colon is interpreted as a local hostname of the interface to [bind(2)](/bind/2.md) to. If the hostname is empty, consists of a single asterisk ("\*:..."), or if there is no colon, INADDR\_ANY is used instead of a local hostname. The rest of the string *host\_port*, or the whole string if it contains no colon, is treated as a service name. The hostname and the service name are converted to a local IP address and port number using [getaddrinfo(3)](/getaddrinfo/3.md). If *bind\_mode* is the constant BIO\_BIND\_REUSEADDR, allowing local address reuse is attempted using [setsockopt(2)](/setsockopt/2.md) with an argument of SO\_REUSEADDR before calling [bind(2)](/bind/2.md).

**BIO\_accept**() calls [accept(2)](/accept/2.md) to receive one connection on the *socket*. When it receives a connection, it [free(3)](/free/3.md)s \**addr*, and if it is an IPv4 connection, it allocates a new string, writes the peer IP address in dotted decimal form, a colon, and the decimal port number into the string, and stores a pointer to the string in \**addr*. For other address families or if [getnameinfo(3)](/getnameinfo/3.md) or memory allocation fails, \**addr* is set to NULL but **BIO\_accept**() succeeds anyway.

**BIO\_sock\_error**() retrieves, clears, and returns the error status code of the *socket* by calling [getsockopt(2)](/getsockopt/2.md) with arguments SOL\_SOCKET and SO\_ERROR.

**BIO\_sock\_non\_fatal\_error**() determines whether the error status code *errnum* represents a recoverable error.

**BIO\_sock\_should\_retry**() determines whether a recoverable error occurred by inspecting both [errno(2)](/errno/2.md) and *retval*, which is supposed to usually be the return value of a previously called function like **BIO\_accept**(), BIO\_read(3), or BIO\_write(3).

If *mode* is non-zero, **BIO\_socket\_nbio**() switches the *socket* to non-blocking mode using [fcntl(2)](/fcntl/2.md). If *mode* is 0, it switches to blocking mode.

**BIO\_set\_tcp\_ndelay**() sets the TCP\_NODELAY option on the *socket* if *on* is 1 or clears it if *on* is 0; see [tcp(4)](/tcp/4.md) for details.

## RETURN VALUES

**BIO\_get\_host\_ip**(), **BIO\_get\_port**(), and **BIO\_socket\_nbio**() return 1 on success or 0 on failure.

**BIO\_get\_accept\_socket**() returns the file descriptor of the newly created listening socket or -1 if *host\_port* is NULL, no service is specified, or [getaddrinfo(3)](/getaddrinfo/3.md), [socket(2)](/socket/2.md), [bind(2)](/bind/2.md), [listen(2)](/listen/2.md), or memory allocation fails.

**BIO\_accept**() returns the file descriptor of the received connection, -1 on fatal errors, that is, when *addr* is NULL or [accept(2)](/accept/2.md) fails fatally, or -2 when [accept(2)](/accept/2.md) fails in a non-fatal way and might succeed when retried later.

**BIO\_sock\_error**() returns an error status code like EAGAIN, ECONNABORTED, ECONNREFUSED, ECONNRESET, ELOOP, EMSGSIZE, ENOBUFS, ENOTCONN, EPIPE, ETIMEDOUT, or others, 0 if the *socket* is not in an error state, or 1 if [getsockopt(2)](/getsockopt/2.md) fails.

**BIO\_sock\_non\_fatal\_error**() returns 1 if *errnum* is EAGAIN, EALREADY, EINPROGRESS, EINTR, or ENOTCONN and 0 otherwise, even if *errnum* is 0.

**BIO\_sock\_should\_retry**() returns 1 if **BIO\_sock\_non\_fatal\_error**(*errno*) is 1 and *retval* is either 0 or -1, or 0 otherwise.

**BIO\_set\_tcp\_ndelay**() returns 0 on success or -1 on failure.

## ERRORS

If **BIO\_get\_host\_ip**(), **BIO\_get\_port**(), or **BIO\_get\_accept\_socket**() fail or **BIO\_accept**() fails fatally, the following diagnostics can be retrieved with ERR\_get\_error(3), ERR\_GET\_REASON(3), and ERR\_reason\_error\_string(3):

- BIO\_R\_ACCEPT\_ERROR "accept error"

  [accept(2)](/accept/2.md) failed fatally in **BIO\_accept**().

- BIO\_R\_BAD\_HOSTNAME\_LOOKUP "bad hostname lookup"

  [getaddrinfo(3)](/getaddrinfo/3.md) failed or *hostname* was NULL in **BIO\_get\_host\_ip**(), or [getaddrinfo(3)](/getaddrinfo/3.md) failed in **BIO\_get\_accept\_socket**().

- BIO\_R\_INVALID\_ARGUMENT "invalid argument"

  [getaddrinfo(3)](/getaddrinfo/3.md) failed in **BIO\_get\_port**().

- ERR\_R\_MALLOC\_FAILURE "malloc failure"

  Memory allocation failed in **BIO\_get\_accept\_socket**(), or **BIO\_accept**() *succeeded* but was unable to allocate memory for \**addr*. For **BIO\_accept**(), the returned file descriptor is valid, and communication with the peer can be attempted using it.

- BIO\_R\_NO\_PORT\_SPECIFIED "no port specified"

  The *servname* argument was NULL in **BIO\_get\_port**(), or *host\_port* was NULL or ended after the first colon in **BIO\_get\_accept\_socket**().

- BIO\_R\_NULL\_PARAMETER "null parameter"

  The *addr* argument was NULL in **BIO\_accept**().

- BIO\_R\_UNABLE\_TO\_BIND\_SOCKET "unable to bind socket"

  [bind(2)](/bind/2.md) failed in **BIO\_get\_accept\_socket**().

- BIO\_R\_UNABLE\_TO\_CREATE\_SOCKET "unable to create socket"

  [socket(2)](/socket/2.md) failed in **BIO\_get\_accept\_socket**().

- BIO\_R\_UNABLE\_TO\_LISTEN\_SOCKET "unable to listen socket"

  [listen(2)](/listen/2.md) failed in **BIO\_get\_accept\_socket**().

## SEE ALSO

[bind(2)](/bind/2.md), [connect(2)](/connect/2.md), [errno(2)](/errno/2.md), [fcntl(2)](/fcntl/2.md), [getsockopt(2)](/getsockopt/2.md), [listen(2)](/listen/2.md), [sigaction(2)](/sigaction/2.md), [socket(2)](/socket/2.md), BIO\_new(3), BIO\_read(3), [getaddrinfo(3)](/getaddrinfo/3.md), [ip(4)](/ip/4.md), [tcp(4)](/tcp/4.md)

## HISTORY

**BIO\_sock\_should\_retry**() first appeared in SSLeay 0.6.5 and the other functions except **BIO\_socket\_nbio**() in SSLeay 0.8.0. They have all been available since OpenBSD 2.4.

**BIO\_socket\_nbio**() first appeared in SSLeay 0.9.1 and has been available since OpenBSD 2.6.
