summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/genl-family-get.c3
-rw-r--r--examples/rtnl-link-dump.c3
-rw-r--r--examples/rtnl-link-dump2.c3
-rw-r--r--examples/rtnl-link-dump3.c2
-rw-r--r--examples/rtnl-link-event.c3
-rw-r--r--examples/rtnl-link-set.c6
-rw-r--r--examples/rtnl-route-dump.c22
7 files changed, 19 insertions, 23 deletions
diff --git a/examples/genl-family-get.c b/examples/genl-family-get.c
index 73a7574..7594003 100644
--- a/examples/genl-family-get.c
+++ b/examples/genl-family-get.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#include <libmnl/libmnl.h>
#include <linux/genetlink.h>
@@ -36,7 +37,6 @@ static int parse_mc_grps_cb(const struct nlattr *attr, void *data)
static void parse_genl_mc_grps(struct nlattr *nested)
{
struct nlattr *pos;
- int len;
mnl_attr_for_each_nested(pos, nested) {
struct nlattr *tb[CTRL_ATTR_MCAST_GRP_MAX+1] = {};
@@ -83,7 +83,6 @@ static int parse_family_ops_cb(const struct nlattr *attr, void *data)
static void parse_genl_family_ops(struct nlattr *nested)
{
struct nlattr *pos;
- int len;
mnl_attr_for_each_nested(pos, nested) {
struct nlattr *tb[CTRL_ATTR_OP_MAX+1] = {};
diff --git a/examples/rtnl-link-dump.c b/examples/rtnl-link-dump.c
index 2b9f472..e3cba05 100644
--- a/examples/rtnl-link-dump.c
+++ b/examples/rtnl-link-dump.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#include <libmnl/libmnl.h>
#include <linux/if.h>
@@ -39,8 +40,6 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
{
struct nlattr *tb[IFLA_MAX+1] = {};
struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh);
- int len = nlh->nlmsg_len;
- struct nlattr *attr;
printf("index=%d type=%d flags=%d family=%d ",
ifm->ifi_index, ifm->ifi_type,
diff --git a/examples/rtnl-link-dump2.c b/examples/rtnl-link-dump2.c
index eda5453..df61c43 100644
--- a/examples/rtnl-link-dump2.c
+++ b/examples/rtnl-link-dump2.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#include <libmnl/libmnl.h>
#include <linux/if.h>
@@ -36,8 +37,6 @@ static int data_attr_cb(const struct nlattr *attr, void *data)
static int data_cb(const struct nlmsghdr *nlh, void *data)
{
struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh);
- int len = nlh->nlmsg_len;
- struct nlattr *attr;
printf("index=%d type=%d flags=%d family=%d ",
ifm->ifi_index, ifm->ifi_type,
diff --git a/examples/rtnl-link-dump3.c b/examples/rtnl-link-dump3.c
index fc887ff..4dc20af 100644
--- a/examples/rtnl-link-dump3.c
+++ b/examples/rtnl-link-dump3.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#include <libmnl/libmnl.h>
#include <linux/if.h>
@@ -10,7 +11,6 @@
static int data_cb(const struct nlmsghdr *nlh, void *data)
{
struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh);
- int len = nlh->nlmsg_len;
struct nlattr *attr;
printf("index=%d type=%d flags=%d family=%d ",
diff --git a/examples/rtnl-link-event.c b/examples/rtnl-link-event.c
index 17f479f..bf4d845 100644
--- a/examples/rtnl-link-event.c
+++ b/examples/rtnl-link-event.c
@@ -39,8 +39,6 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
{
struct nlattr *tb[IFLA_MAX+1] = {};
struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh);
- int len = nlh->nlmsg_len;
- struct nlattr *attr;
printf("index=%d type=%d flags=%d family=%d ",
ifm->ifi_index, ifm->ifi_type,
@@ -66,7 +64,6 @@ int main()
{
struct mnl_socket *nl;
char buf[getpagesize()];
- struct nlmsghdr *nlh = (struct nlmsghdr *) buf;
int ret;
nl = mnl_socket_open(NETLINK_ROUTE);
diff --git a/examples/rtnl-link-set.c b/examples/rtnl-link-set.c
index 9be6635..87ac167 100644
--- a/examples/rtnl-link-set.c
+++ b/examples/rtnl-link-set.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
+#include <time.h>
#include <libmnl/libmnl.h>
#include <linux/if.h>
@@ -21,9 +23,9 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (strncasecmp(argv[2], "up") == 0)
+ if (strncasecmp(argv[2], "up", strlen("up")) == 0)
oper = IF_OPER_UP;
- else if (strncasecmp(argv[2], "down") == 0)
+ else if (strncasecmp(argv[2], "down", strlen("down")) == 0)
oper = IF_OPER_DOWN;
else {
fprintf(stderr, "%s is not `up' nor `down'\n", argv[2]);
diff --git a/examples/rtnl-route-dump.c b/examples/rtnl-route-dump.c
index 4241cf8..41ab10d 100644
--- a/examples/rtnl-route-dump.c
+++ b/examples/rtnl-route-dump.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
+#include <arpa/inet.h>
#include <libmnl/libmnl.h>
#include <linux/if.h>
@@ -9,9 +11,6 @@
static int data_attr_cb2(const struct nlattr *attr, void *data)
{
- const struct nlattr **tb = (const struct nlattr **)data;
- int type = mnl_attr_get_type(attr);
-
if (mnl_attr_type_valid(attr, RTAX_MAX) < 0) {
perror("mnl_attr_type_valid");
return MNL_CB_ERROR;
@@ -29,10 +28,12 @@ static void attributes_show_ipv4(struct nlattr *tb[])
printf("table=%u ", mnl_attr_get_u32(tb[RTA_TABLE]));
}
if (tb[RTA_DST]) {
- printf("dst=%s ", inet_ntoa(mnl_attr_get_u32(tb[RTA_DST])));
+ struct in_addr *addr = mnl_attr_get_payload(tb[RTA_DST]);
+ printf("dst=%s ", inet_ntoa(*addr));
}
if (tb[RTA_SRC]) {
- printf("src=%s ", inet_ntoa(mnl_attr_get_u32(tb[RTA_SRC])));
+ struct in_addr *addr = mnl_attr_get_payload(tb[RTA_SRC]);
+ printf("src=%s ", inet_ntoa(*addr));
}
if (tb[RTA_OIF]) {
printf("oif=%u ", mnl_attr_get_u32(tb[RTA_OIF]));
@@ -41,11 +42,12 @@ static void attributes_show_ipv4(struct nlattr *tb[])
printf("flow=%u ", mnl_attr_get_u32(tb[RTA_FLOW]));
}
if (tb[RTA_PREFSRC]) {
- printf("prefsrc=%s ",
- inet_ntoa(mnl_attr_get_u32(tb[RTA_PREFSRC])));
+ struct in_addr *addr = mnl_attr_get_payload(tb[RTA_PREFSRC]);
+ printf("prefsrc=%s ", inet_ntoa(*addr));
}
if (tb[RTA_GATEWAY]) {
- printf("gw=%s ", inet_ntoa(mnl_attr_get_u32(tb[RTA_GATEWAY])));
+ struct in_addr *addr = mnl_attr_get_payload(tb[RTA_GATEWAY]);
+ printf("gw=%s ", inet_ntoa(*addr));
}
if (tb[RTA_METRICS]) {
int i;
@@ -56,7 +58,7 @@ static void attributes_show_ipv4(struct nlattr *tb[])
for (i=0; i<RTAX_MAX; i++) {
if (tbx[i]) {
printf("metrics[%d]=%u ",
- mnl_attr_get_u32(tbx[i]));
+ i, mnl_attr_get_u32(tbx[i]));
}
}
}
@@ -101,8 +103,6 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
{
struct nlattr *tb[RTA_MAX+1] = {};
struct rtmsg *rm = mnl_nlmsg_get_payload(nlh);
- int len = nlh->nlmsg_len;
- struct nlattr *attr;
/* protocol family = AF_INET | AF_INET6 */
printf("family=%u ", rm->rtm_family);