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;

http://www.kohala.com/start/unpv12e.html
http://www.kohala.com/start/unpv12e/unpv12e.tar.gz

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:

unixdomain/mycat.c
unixdomain/myopen.c
unixdomain/openfile.c
lib/read_fd.c
lib/write_fd.c

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

> 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?  

HTH.  

--jkl

Attachment: Makefile.begin
Description: Binary data



Home | Main Index | Thread Index | Old Index