summaryrefslogtreecommitdiff
path: root/doc/src/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/examples')
-rw-r--r--doc/src/examples/NLA_PUT.c15
-rw-r--r--doc/src/examples/msg_constr_attr.c51
-rw-r--r--doc/src/examples/msg_parse_attr.c50
-rw-r--r--doc/src/examples/my_parse.c11
-rw-r--r--doc/src/examples/nl_cb_set.c14
-rw-r--r--doc/src/examples/nl_send_simple.c11
-rw-r--r--doc/src/examples/nla_flag.c7
-rw-r--r--doc/src/examples/nla_for_each_attr.c11
-rw-r--r--doc/src/examples/nla_nest_start.c16
-rw-r--r--doc/src/examples/nla_ok.c10
-rw-r--r--doc/src/examples/nla_parse_nested.c12
-rw-r--r--doc/src/examples/nla_put.c14
-rw-r--r--doc/src/examples/nlmsg_for_each.c7
-rw-r--r--doc/src/examples/nlmsg_parse.c29
-rw-r--r--doc/src/examples/nlmsg_put.c31
-rw-r--r--doc/src/examples/sk_group_example.c43
16 files changed, 0 insertions, 332 deletions
diff --git a/doc/src/examples/NLA_PUT.c b/doc/src/examples/NLA_PUT.c
deleted file mode 100644
index c3afb47..0000000
--- a/doc/src/examples/NLA_PUT.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <netlink/msg.h>
-#include <netlink/attr.h>
-
-void construct_attrs(struct nl_msg *msg)
-{
- NLA_PUT_STRING(msg, MY_ATTR_FOO1, "some text");
- NLA_PUT_U32(msg, MY_ATTR_FOO1, 0x1010);
- NLA_PUT_FLAG(msg, MY_ATTR_FOO3, 1);
-
- return 0;
-
-nla_put_failure:
- /* NLA_PUT* macros jump here in case of an error */
- return -EMSGSIZE;
-}
diff --git a/doc/src/examples/msg_constr_attr.c b/doc/src/examples/msg_constr_attr.c
deleted file mode 100644
index bfa00fe..0000000
--- a/doc/src/examples/msg_constr_attr.c
+++ /dev/null
@@ -1,51 +0,0 @@
-struct nl_msg *build_msg(int ifindex, struct nl_addr *lladdr, int mtu)
-{
- struct nl_msg *msg;
- struct nlattr *info, *vlan;
- struct ifinfomsg ifi = {
- .ifi_family = AF_INET,
- .ifi_index = ifindex,
- };
-
- /* Allocate a default sized netlink message */
- if (!(msg = nlmsg_alloc_simple(RTM_SETLINK, 0)))
- return NULL;
-
- /* Append the protocol specific header (struct ifinfomsg)*/
- if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
- goto nla_put_failure
-
- /* Append a 32 bit integer attribute to carry the MTU */
- NLA_PUT_U32(msg, IFLA_MTU, mtu);
-
- /* Append a unspecific attribute to carry the link layer address */
- NLA_PUT_ADDR(msg, IFLA_ADDRESS, lladdr);
-
- /* Append a container for nested attributes to carry link information */
- if (!(info = nla_nest_start(msg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- /* Put a string attribute into the container */
- NLA_PUT_STRING(msg, IFLA_INFO_KIND, "vlan");
-
- /*
- * Append another container inside the open container to carry
- * vlan specific attributes
- */
- if (!(vlan = nla_nest_start(msg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- /* add vlan specific info attributes here... */
-
- /* Finish nesting the vlan attributes and close the second container. */
- nla_nest_end(msg, vlan);
-
- /* Finish nesting the link info attribute and close the first container. */
- nla_nest_end(msg, info);
-
- return msg;
-
-nla_put_failure:
- nlmsg_free(msg);
- return NULL;
-}
diff --git a/doc/src/examples/msg_parse_attr.c b/doc/src/examples/msg_parse_attr.c
deleted file mode 100644
index 6e275e9..0000000
--- a/doc/src/examples/msg_parse_attr.c
+++ /dev/null
@@ -1,50 +0,0 @@
-int parse_message(struct nlmsghdr *hdr)
-{
- /*
- * The policy defines two attributes: a 32 bit integer and a container
- * for nested attributes.
- */
- struct nla_policy attr_policy[] = {
- [ATTR_FOO] = { .type = NLA_U32 },
- [ATTR_BAR] = { .type = NLA_NESTED },
- };
- struct nlattr *attrs[ATTR_MAX+1];
- int err;
-
- /*
- * The nlmsg_parse() function will make sure that the message contains
- * enough payload to hold the header (struct my_hdr), validates any
- * attributes attached to the messages and stores a pointer to each
- * attribute in the attrs[] array accessable by attribute type.
- */
- if ((err = nlmsg_parse(hdr, sizeof(struct my_hdr), attrs, ATTR_MAX,
- attr_policy)) < 0)
- goto errout;
-
- if (attrs[ATTR_FOO]) {
- /*
- * It is safe to directly access the attribute payload without
- * any further checks since nlmsg_parse() enforced the policy.
- */
- uint32_t foo = nla_get_u32(attrs[ATTR_FOO]);
- }
-
- if (attrs[ATTR_BAR]) {
- struct *nested[NESTED_MAX+1];
-
- /*
- * Attributes nested in a container can be parsed the same way
- * as top level attributes.
- */
- err = nla_parse_nested(nested, NESTED_MAX, attrs[ATTR_BAR],
- nested_policy);
- if (err < 0)
- goto errout;
-
- // Process nested attributes here.
- }
-
- err = 0;
-errout:
- return err;
-}
diff --git a/doc/src/examples/my_parse.c b/doc/src/examples/my_parse.c
deleted file mode 100644
index c1ff637..0000000
--- a/doc/src/examples/my_parse.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <netlink/msg.h>
-
-void my_parse(void *stream, int length)
-{
- struct nlmsghdr *hdr = stream;
-
- while (nlmsg_ok(hdr, length)) {
- // Parse message here
- hdr = nlmsg_next(hdr, &length);
- }
-}
diff --git a/doc/src/examples/nl_cb_set.c b/doc/src/examples/nl_cb_set.c
deleted file mode 100644
index 4fbaefc..0000000
--- a/doc/src/examples/nl_cb_set.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <netlink/handlers.h>
-
-/* Allocate a callback set and initialize it to the verbose default set */
-struct nl_cb *cb = nl_cb_alloc(NL_CB_VERBOSE);
-
-/* Modify the set to call my_func() for all valid messages */
-nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, my_func, NULL);
-
-/*
- * Set the error message handler to the verbose default implementation
- * and direct it to print all errors to the given file descriptor.
- */
-FILE *file = fopen(...);
-nl_cb_err(cb, NL_CB_VERBOSE, NULL, file);
diff --git a/doc/src/examples/nl_send_simple.c b/doc/src/examples/nl_send_simple.c
deleted file mode 100644
index afbed7a..0000000
--- a/doc/src/examples/nl_send_simple.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <netlink/netlink.h>
-
-struct nl_sock *sk;
-struct rtgenmsg rt_hdr = {
- .rtgen_family = AF_UNSPEC,
-};
-
-sk = nl_socket_alloc();
-nl_connect(sk, NETLINK_ROUTE);
-
-nl_send_simple(sock, RTM_GETLINK, NLM_F_DUMP, &rt_hdr, sizeof(rt_hdr));
diff --git a/doc/src/examples/nla_flag.c b/doc/src/examples/nla_flag.c
deleted file mode 100644
index dc3d0f9..0000000
--- a/doc/src/examples/nla_flag.c
+++ /dev/null
@@ -1,7 +0,0 @@
-/* nla_put_flag() appends a zero sized attribute to the message. */
-nla_put_flag(msg, ATTR_FLAG);
-
-
-/* There is no need for a receival function, the presence is the value. */
-if (attrs[ATTR_FLAG])
- /* flag is present */
diff --git a/doc/src/examples/nla_for_each_attr.c b/doc/src/examples/nla_for_each_attr.c
deleted file mode 100644
index 9d81835..0000000
--- a/doc/src/examples/nla_for_each_attr.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <netlink/attr.h>
-
-struct nalttr *nla;
-int rem;
-
-nla_for_each_attr(nla, attrstream, streamlen, rem) {
- /* validate & parse attribute */
-}
-
-if (rem > 0)
- /* unparsed attribute data */
diff --git a/doc/src/examples/nla_nest_start.c b/doc/src/examples/nla_nest_start.c
deleted file mode 100644
index 51cd616..0000000
--- a/doc/src/examples/nla_nest_start.c
+++ /dev/null
@@ -1,16 +0,0 @@
-int put_opts(struct nl_msg *msg)
-{
- struct nlattr *opts;
-
- if (!(opts = nla_nest_start(msg, ATTR_OPTS)))
- goto nla_put_failure;
-
- NLA_PUT_U32(msg, NESTED_FOO, 123);
- NLA_PUT_STRING(msg, NESTED_BAR, "some text");
-
- nla_nest_end(msg, opts);
- return 0;
-
-nla_put_failure:
- return -EMSGSIZE;
-}
diff --git a/doc/src/examples/nla_ok.c b/doc/src/examples/nla_ok.c
deleted file mode 100644
index 4485a96..0000000
--- a/doc/src/examples/nla_ok.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <netlink/msg.h>
-#include <netlink/attr.h>
-
-struct nlattr *hdr = nlmsg_attrdata(msg, 0);
-int remaining = nlmsg_attrlen(msg, 0);
-
-while (nla_ok(hdr, remaining)) {
- /* parse attribute here */
- hdr = nla_next(hdr, &remaining);
-};
diff --git a/doc/src/examples/nla_parse_nested.c b/doc/src/examples/nla_parse_nested.c
deleted file mode 100644
index 563bfc8..0000000
--- a/doc/src/examples/nla_parse_nested.c
+++ /dev/null
@@ -1,12 +0,0 @@
-if (attrs[ATTR_OPTS]) {
- struct nlattr *nested[NESTED_MAX+1];
- struct nla_policy nested_policy[] = {
- [NESTED_FOO] = { .type = NLA_U32 },
- };
-
- if (nla_parse_nested(nested, NESTED_MAX, attrs[ATTR_OPTS], nested_policy) < 0)
- /* error */
-
- if (nested[NESTED_FOO])
- uint32_t val = nla_get_u32(nested[NESTED_FOO]);
-}
diff --git a/doc/src/examples/nla_put.c b/doc/src/examples/nla_put.c
deleted file mode 100644
index 0683fa5..0000000
--- a/doc/src/examples/nla_put.c
+++ /dev/null
@@ -1,14 +0,0 @@
-struct my_attr_struct {
- uint32_t a;
- uint32_t b;
-};
-
-int my_put(struct nl_msg *msg)
-{
- struct my_attr_struct obj = {
- .a = 10,
- .b = 20,
- };
-
- return nla_put(msg, ATTR_MY_STRUCT, sizeof(obj), &obj);
-}
diff --git a/doc/src/examples/nlmsg_for_each.c b/doc/src/examples/nlmsg_for_each.c
deleted file mode 100644
index ae2ee66..0000000
--- a/doc/src/examples/nlmsg_for_each.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <netlink/msg.h>
-
-struct nlmsghdr *hdr;
-
-nlmsg_for_each(hdr, stream, length) {
- /* do something with message */
-}
diff --git a/doc/src/examples/nlmsg_parse.c b/doc/src/examples/nlmsg_parse.c
deleted file mode 100644
index ac6acb3..0000000
--- a/doc/src/examples/nlmsg_parse.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <netlink/msg.h>
-#include <netlink/attr.h>
-
-enum {
- MY_ATTR_FOO = 1,
- MY_ATTR_BAR,
- __MY_ATTR_MAX,
-};
-
-#define MY_ATTR_MAX (__MY_ATTR_MAX - 1)
-
-static struct nla_policy my_policy[MY_ATTR_MAX+1] = {
- [MY_ATTR_FOO] = { .type = NLA_U32 },
- [MY_ATTR_BAR] = { .type = NLA_STRING,
- .maxlen = 16 },
-};
-
-void parse_msg(struct nlmsghdr *nlh)
-{
- struct nlattr *attrs[MY_ATTR_MAX+1];
-
- if (nlmsg_parse(nlh, 0, attrs, MY_ATTR_MAX, my_policy) < 0)
- /* error */
-
- if (attrs[MY_ATTR_FOO]) {
- /* MY_ATTR_FOO is present in message */
- printf("value: %u\n", nla_get_u32(attrs[MY_ATTR_FOO]));
- }
-}
diff --git a/doc/src/examples/nlmsg_put.c b/doc/src/examples/nlmsg_put.c
deleted file mode 100644
index 5e609c6..0000000
--- a/doc/src/examples/nlmsg_put.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <netlink/msg.h>
-
-struct nlmsghdr *hdr;
-struct nl_msg *msg;
-struct myhdr {
- uint32_t foo1, foo2;
-} hdr = { 10, 20 };
-
-/* Allocate a message with the default maximum message size */
-msg = nlmsg_alloc();
-
-/*
- * Add header with message type MY_MSGTYPE, the flag NLM_F_CREATE,
- * let library fill port and sequence number, and reserve room for
- * struct myhdr
- */
-hdr = nlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, MY_MSGTYPE, sizeof(hdr), NLM_F_CREATE);
-
-/* Copy own header into newly reserved payload section */
-memcpy(nlmsg_data(hdr), &hdr, sizeof(hdr));
-
-/*
- * The message will now look like this:
- * +-------------------+- - -+----------------+- - -+
- * | struct nlmsghdr | Pad | struct myhdr | Pad |
- * +-------------------+-----+----------------+- - -+
- * nlh -^ / \
- * +--------+---------+
- * | foo1 | foo2 |
- * +--------+---------+
- */
diff --git a/doc/src/examples/sk_group_example.c b/doc/src/examples/sk_group_example.c
deleted file mode 100644
index f948e18..0000000
--- a/doc/src/examples/sk_group_example.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <netlink/netlink.h>
-#include <netlink/socket.h>
-#include <netlink/msg.h>
-
-/*
- * This function will be called for each valid netlink message received
- * in nl_recvmsgs_default()
- */
-static int my_func(struct nl_msg *msg, void *arg)
-{
- return 0;
-}
-
-struct nl_sock *sk;
-
-/* Allocate a new socket */
-sk = nl_socket_alloc();
-
-/*
- * Notifications do not use sequence numbers, disable sequence number
- * checking.
- */
-nl_socket_disable_seq_check(sk);
-
-/*
- * Define a callback function, which will be called for each notification
- * received
- */
-nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, my_func, NULL);
-
-/* Connect to routing netlink protocol */
-nl_connect(sk, NETLINK_ROUTE);
-
-/* Subscribe to link notifications group */
-nl_socket_add_memberships(sk, RTNLGRP_LINK);
-
-/*
- * Start receiving messages. The function nl_recvmsgs_default() will block
- * until one or more netlink messages (notification) are received which
- * will be passed on to my_func().
- */
-while (1)
- nl_recvmsgs_default(sock);