NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: aligning control message ancillary data

Taylor R Campbell wrote:
> Instead, the correct idiom, I believe, is
>    struct msghdr msg;
>    char control[CMSG_SPACE (sizeof (int))];
>    msg.msg_control = (void *) control;
>    msg.msg_controllen = CMSG_LEN (sizeof (int));
>    /* et cetera */
>    cm_ptr = CMSG_FIRSTHDR (&msg);
>    cm_ptr->cmsg_len = CMSG_LEN (sizeof (int));
>    /* ... */
>    (*((int *) CMSG_DATA (cm_ptr))) = fd;

AFAICT, your code agrees with the of the esteemed W. Richard Stevens!  Cf.
lib/write_fd.c in the above tarball.  What's odd is that your tests failed
on NetBSD and his works.  

His write_fd function is used by the unixdomain/mycat program.  I built
and ran it on OS X (PPC) and NetBSD 2.0 (i386).  

In case you want to trace the logic, you need only these files:


(To build the code, I had only to comment out the IPV6 defines in
config.h.  The attached Makefile implements the instructions in the

> Am I doing something wrong in my test programs, 

Not that I found, but it would seem so.  

> is this a bug in NetBSD, 

I thought so until I ran Stevens's code.  

> should the RFC 2292 macros be documented in the man pages?

Whyever not?  



Attachment: Makefile.begin
Description: Binary data

Home | Main Index | Thread Index | Old Index