Skip to content

Commit

Permalink
update(helpers): add an example for bpf_strncmp
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Oct 12, 2024
1 parent d981b83 commit 3446ae8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/linux/helper-function/bpf_strncmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,17 @@ This helper call can be used in the following program types:

### Example

!!! example "Docs could be improved"
This part of the docs is incomplete, contributions are very welcome
```c
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

SEC("tp_btf/sys_enter")
int sys_enter_trace(void *ctx) {
struct task_struct *task = (struct task_struct *)bpf_get_current_task_btf();
if (bpf_strncmp(task->comm, TASK_COMM_LEN, "cat") != 0) {
return 0;
}
bpf_printk("Hello, I'm a cat!\n");
return 0;
}
```

0 comments on commit 3446ae8

Please sign in to comment.