00001 #include <netlink/msg.h> 00002 00003 struct nlmsghdr *hdr; 00004 struct nl_msg *msg; 00005 struct myhdr { 00006 uint32_t foo1, foo2; 00007 } hdr = { 10, 20 }; 00008 00009 /* Allocate a message with the default maximum message size */ 00010 msg = nlmsg_alloc(); 00011 00012 /* 00013 * Add header with message type MY_MSGTYPE, the flag NLM_F_CREATE, 00014 * let library fill port and sequence number, and reserve room for 00015 * struct myhdr 00016 */ 00017 hdr = nlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, MY_MSGTYPE, sizeof(hdr), NLM_F_CREATE); 00018 00019 /* Copy own header into newly reserved payload section */ 00020 memcpy(nlmsg_data(hdr), &hdr, sizeof(hdr)); 00021 00022 /* 00023 * The message will now look like this: 00024 * +-------------------+- - -+----------------+- - -+ 00025 * | struct nlmsghdr | Pad | struct myhdr | Pad | 00026 * +-------------------+-----+----------------+- - -+ 00027 * nlh -^ / \ 00028 * +--------+---------+ 00029 * | foo1 | foo2 | 00030 * +--------+---------+ 00031 */