diff options
author | Alex Harpin <development@landsofshadow.co.uk> | 2015-10-18 11:48:55 +0100 |
---|---|---|
committer | Alex Harpin <development@landsofshadow.co.uk> | 2015-10-18 11:48:55 +0100 |
commit | cebada14c32e6603380a913fb852854c46605d1d (patch) | |
tree | 88396b80b0a558866002809642876792f3c60de9 /examples/rtnl/rtnl-link-dump.c | |
parent | 0bb90c44862ce3f9018656beadfbc2aac4a0d517 (diff) | |
parent | 1891e0e2cefced50e7bfdacd50942cefe5bf73ba (diff) | |
download | libmnl-cebada14c32e6603380a913fb852854c46605d1d.tar.gz libmnl-cebada14c32e6603380a913fb852854c46605d1d.zip |
Merge remote-tracking branch 'source/master' into upstreamupstream
Diffstat (limited to 'examples/rtnl/rtnl-link-dump.c')
-rw-r--r-- | examples/rtnl/rtnl-link-dump.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/examples/rtnl/rtnl-link-dump.c b/examples/rtnl/rtnl-link-dump.c index 159f3b6..f5d6312 100644 --- a/examples/rtnl/rtnl-link-dump.c +++ b/examples/rtnl/rtnl-link-dump.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <unistd.h> #include <time.h> +#include <arpa/inet.h> #include <libmnl/libmnl.h> #include <linux/if.h> @@ -19,6 +20,12 @@ static int data_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; switch(type) { + case IFLA_ADDRESS: + if (mnl_attr_validate(attr, MNL_TYPE_BINARY) < 0) { + perror("mnl_attr_validate"); + return MNL_CB_ERROR; + } + break; case IFLA_MTU: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { perror("mnl_attr_validate"); @@ -27,7 +34,7 @@ static int data_attr_cb(const struct nlattr *attr, void *data) break; case IFLA_IFNAME: if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) { - perror("mnl_attr_validate2"); + perror("mnl_attr_validate"); return MNL_CB_ERROR; } break; @@ -55,7 +62,18 @@ static int data_cb(const struct nlmsghdr *nlh, void *data) printf("mtu=%d ", mnl_attr_get_u32(tb[IFLA_MTU])); } if (tb[IFLA_IFNAME]) { - printf("name=%s", mnl_attr_get_str(tb[IFLA_IFNAME])); + printf("name=%s ", mnl_attr_get_str(tb[IFLA_IFNAME])); + } + if (tb[IFLA_ADDRESS]) { + uint8_t *hwaddr = mnl_attr_get_payload(tb[IFLA_ADDRESS]); + int i; + + printf("hwaddr="); + for (i=0; i<mnl_attr_get_payload_len(tb[IFLA_ADDRESS]); i++) { + printf("%.2x", hwaddr[i] & 0xff); + if (i+1 != mnl_attr_get_payload_len(tb[IFLA_ADDRESS])) + printf(":"); + } } printf("\n"); return MNL_CB_OK; @@ -90,7 +108,7 @@ int main(void) portid = mnl_socket_get_portid(nl); if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { - perror("mnl_socket_send"); + perror("mnl_socket_sendto"); exit(EXIT_FAILURE); } |