All of lore.kernel.org
 help / color / mirror / Atom feed
* rtnetlink(3) undeclared variable in example
@ 2010-01-15 13:34 Edward Welbourne
  2010-01-16 17:29 ` Michael Kerrisk
  0 siblings, 1 reply; 3+ messages in thread
From: Edward Welbourne @ 2010-01-15 13:34 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

In man 3 rtnetlink, the example code includes the lines:

           rta = (struct rtattr *)(((char *) &req) +
                                         NLMSG_ALIGN(n->nlmsg_len));

in which the variable "n" is nowhere declared.  It seems likely that
NLMSG_ALIGN(req.nh.nlmsg_len) was intended, albeit I am so deeply
ignorant of relevant systems that I am learning about them by reading
man pages, so I may easilly be wrong ...

I am also acutely aware of the bug already noted on the man page, but
you clearly already know about that one !

	Eddy.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: rtnetlink(3) undeclared variable in example
  2010-01-15 13:34 rtnetlink(3) undeclared variable in example Edward Welbourne
@ 2010-01-16 17:29 ` Michael Kerrisk
       [not found]   ` <cfd18e0f1001160929i4243f219k8c3c6d017a0094d9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kerrisk @ 2010-01-16 17:29 UTC (permalink / raw)
  To: eddy-4vTceeIZeJ0AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, Andi Kleen

Hello Edward,

On Fri, Jan 15, 2010 at 2:34 PM, Edward Welbourne <eddy-4vTceeIZeJ0AvxtiuMwx3w@public.gmane.org> wrote:
> In man 3 rtnetlink, the example code includes the lines:
>
>           rta = (struct rtattr *)(((char *) &req) +
>                                         NLMSG_ALIGN(n->nlmsg_len));
>
> in which the variable "n" is nowhere declared.  It seems likely that
> NLMSG_ALIGN(req.nh.nlmsg_len) was intended, albeit I am so deeply
> ignorant of relevant systems that I am learning about them by reading
> man pages, so I may easilly be wrong ...

My guess is that your interpretation is correct, and indeed there are
a few other pieces that look to need similar fixes. I've applied the
patch below, and CCed Andi, who may be offer further
input/confirmation.

> I am also acutely aware of the bug already noted on the man page, but
> you clearly already know about that one !

Yup.

Cheers,

Michael

--- a/man3/rtnetlink.3
+++ b/man3/rtnetlink.3
@@ -84,6 +84,9 @@ This manual page is incomplete.

 Creating a rtnetlink message to set the MTU of a device:
 .nf
+    #include <linux/rtnetlink.h>
+
+    ...

     struct {
         struct nlmsghdr  nh;
@@ -99,18 +102,18 @@ Creating a rtnetlink message to set the MTU of a device:
     memset(&req, 0, sizeof(req));
     req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
     req.nh.nlmsg_flags = NLM_F_REQUEST;
-    req.nh.nlmsg_type = RTML_NEWLINK;
+    req.nh.nlmsg_type = RTM_NEWLINK;
     req.if.ifi_family = AF_UNSPEC;
     req.if.ifi_index = INTERFACE_INDEX;
     req.if.ifi_change = 0xffffffff; /* ???*/
     rta = (struct rtattr *)(((char *) &req) +
-                                  NLMSG_ALIGN(n\->nlmsg_len));
+                                  NLMSG_ALIGN(req.nh.nlmsg_len));
     rta\->rta_type = IFLA_MTU;
     rta\->rta_len = sizeof(unsigned int);
-    req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) +
+    req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
                                   RTA_LENGTH(sizeof(mtu));
     memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
-    send(rtnetlink_sk, &req, req.n.nlmsg_len);
+    send(rtnetlink_sk, &req, req.nh.nlmsg_len);
 .fi
 .SH "SEE ALSO"
 .BR netlink (3),
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: rtnetlink(3) undeclared variable in example
       [not found]   ` <cfd18e0f1001160929i4243f219k8c3c6d017a0094d9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-01-18 16:24     ` Edward Welbourne
  0 siblings, 0 replies; 3+ messages in thread
From: Edward Welbourne @ 2010-01-18 16:24 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w
  Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, andi-Vw/NltI1exuRpAAqCnN02g

> I've applied the patch below,

I also note that the NLMSG_ALIGN line I initially pointed out is
significantly more indented than to match the open paren that
starts the argument list of which it's a part: <suggest>

     req.if.ifi_change = 0xffffffff; /* ???*/
     rta = (struct rtattr *)(((char *) &req) +
-                                  NLMSG_ALIGN(n\->nlmsg_len));
+                            NLMSG_ALIGN(req.nh.nlmsg_len));
     rta\->rta_type = IFLA_MTU;
     rta\->rta_len = sizeof(unsigned int);

</suggest> but it *is* just layout ...

	Eddy.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-18 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-15 13:34 rtnetlink(3) undeclared variable in example Edward Welbourne
2010-01-16 17:29 ` Michael Kerrisk
     [not found]   ` <cfd18e0f1001160929i4243f219k8c3c6d017a0094d9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-01-18 16:24     ` Edward Welbourne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.