ELF_GETIDENT(3)

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).

SEE ALSO
libelf(3), elf(5)

ATTRIBUTES
Interface | Attribute | Value
 | Thread safety | MT-Safe

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