---
name: "gai_strerror"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/gai_strerror"
---

# gai\_strerror(3)

get error message string from EAI\_xxx error code

## NAME

**gai\_strerror** – get error message string from EAI\_xxx error code

## SYNOPSIS

**#include \<sys/types.h\>**

**#include \<sys/socket.h\>**

**#include \<netdb.h\>**

*const char \**\

**gai\_strerror**(*int ecode*);

## DESCRIPTION

The **gai\_strerror**() function returns an error message string corresponding to the error code returned by [getaddrinfo(3)](/getaddrinfo/3.md) or [getnameinfo(3)](/getnameinfo/3.md).

The following error codes and their meaning are defined in ⟨netdb.h⟩:

- EAI\_ADDRFAMILY

  Address family for hostname not supported

- EAI\_AGAIN

  Name could not be resolved at this time

- EAI\_BADFLAGS

  flags parameter had an invalid value

- EAI\_BADHINTS

  invalid value for *hints*

- EAI\_FAIL

  Non-recoverable failure in name resolution

- EAI\_FAMILY

  Address family was not recognized

- EAI\_MEMORY

  Memory allocation failure

- EAI\_NODATA

  No address associated with hostname

- EAI\_NONAME

  Name does not resolve

- EAI\_OVERFLOW

  argument buffer overflow

- EAI\_PROTOCOL

  Resolved protocol is unknown

- EAI\_SERVICE

  Service was not recognized for socket type

- EAI\_SOCKTYPE

  Intended socket type was not recognized

- EAI\_SYSTEM

  System error returned in *errno*

## RETURN VALUES

The **gai\_strerror**() function returns a pointer to the error message string corresponding to *ecode*. If *ecode* is out of range, an implementation-specific error message string is returned.

## SEE ALSO

[getaddrinfo(3)](/getaddrinfo/3.md), [getnameinfo(3)](/getnameinfo/3.md)

## STANDARDS

- RFC 3493

  Basic Socket Interface Extensions for IPv6

EAI\_ADDRFAMILY and EAI\_NODATA were in previous RFCs, but not in RFC 3493. They are not in POSIX (IEEE Std 1003.1-2017). They were in FreeBSD before 5.2, and were re-added for 14.0. EAI\_BADHINTS, EAI\_OVERFLOW, and EAI\_PROTOCOL are not in RFC 3493 or POSIX.
