summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2010-04-03 13:06:20 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2010-04-03 13:06:20 +0200
commitabcaad6b65ed368c13c353ed71619332f76d9c2a (patch)
tree8c057fef5ffd19475b65dc905d4293244e6f03ad /examples
parentccf40b8b3789193554ae13182c38ba7e69841cce (diff)
downloadlibmnl-abcaad6b65ed368c13c353ed71619332f76d9c2a.tar.gz
libmnl-abcaad6b65ed368c13c353ed71619332f76d9c2a.zip
check portid of received messages in examples
netlink is not connection-oriented, we have to check the origin of the message. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/genl-family-get.c4
-rw-r--r--examples/rtnl-link-dump.c4
-rw-r--r--examples/rtnl-link-event.c4
-rw-r--r--examples/rtnl-route-dump.c4
4 files changed, 16 insertions, 0 deletions
diff --git a/examples/genl-family-get.c b/examples/genl-family-get.c
index 3e741cb..e6033af 100644
--- a/examples/genl-family-get.c
+++ b/examples/genl-family-get.c
@@ -51,6 +51,10 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
struct nlattr *tb[CTRL_ATTR_MAX+1];
struct genlmsghdr *genl = mnl_nlmsg_get_data(nlh);
+ /* this does not come from the kernel. */
+ if (nlh->nlmsg_pid != 0)
+ return MNL_CB_OK;
+
mnl_attr_parse_at_offset(nlh, sizeof(*genl), tb, CTRL_ATTR_MAX);
if (tb[CTRL_ATTR_FAMILY_NAME]) {
printf("name=%s\t",
diff --git a/examples/rtnl-link-dump.c b/examples/rtnl-link-dump.c
index 7cf061d..cc3fdf7 100644
--- a/examples/rtnl-link-dump.c
+++ b/examples/rtnl-link-dump.c
@@ -14,6 +14,10 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
int len = mnl_nlmsg_get_len(nlh);
struct nlattr *attr;
+ /* this does not come from the kernel. */
+ if (nlh->nlmsg_pid != 0)
+ return MNL_CB_OK;
+
printf("index=%d type=%d flags=%d family=%d ",
ifm->ifi_index, ifm->ifi_type,
ifm->ifi_flags, ifm->ifi_family);
diff --git a/examples/rtnl-link-event.c b/examples/rtnl-link-event.c
index ed5a577..3cff82d 100644
--- a/examples/rtnl-link-event.c
+++ b/examples/rtnl-link-event.c
@@ -14,6 +14,10 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
int len = mnl_nlmsg_get_len(nlh);
struct nlattr *attr;
+ /* this does not come from the kernel. */
+ if (nlh->nlmsg_pid != 0)
+ return MNL_CB_OK;
+
printf("index=%d type=%d flags=%d family=%d ",
ifm->ifi_index, ifm->ifi_type,
ifm->ifi_flags, ifm->ifi_family);
diff --git a/examples/rtnl-route-dump.c b/examples/rtnl-route-dump.c
index e8f3a0c..131d344 100644
--- a/examples/rtnl-route-dump.c
+++ b/examples/rtnl-route-dump.c
@@ -55,6 +55,10 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
int len = mnl_nlmsg_get_len(nlh);
struct nlattr *attr;
+ /* this does not come from the kernel. */
+ if (nlh->nlmsg_pid != 0)
+ return MNL_CB_OK;
+
/* protocol family = AF_INET | AF_INET6 */
printf("family=%u ", rm->rtm_family);