How to cast a struct nl_object

Thomas Graf tgraf at infradead.org
Thu Mar 17 09:46:51 EDT 2011


On Thu, Mar 17, 2011 at 06:38:58AM -0700, Joerg Pommnitz wrote:
> If I'm not allowed to access netlink-types.h, then struct nl_object is not part 
> of the public API either. How am I supposed to access obj->ce_msgtype?
> 
> And actually looking at ce_msgtype seems wrong to me. The question I'm asking 
> the
> object is "What are you?", not "How were you made?". Sure, with background 
> knowledge
> one can infer the answer to the first question from the answer to the second, 
> but this seems a convoluted way to go.
> 
> May I suggest that an accessor for nl_object::ce_ops::oo_name would be very 
> useful?

You bring up a good point.

NLHDR_COMMON has been public via <netlink/object-api.h> but struct nl_object
was still defined in netlink-types.h

I've moved it to <netlink/object-api.h> with the commit below.

You may access the object type via obj->ce_ops->oo_name now

commit ae5dfb1cc7268c5134a1ee1c911f3792b80ff7ea
Author: Thomas Graf <tgraf at suug.ch>
Date:   Thu Mar 17 14:44:56 2011 +0100

    Make struct nl_object public, NLHDR_COMMON has been public anyway

diff --git a/include/netlink-types.h b/include/netlink-types.h
index 24911b9..de17f9a 100644
--- a/include/netlink-types.h
+++ b/include/netlink-types.h
@@ -101,11 +101,6 @@ struct nl_parser_param;
 
 #define NL_OBJ_MARK            1
 
-struct nl_object
-{
-       NLHDR_COMMON
-};
-
 struct nl_data
 {
        size_t                  d_size;
diff --git a/include/netlink/object-api.h b/include/netlink/object-api.h
index b3337f0..70a4ddd 100644
--- a/include/netlink/object-api.h
+++ b/include/netlink/object-api.h
@@ -190,6 +190,12 @@ extern "C" {
        int                     ce_flags;       \
        uint32_t                ce_mask;
 
+struct nl_object
+{
+       NLHDR_COMMON
+};
+
+
 /**
  * Return true if attribute is available in both objects
  * @arg A              an object





More information about the libnl mailing list