Libbpf userspace function bpf_obj_get_info_by_fd
Low level wrapper around the BPF_OBJ_GET_INFO_BY_FD syscall command.
Definition
int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);
Parameters
bpf_fd: file descriptor of the BPF objectinfo: buffer to store the information about the BPF objectinfo_len: indicates the size of the buffer whichinfopoints to and will be changed by the syscall command to the actual amount of data written to theinfobuffer
Return
0, on success; negative error code, otherwise
Usage
This function allows you to retrieve information about a BPF object by its file descriptor. The information will be written to info, the structure of the info depends on the underlying object type.
Example
This example demonstrates how to use bpf_obj_get_info_by_fd to retrieve an eBPF program’s ID from its file descriptor.
The prog_fd could be obtained, for example, via bpf_program__fd or other methods.
struct bpf_prog_info info = {0};
__u32 len = sizeof(info);
if (bpf_obj_get_info_by_fd(prog_fd, &info, &len) < 0)
printf("Failed to get info\n");
else
printf("Program ID: %u\n", info.id);