From 1f09fdccb75005a53ba2bb90fb61d4e6f45e8e14 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 12 Apr 2010 18:06:28 +0200 Subject: remove mnl_nlmsg_get_len() function Remove mnl_nlmsg_get_len() since it returns a field of a structure that is public (struct nlmsghdr). We can directly access the header fields and they are not likely to change in the future (at least for this version of Netlink I think). Signed-off-by: Pablo Neira Ayuso --- examples/genl-family-get.c | 2 +- examples/rtnl-link-dump.c | 4 ++-- examples/rtnl-link-dump2.c | 4 ++-- examples/rtnl-link-dump3.c | 4 ++-- examples/rtnl-link-event.c | 2 +- examples/rtnl-link-set.c | 2 +- examples/rtnl-route-dump.c | 4 ++-- include/libmnl/libmnl.h | 3 +-- src/attr.c | 2 +- src/nlmsg.c | 17 +---------------- 10 files changed, 14 insertions(+), 30 deletions(-) diff --git a/examples/genl-family-get.c b/examples/genl-family-get.c index 674a529..73a7574 100644 --- a/examples/genl-family-get.c +++ b/examples/genl-family-get.c @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) } portid = mnl_socket_get_portid(nl); - if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) { + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { perror("mnl_socket_send"); exit(EXIT_FAILURE); } diff --git a/examples/rtnl-link-dump.c b/examples/rtnl-link-dump.c index d888cbc..2b9f472 100644 --- a/examples/rtnl-link-dump.c +++ b/examples/rtnl-link-dump.c @@ -39,7 +39,7 @@ 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 = mnl_nlmsg_get_len(nlh); + int len = nlh->nlmsg_len; struct nlattr *attr; printf("index=%d type=%d flags=%d family=%d ", @@ -90,7 +90,7 @@ int main() } portid = mnl_socket_get_portid(nl); - if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) { + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { perror("mnl_socket_send"); exit(EXIT_FAILURE); } diff --git a/examples/rtnl-link-dump2.c b/examples/rtnl-link-dump2.c index 2276eba..eda5453 100644 --- a/examples/rtnl-link-dump2.c +++ b/examples/rtnl-link-dump2.c @@ -36,7 +36,7 @@ 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 = mnl_nlmsg_get_len(nlh); + int len = nlh->nlmsg_len; struct nlattr *attr; printf("index=%d type=%d flags=%d family=%d ", @@ -81,7 +81,7 @@ int main() } portid = mnl_socket_get_portid(nl); - if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) { + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { perror("mnl_socket_send"); exit(EXIT_FAILURE); } diff --git a/examples/rtnl-link-dump3.c b/examples/rtnl-link-dump3.c index fac3b87..fc887ff 100644 --- a/examples/rtnl-link-dump3.c +++ b/examples/rtnl-link-dump3.c @@ -10,7 +10,7 @@ static int data_cb(const struct nlmsghdr *nlh, void *data) { struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh); - int len = mnl_nlmsg_get_len(nlh); + int len = nlh->nlmsg_len; struct nlattr *attr; printf("index=%d type=%d flags=%d family=%d ", @@ -79,7 +79,7 @@ int main() } portid = mnl_socket_get_portid(nl); - if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) { + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { perror("mnl_socket_send"); exit(EXIT_FAILURE); } diff --git a/examples/rtnl-link-event.c b/examples/rtnl-link-event.c index 1f3ceaf..17f479f 100644 --- a/examples/rtnl-link-event.c +++ b/examples/rtnl-link-event.c @@ -39,7 +39,7 @@ 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 = mnl_nlmsg_get_len(nlh); + int len = nlh->nlmsg_len; struct nlattr *attr; printf("index=%d type=%d flags=%d family=%d ", diff --git a/examples/rtnl-link-set.c b/examples/rtnl-link-set.c index d7327dd..0a63527 100644 --- a/examples/rtnl-link-set.c +++ b/examples/rtnl-link-set.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) mnl_nlmsg_print(nlh); - if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) { + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { perror("mnl_socket_send"); exit(EXIT_FAILURE); } diff --git a/examples/rtnl-route-dump.c b/examples/rtnl-route-dump.c index ddfbaa9..4241cf8 100644 --- a/examples/rtnl-route-dump.c +++ b/examples/rtnl-route-dump.c @@ -101,7 +101,7 @@ 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 = mnl_nlmsg_get_len(nlh); + int len = nlh->nlmsg_len; struct nlattr *attr; /* protocol family = AF_INET | AF_INET6 */ @@ -219,7 +219,7 @@ int main() } portid = mnl_socket_get_portid(nl); - if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) { + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { perror("mnl_socket_send"); exit(EXIT_FAILURE); } diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h index 11eda8a..afb298a 100644 --- a/include/libmnl/libmnl.h +++ b/include/libmnl/libmnl.h @@ -51,8 +51,7 @@ extern int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq); /* Netlink portID checking */ int mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid); -/* Netlink header getters */ -extern uint16_t mnl_nlmsg_get_len(const struct nlmsghdr *nlh); +/* Netlink message getters */ extern void *mnl_nlmsg_get_payload(const struct nlmsghdr *nlh); extern void *mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh, int offset); extern void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh); diff --git a/src/attr.c b/src/attr.c index 936a9ae..59cf8c0 100644 --- a/src/attr.c +++ b/src/attr.c @@ -247,7 +247,7 @@ int mnl_attr_parse(const struct nlmsghdr *nlh, int offset, { int ret = MNL_CB_OK; struct nlattr *attr = mnl_nlmsg_get_payload_offset(nlh, offset); - int len = mnl_nlmsg_get_len(nlh); + int len = nlh->nlmsg_len; while (mnl_attr_ok(attr, len)) { if (cb && (ret = cb(attr, data)) <= MNL_CB_STOP) diff --git a/src/nlmsg.c b/src/nlmsg.c index 4450cf5..de41be6 100644 --- a/src/nlmsg.c +++ b/src/nlmsg.c @@ -112,21 +112,6 @@ void *mnl_nlmsg_put_extra_header(struct nlmsghdr *nlh, int size) return ptr; } -/** - * mnl_nlmsg_get_len - get the length field from the netlink message - * @nlh: pointer to a netlink header - * - * This function returns the full length of the Netlink message (including the - * length of the Netlink header) by return the field nlmsg_len of the message. - * - * XXX: This function is likely to be deleted soon since the structure of the - * Netlink header is public. - */ -uint16_t mnl_nlmsg_get_len(const struct nlmsghdr *nlh) -{ - return nlh->nlmsg_len; -} - /** * mnl_nlmsg_get_payload - get a pointer to the payload of the netlink message * @nlh: pointer to a netlink header @@ -248,7 +233,7 @@ void mnl_nlmsg_print(const struct nlmsghdr *nlh) printf("port ID(32 bits)=%.08u\n", nlh->nlmsg_pid); printf("===================================\n"); - for (i=sizeof(struct nlmsghdr); inlmsg_len; i+=4) { char *b = (char *) nlh; printf("(%.3d) %.2x %.2x %.2x %.2x | ", i, -- cgit v1.2.3