ELF\_GETIDENT(3) Libelf Programmer's Manual ELF\_GETIDENT(3)

# [NAME](#NAME)

elf\_getident - return the ELF identification bytes

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
char * elf_getident("Elf *elf", size_t *nbytes );
```

# [DESCRIPTION](#DESCRIPTION)

The **elf\_getident**() function returns a pointer to the 16-byte ELF identification array from the ELF header of the given descriptor *elf*.

This identification data begins with the magic number \`**\\177ELF**\` and includes the class, data encoding, ELF version, OS ABI, and ABI version fields. It corresponds to the first **EI\_NIDENT** bytes of the ELF header and can be accessed via the **e\_ident** field of either **Elf32\_Ehdr** or **Elf64\_Ehdr .**

If *elf* is a valid descriptor for an ELF object, the function returns a pointer to the internal buffer containing the header's identification bytes. The buffer is owned by the library and must not be modified or freed by the caller.

If *nbytes* is not NULL, the function sets to **EI\_NIDENT** (16), the length in bytes of the returned identifier.

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

Pointer to an **Elf** descriptor referring to a valid ELF object. If the descriptor does not represent an ELF object file (is NULL or **elf\_kind**() is not **ELF\_K\_ELF** ), NULL is returned.

[*nbytes*](#nbytes)

Optional pointer to a **size\_t** variable. If non-NULL, it will be set to the length of the returned buffer (always EI\_NIDENT on success, 0 on failure).

# [RETURN VALUE](#RETURN_VALUE)

Returns a pointer to the internal 16-byte **e\_ident** buffer on success and NULL on failure. Does not set elf\_errno.

This buffer is indexed using the **EI\_CLASS**, **EI\_DATA**, **EI\_VERSION**, **EI\_OSABI**, and **EI\_ABIVERSION** macros found in elf.h. Also see [**elf**(5)](/man/os/elfutils/elf.5).

# [SEE ALSO](#SEE_ALSO)

[**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** elf\_getident () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;elfutils-devel@sourceware.org&gt; or https://sourceware.org/bugzilla/.

2025-06-30 Libelf

---

Document: elf_getident(3) from elfutils 0.196-r1 (Chainguard OS)
Source: https://sourceware.org/git/elfutils.git
