~ubuntu-branches/ubuntu/trusty/libnl3/trusty

« back to all changes in this revision

Viewing changes to doc/src/examples/nlmsg_put.c

  • Committer: Bazaar Package Importer
  • Author(s): Heiko Stuebner
  • Date: 2011-05-21 19:25:13 UTC
  • Revision ID: james.westby@ubuntu.com-20110521192513-1ieyu9w9kym4bt16
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <netlink/msg.h>
 
2
 
 
3
struct nlmsghdr *hdr;
 
4
struct nl_msg *msg;
 
5
struct myhdr {
 
6
        uint32_t foo1, foo2;
 
7
} hdr = { 10, 20 };
 
8
 
 
9
/* Allocate a message with the default maximum message size */
 
10
msg = nlmsg_alloc();
 
11
 
 
12
/*
 
13
 * Add header with message type MY_MSGTYPE, the flag NLM_F_CREATE,
 
14
 * let library fill port and sequence number, and reserve room for
 
15
 * struct myhdr
 
16
 */
 
17
hdr = nlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, MY_MSGTYPE, sizeof(hdr), NLM_F_CREATE);
 
18
 
 
19
/* Copy own header into newly reserved payload section */
 
20
memcpy(nlmsg_data(hdr), &hdr, sizeof(hdr));
 
21
 
 
22
/*
 
23
 * The message will now look like this:
 
24
 *     +-------------------+- - -+----------------+- - -+
 
25
 *     |  struct nlmsghdr  | Pad |  struct myhdr  | Pad |
 
26
 *     +-------------------+-----+----------------+- - -+
 
27
 * nlh -^                        /                \
 
28
 *                              +--------+---------+
 
29
 *                              |  foo1  |  foo2   |
 
30
 *                              +--------+---------+
 
31
 */