From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: <mtk.manpages@gmail.com>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
nd <nd@arm.com>, Rich Felker <dalias@libc.org>
Subject: Re: [PATCH 2/3] network: recvmsg and sendmsg standard compliance (BZ#16919)
Date: Fri, 22 Apr 2016 10:25:00 -0000 [thread overview]
Message-ID: <5719FC05.1020002@arm.com> (raw)
In-Reply-To: <CAKgNAkgp_CrJweUUrqKwAbwG7QjSGeztSFp+wPJBhoADk-Lzow@mail.gmail.com>
On 22/04/16 09:04, Michael Kerrisk (man-pages) wrote:
> On 21 April 2016 at 16:01, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
>> it is not clear from the standard how the
>> msg_control buffer may be allocated (since
>> only CMSG_* macros can access it), on linux
>> the kernel makes a copy so it does not care
>> about alignment in user-space, but the struct
>> alignment is still visible in the c and c++ abi.
>>
>> msg_control usage should be probably documented
>> in the linux man-page: glibc sunrpc sometimes
>> uses plain char[], nscd uses a union with struct
>> cmsghdr, i think neither of them makes a
>>
>> CMSG_FIRSTHDR (&msg)->cmsg_len
>>
>> access strictly iso c confrom, but the later at
>> least uses correct alignment.
>>
>> maybe a posix issue should be filed to the
>> austin group.
>
> Below are the current snippets of code shown in the cmsg(3) man page.
> Could you please tell me more exactly what you think needs fixing?
>
thanks, this is what i was looking for.
(i missed cmsg(3), only looked at recvmsg(2) and sendmsg(2).)
this means some code in glibc and iproute2 should be fixed
to use such a union. (what a nasty interface.)
> [[
> EXAMPLE
> This code looks for the IP_TTL option in a received ancillary
> buffer:
>
> struct msghdr msgh;
> struct cmsghdr *cmsg;
> int *ttlptr;
> int received_ttl;
>
> /* Receive auxiliary data in msgh */
>
> for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
> cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
> if (cmsg->cmsg_level == IPPROTO_IP
> && cmsg->cmsg_type == IP_TTL) {
> ttlptr = (int *) CMSG_DATA(cmsg);
> received_ttl = *ttlptr;
> break;
> }
> }
>
> if (cmsg == NULL) {
> /* Error: IP_TTL not enabled or small buffer or I/O error */
> }
>
> The code below passes an array of file descriptors over a UNIX
> domain socket using SCM_RIGHTS:
>
> struct msghdr msg = {0};
> struct cmsghdr *cmsg;
> int myfds[NUM_FD]; /* Contains the file descriptors to pass */
> int *fdptr;
> union { /* Ancillary data buffer, wrapped in a union
> in order to ensure it is suitably aligned */
> char buf[CMSG_SPACE(sizeof myfds)];
> struct cmsghdr align;
> } u;
>
> msg.msg_control = u.buf;
> msg.msg_controllen = sizeof u.buf;
> cmsg = CMSG_FIRSTHDR(&msg);
> cmsg->cmsg_level = SOL_SOCKET;
> cmsg->cmsg_type = SCM_RIGHTS;
> cmsg->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
> fdptr = (int *) CMSG_DATA(cmsg); /* Initialize the payload */
> memcpy(fdptr, myfds, NUM_FD * sizeof(int));
> ]]
>
> Cheers,
>
> Michael
>
next prev parent reply other threads:[~2016-04-22 10:25 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-28 14:34 [PATCH v4 0/3] Fix {recv,send}{m}msg " Adhemerval Zanella
2016-03-28 14:34 ` [PATCH 1/3] Adjust kernel-features.h defaults for recvmsg and sendmsg Adhemerval Zanella
2016-03-29 21:32 ` Joseph Myers
2016-03-29 21:50 ` Adhemerval Zanella
2016-03-29 21:53 ` Adhemerval Zanella
2016-03-29 22:16 ` Andreas Schwab
2016-03-28 14:34 ` [PATCH 2/3] network: recvmsg and sendmsg standard compliance (BZ#16919) Adhemerval Zanella
2016-04-07 9:28 ` Szabolcs Nagy
2016-04-07 12:23 ` Adhemerval Zanella
2016-04-07 9:56 ` Florian Weimer
2016-04-07 11:37 ` Szabolcs Nagy
2016-04-07 12:29 ` Adhemerval Zanella
2016-04-21 14:01 ` Szabolcs Nagy
2016-04-21 20:07 ` Adhemerval Zanella
2016-04-22 8:04 ` Michael Kerrisk (man-pages)
2016-04-22 10:25 ` Szabolcs Nagy [this message]
2016-04-22 13:20 ` Michael Kerrisk (man-pages)
2016-04-22 13:40 ` Szabolcs Nagy
2016-04-21 17:15 ` Rich Felker
2016-05-02 19:17 ` Adhemerval Zanella
2016-06-07 13:31 ` Zack Weinberg
2016-06-07 14:21 ` Adhemerval Zanella
2016-06-08 20:15 ` Zack Weinberg
2016-06-08 20:58 ` Adhemerval Zanella
2016-06-09 3:18 ` Carlos O'Donell
2016-06-09 13:35 ` Zack Weinberg
2016-06-10 18:01 ` Carlos O'Donell
2016-06-10 18:19 ` Joseph Myers
2016-06-10 18:45 ` Carlos O'Donell
2016-06-10 20:17 ` Joseph Myers
2016-06-13 14:43 ` Carlos O'Donell
2016-06-09 14:21 ` Joseph Myers
2016-06-09 13:25 ` Zack Weinberg
2016-06-09 14:25 ` Adhemerval Zanella
2016-03-28 14:34 ` [PATCH 3/3] network: recvmmsg and sendmmsg " Adhemerval Zanella
2016-04-01 13:51 ` [PATCH v4 0/3] Fix {recv,send}{m}msg " Adhemerval Zanella
2016-04-06 18:24 ` Adhemerval Zanella
2016-04-21 13:21 ` Adhemerval Zanella
2016-05-24 19:44 ` Adhemerval Zanella
2016-05-26 13:50 ` Joseph Myers
2016-05-26 14:23 ` Adhemerval Zanella
2016-05-26 14:37 ` Adhemerval Zanella
2016-05-27 9:13 ` Florian Weimer
2016-06-08 8:36 ` Florian Weimer
2016-06-08 12:37 ` Joseph Myers
2016-06-08 15:57 ` Mike Frysinger
2016-06-08 19:45 ` Florian Weimer
2016-06-08 20:19 ` Adhemerval Zanella
2016-06-08 20:27 ` Florian Weimer
2016-06-08 21:05 ` Adhemerval Zanella
-- strict thread matches above, loose matches on Subject: below --
2016-03-25 13:57 [PATCH v3 " Adhemerval Zanella
2016-03-25 13:57 ` [PATCH 2/3] network: recvmsg and sendmsg " Adhemerval Zanella
2016-03-23 14:31 [PATCH v2 0/3] Fix {recv,send}{m}msg " Adhemerval Zanella
2016-03-23 14:31 ` [PATCH 2/3] network: recvmsg and sendmsg " Adhemerval Zanella
2016-03-23 15:00 ` Andreas Schwab
2016-03-23 18:20 ` Adhemerval Zanella
2016-03-23 21:51 ` Joseph Myers
2016-03-24 12:58 ` Adhemerval Zanella
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=5719FC05.1020002@arm.com \
--to=szabolcs.nagy@arm.com \
--cc=adhemerval.zanella@linaro.org \
--cc=dalias@libc.org \
--cc=libc-alpha@sourceware.org \
--cc=mtk.manpages@gmail.com \
--cc=nd@arm.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).