---
name: "elf_getident"
section: "3"
platform: "linux"
package: "libelf"
version: "0.197-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf_getident"
---

# elf\_getident(3)

return the ELF identification bytes

## NAME

elf\_getident - return the ELF identification bytes

## SYNOPSIS

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

## 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

- *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*

  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

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)](/elf/5.md).

## SEE ALSO

[**libelf**(3)](/libelf/3.md), [**elf**(5)](/elf/5.md)

## ATTRIBUTES

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

## REPORTING BUGS

Report bugs to \<elfutils-devel@sourceware.org\> or https://sourceware.org/bugzilla/.
