From: Jan Engelhardt <jengelh@medozas.de>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 12/13] nlmsg: use bool return type for yes-no functions
Date: Sat, 23 Oct 2010 07:44:49 +0200 [thread overview]
Message-ID: <1287812691-14470-13-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1287812691-14470-1-git-send-email-jengelh@medozas.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
include/libmnl/libmnl.h | 7 +++++--
src/nlmsg.c | 18 +++++++++---------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index b64306a..a32fb1d 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -5,6 +5,9 @@
#include <stdint.h>
#include <sys/socket.h> /* for sa_family_t */
#include <linux/netlink.h>
+#ifndef __cplusplus
+# include <stdbool.h>
+#endif
#ifdef __cplusplus
extern "C" {
@@ -50,10 +53,10 @@ extern int mnl_nlmsg_ok(const struct nlmsghdr *nlh, int len);
extern struct nlmsghdr *mnl_nlmsg_next(const struct nlmsghdr *nlh, int *len);
/* Netlink sequence tracking */
-extern int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq);
+extern bool mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq);
/* Netlink portID checking */
-extern int mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid);
+extern bool mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid);
/* Netlink message getters */
extern void *mnl_nlmsg_get_payload(const struct nlmsghdr *nlh);
diff --git a/src/nlmsg.c b/src/nlmsg.c
index 535f4b5..f89a9ec 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
-
+#include <stdbool.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
@@ -200,8 +200,8 @@ void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh)
* \param nlh current netlink message that we are handling
* \param seq last sequence number used to send a message
*
- * This functions returns 1 if the sequence tracking is fulfilled, otherwise
- * 0 is returned. We skip the tracking for netlink messages whose sequence
+ * This functions returns true if the sequence tracking is fulfilled, otherwise
+ * false is returned. We skip the tracking for netlink messages whose sequence
* number is zero since it is usually reserved for event-based kernel
* notifications. On the other hand, if seq is set but the message sequence
* number is not set (i.e. this is an event message coming from kernel-space),
@@ -209,9 +209,9 @@ void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh)
* socket to send commands to kernel-space (that we want to track) and to
* listen to events (that we do not track).
*/
-int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
+bool mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
{
- return nlh->nlmsg_seq && seq ? nlh->nlmsg_seq == seq : 1;
+ return nlh->nlmsg_seq && seq ? nlh->nlmsg_seq == seq : true;
}
/**
@@ -219,8 +219,8 @@ int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
* \param nlh current netlink message that we are handling
* \param seq netlink portid that we want to check
*
- * This functions returns 1 if the origin is fulfilled, otherwise
- * 0 is returned. We skip the tracking for netlink message whose portID
+ * This functions returns true if the origin is fulfilled, otherwise
+ * false is returned. We skip the tracking for netlink message whose portID
* is zero since it is reserved for event-based kernel notifications. On the
* other hand, if portid is set but the message PortID is not (i.e. this
* is an event message coming from kernel-space), then we also skip the
@@ -228,9 +228,9 @@ int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
* to kernel-space (that we want to track) and to listen to events (that we
* do not track).
*/
-int mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid)
+bool mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid)
{
- return nlh->nlmsg_pid && portid ? nlh->nlmsg_pid == portid : 1;
+ return nlh->nlmsg_pid && portid ? nlh->nlmsg_pid == portid : true;
}
/**
--
1.7.1
next prev parent reply other threads:[~2010-10-23 5:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-23 5:44 libmnl: misc code updates Jan Engelhardt
2010-10-23 5:44 ` [PATCH 01/13] build: fix disable_static functionality Jan Engelhardt
2010-10-23 5:44 ` [PATCH 02/13] src: avoid using deprecated unspecified argument lists Jan Engelhardt
2010-10-23 5:44 ` [PATCH 03/13] src: add const qualifiers Jan Engelhardt
2010-10-23 5:44 ` [PATCH 04/13] src: remove redundant casts Jan Engelhardt
2010-10-23 5:44 ` [PATCH 05/13] socket: remove statement with no effect Jan Engelhardt
2010-10-23 5:44 ` [PATCH 06/13] doc: documentation updates Jan Engelhardt
2010-10-23 5:44 ` [PATCH 07/13] include: consistent usage of "extern" Jan Engelhardt
2010-10-23 5:44 ` [PATCH 08/13] attr: string functions should take char * Jan Engelhardt
2010-10-23 5:44 ` [PATCH 09/13] callback: mnl_cb_run should use a void * Jan Engelhardt
2010-10-23 5:44 ` [PATCH 10/13] socket: use more appropriate types for mnl_socket_bind Jan Engelhardt
2010-10-23 5:44 ` [PATCH 11/13] include: add cplusplus guards for extern Jan Engelhardt
2010-10-23 5:44 ` Jan Engelhardt [this message]
2010-10-23 5:44 ` [PATCH 13/13] attr: rename str_null from NULL away Jan Engelhardt
2010-10-23 14:52 ` libmnl: misc code updates Pablo Neira Ayuso
2010-10-23 18:53 ` Jan Engelhardt
2010-10-24 20:33 ` Jozsef Kadlecsik
2010-10-24 22:45 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287812691-14470-13-git-send-email-jengelh@medozas.de \
--to=jengelh@medozas.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).