开发者

Netlink sockets

开发者 https://www.devze.com 2023-01-30 05:01 出处:网络
I am trying send a list/array of struct to kernel space from userspace. Similar to Link As re开发者_如何学Pythoncommended there, I am thinking of using sockets for which i found link. Message is set h

I am trying send a list/array of struct to kernel space from userspace. Similar to Link As re开发者_如何学Pythoncommended there, I am thinking of using sockets for which i found link. Message is set hello in this line

strcpy(NLMSG_DATA(nlh), "Hello");

I tried

NLMSG_DATA(nlh) = my_list

That gave me error: lvalue required as left operand of assignment.

How can I change this to send an array/list using netlinks? If it can't be send this way, how else easily can I do this?

Update

My structure

typedef struct {
 int val1;
 int val2;
} mystruct;

I need to allocate an array/list of these in kernel memory so other system calls can access that list.


NLMSG_DATA() evaluates to a pointer rvalue, so you need to use a copying function like memcpy(NLMSG_DATA(nlh), my_list, sizeof my_list).

The exact details will depend on your data structure. Presumably you will want to send the number of list entries, then each entry separately.


You cannot send pointer-based structures using netlink sockets. See the packet structure of netlink: all data must be in a single block.

0

精彩评论

暂无评论...
验证码 换一张
取 消