OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / cmsg.3
index 8c63eff..279c449 100644 (file)
@@ -1,12 +1,16 @@
 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
+.\"
+.\" %%%LICENSE_START(VERBATIM_ONE_PARA)
 .\" Permission is granted to distribute possibly modified copies
 .\" of this page provided the header is included verbatim,
 .\" and in case of nontrivial modification author and date
 .\" of the modification is added to the header.
+.\" %%%LICENSE_END
+.\"
 .\" $Id: cmsg.3,v 1.8 2000/12/20 18:10:31 ak Exp $
-.TH CMSG 3 2008-11-20 "Linux" "Linux Programmer's Manual"
+.TH CMSG 3 2014-12-31 "Linux" "Linux Programmer's Manual"
 .SH NAME
-CMSG_ALIGN, CMSG_SPACE, CMSG_NXTHDR, CMSG_FIRSTHDR \- Access ancillary data
+CMSG_ALIGN, CMSG_SPACE, CMSG_NXTHDR, CMSG_FIRSTHDR \- access ancillary data
 .SH SYNOPSIS
 .B #include <sys/socket.h>
 .sp
@@ -48,8 +52,8 @@ See their manual pages for more information.
 Ancillary data is a sequence of
 .I struct cmsghdr
 structures with appended data.
-This sequence should only be accessed
-using the macros described in this manual page and never directly.
+This sequence should be accessed
+using only the macros described in this manual page and never directly.
 See the specific protocol man pages for the available control message types.
 The maximum ancillary buffer size allowed per socket can be set using
 .IR /proc/sys/net/core/optmem_max ;
@@ -105,7 +109,7 @@ Use
 on the
 .I msghdr
 to get the first control message and
-.BR CMSG_NEXTHDR ()
+.BR CMSG_NXTHDR ()
 to get all subsequent ones.
 In each control message, initialize
 .I cmsg_len
@@ -134,16 +138,16 @@ flag is set in the
 .I msg_flags
 member of the
 .IR msghdr .
-.SH "CONFORMING TO"
+.SH CONFORMING TO
 This ancillary data model conforms to the POSIX.1g draft, 4.4BSD-Lite,
-the IPv6 advanced API described in RFC\ 2292 and the SUSv2.
+the IPv6 advanced API described in RFC\ 2292 and SUSv2.
 .BR CMSG_ALIGN ()
 is a Linux extension.
 .SH NOTES
-For portability, ancillary data should be accessed only using the macros
+For portability, ancillary data should be accessed using only the macros
 described here.
 .BR CMSG_ALIGN ()
-is a Linux extension and should be not used in portable programs.
+is a Linux extension and should not be used in portable programs.
 .PP
 In Linux,
 .BR CMSG_LEN (),
@@ -153,7 +157,7 @@ and
 are constant expressions (assuming their argument is constant);
 this could be used to declare the size of global
 variables.
-This may be not portable, however.
+This may not be portable, however.
 .SH EXAMPLE
 This code looks for the
 .B IP_TTL
@@ -194,11 +198,16 @@ UNIX domain socket using
 struct msghdr msg = {0};
 struct cmsghdr *cmsg;
 int myfds[NUM_FD]; /* Contains the file descriptors to pass. */
-char buf[CMSG_SPACE(sizeof myfds)];  /* ancillary data buffer */
+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;
 int *fdptr;
 
-msg.msg_control = buf;
-msg.msg_controllen = sizeof buf;
+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;
@@ -210,8 +219,17 @@ memcpy(fdptr, myfds, NUM_FD * sizeof(int));
 msg.msg_controllen = cmsg\->cmsg_len;
 .fi
 .in
-.SH "SEE ALSO"
+.SH SEE ALSO
 .BR recvmsg (2),
 .BR sendmsg (2)
 .PP
 RFC\ 2292
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.