Skip to content

Reading a C char array as a Go string #648

Answered by mmat11
tamilmani1989 asked this question in Q&A
Discussion options

You must be logged in to vote

You could define your struct in C code as:

struct verdict {
    ..
    __u8 comm[TASK_COMM_LEN];
    ..
};

which will generate Comm [16]uint8.

Edit: as Lorenz pointed out below, this field will likely contain a nul-terminated C string sent by the kernel, which can be parsed using https://pkg.go.dev/golang.org/x/sys/unix#ByteSliceToString. See https://go.dev/play/p/16gaV3H2yM-.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lmb
Comment options

@lmb
Comment options

@tamilmani1989
Comment options

Answer selected by ti-mo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bpf2go Topics related to the bpf2go tool
3 participants