1 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
2 .\" Permission is granted to distribute possibly modified copies
3 .\" of this page provided the header is included verbatim,
4 .\" and in case of nontrivial modification author and date
5 .\" of the modification is added to the header.
6 .\" $Id: cmsg.3,v 1.3 2001/01/14 05:30:39 hanataka Exp $
8 .\" Japanese Version Copyright (c) 1999 Shouichi Saito
9 .\" all rights reserved.
10 .\" Translated Mon Jul 26 21:58:26 JST 1999
11 .\" by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
12 .\" Proofed Tue Aug 17 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
14 .TH CMSG 3 2008-11-20 "Linux" "Linux Programmer's Manual"
16 CMSG_ALIGN, CMSG_SPACE, CMSG_NXTHDR, CMSG_FIRSTHDR \- Êä½õ¥Ç¡¼¥¿¤Ë¥¢¥¯¥»¥¹¤¹¤ë¡£
18 .B #include <sys/socket.h>
20 .BI "struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *" msgh );
22 .BI "struct cmsghdr *CMSG_NXTHDR(struct msghdr *" msgh ", struct cmsghdr *" cmsg );
24 .BI "size_t CMSG_ALIGN(size_t " length );
26 .BI "size_t CMSG_SPACE(size_t " length );
28 .BI "size_t CMSG_LEN(size_t " length );
30 .BI "unsigned char *CMSG_DATA(struct cmsghdr *" cmsg );
34 socklen_t cmsg_len; /* data byte count, including header */
35 int cmsg_level; /* originating protocol */
36 int cmsg_type; /* protocol-specific type */
37 /* followed by unsigned char cmsg_data[]; */
41 ¤³¤ì¤é¤Î¥Þ¥¯¥í¤ÏÀ©¸æ¥á¥Ã¥»¡¼¥¸
42 (Êä½õ¥Ç¡¼¥¿ (ancillary data) ¤È¤â¸Æ¤Ð¤ì¤ë) ¤òºî¤ê¡¢
43 ¤½¤ì¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤Ë»È¤ï¤ì¤ë¡£
44 À©¸æ¥á¥Ã¥»¡¼¥¸¤Ï¥½¥±¥Ã¥È¤Ë¤Î¤ë¥Ç¡¼¥¿¤Ç¤Ï¤Ê¤¤¡£
45 ¤³¤ÎÀ©¸æ¾ðÊó¤Ï¡¢ÅþÃ夷¤¿¥Ñ¥±¥Ã¥È¤Ø¤Î¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¡¢ÍÍ¡¹¤Ê¤¢¤Þ¤ê
46 »È¤ï¤ì¤Ê¤¤¥Ø¥Ã¥À¡¼¥Õ¥£¡¼¥ë¥É¡¢¥¨¥é¡¼µ½Ò¤Î³ÈÄ¥¡¢¥Õ¥¡¥¤¥ë¥Ç¥¹¥¯¥ê
47 ¥×¥¿¤Î½¸¹ç¤ä¡¢UNIX¤Ë¤ª¤±¤ë¿®Íê¾ðÊó (credential) ¤ò´Þ¤ó¤Ç¤¤¤ë¡£
48 À©¸æ¥á¥Ã¥»¡¼¥¸¤Ï¡¢Î㤨¤Ð IP ¥ª¥×¥·¥ç¥ó¤Î¤è¤¦¤ÊÄɲåإåÀ¡¼¥Õ¥£¡¼¥ë¥É¤ò
49 Á÷¤ë¤Î¤Ë»È¤¦»ö¤¬¤Ç¤¤ë¡£
54 ¤ò¸Æ¤Ó½Ð¤·¤Æ¼õ¤±¼è¤ë¡£
55 ¾ÜºÙ¤Ï¤½¤ì¤é¤Î¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤ò»²¾È¡£
59 ¹½Â¤ÂΤΥ·¡¼¥±¥ó¥¹¤ËÄɲåǡ¼¥¿¤¬Éղ䵤줿¤â¤Î¤Ç¤¢¤ë¡£
60 ¤³¤Î¥·¡¼¥±¥ó¥¹¤Ë¤Ï¤³¤Î¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤Ë½ñ¤«¤ì¤Æ¤¤¤ë
61 ¥Þ¥¯¥í¤ò»È¤Ã¤Æ¥¢¥¯¥»¥¹¤¹¤Ù¤¤Ç¡¢Ä¾ÀÜ¥¢¥¯¥»¥¹¤¹¤Ù¤¤Ç¤Ï¤Ê¤¤¡£
62 »ÈÍѲÄǽ¤ÊÀ©¸æ¥á¥Ã¥»¡¼¥¸¤Î¥¿¥¤¥×¤Ë¤Ä¤¤¤Æ¤Ï¡¢
63 ¤½¤ì¤¾¤ì¤Î¥×¥í¥È¥³¥ë¤Î¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤ò»²¾È¤Î¤³¤È¡£
64 ÀܳËè¤ÎºÇÂçÊä½õÍѥХåե¡¥µ¥¤¥º¤Ï
65 .I /proc/sys/net/core/optmem_max
73 ¤Ë´ØÏ¢¤·¤¿Êä½õ¥Ç¡¼¥¿¥Ð¥Ã¥Õ¥¡Ãæ¤Î¡¢ºÇ½é¤Î
83 ¥Ð¥Ã¥Õ¥¡¤Ë½½Ê¬¤Ê¶õ¤¤¬Ìµ¤¤¾ì¹ç¡¢NULL ¤òÊÖ¤¹¡£
86 ¤ËŤµ¤òÍ¿¤¨¤ë¤È¡¢É¬Íפʥ¢¥é¥¤¥ó¥á¥ó¥È¤ò²ÃÌ£¤·¤¿Ä¹¤µ¤òÊÖ¤·¤Æ¤¯¤ë¡£
90 ¤Ï¡¢Í¿¤¨¤¿¥Ç¡¼¥¿Ä¹¤¬Àê¤á¤ë¤Î¤ËɬÍפÊÊä½õÍ×ÁÇ (ancillary element) ¤Î
91 ¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£¤³¤ì¤ÏÄê¿ô¼°¤Ç¤¢¤ë¡£
96 ¤Î¥Ç¡¼¥¿Éôʬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
103 ¥á¥ó¥Ð¤Ë¥Ç¡¼¥¿¤ò³ÊǼ¤¹¤ëºÝ¤ËɬÍפÊÃͤòÊÖ¤¹¡£¥¢¥é¥¤¥ó¥á¥ó¥È¤â¹Íθ¤ËÆþ¤ì
105 °ú¿ô¤È¤·¤Æ¥Ç¡¼¥¿Ä¹¤ò¤È¤ë¡£¤³¤ì¤ÏÄê¿ô¼°¤Ç¤¢¤ë¡£
107 Êä½õ¥Ç¡¼¥¿¤òºî¤ë¤¿¤á¤Ë¤ÏºÇ½é¤Ë
111 ¤ò¡¢À©¸æ¥á¥Ã¥»¡¼¥¸¥Ð¥Ã¥Õ¥¡¤ÎŤµ¤Ç½é´ü²½¤¹¤ë¡£
115 ¤ËÍѤ¤¤ë¤ÈºÇ½é¤ÎÀ©¸æ¥á¥Ã¥»¡¼¥¸¤¬ÆÀ¤é¤ì¡¢
117 ¤ò»È¤¦¤È¼¡¤ÎÀ©¸æ¥á¥Ã¥»¡¼¥¸¤¬ÆÀ¤é¤ì¤ë¡£
118 ¤½¤ì¤¾¤ì¤ÎÀ©¸æ¥á¥Ã¥»¡¼¥¸¤Ç¤Ï¡¢
125 ¥Ø¥Ã¥À¡¼¥Õ¥£¡¼¥ë¥É¡¢¤½¤·¤Æ¥Ç¡¼¥¿Éôʬ¤ËÂФ·¤Æ¤â
127 ¤ò»È¤Ã¤Æ½é´ü²½¤ò¤¹¤ë¡£
132 ¥Õ¥£¡¼¥ë¥É¤Ë¡¢¥Ð¥Ã¥Õ¥¡Ãæ¤ÎÀ©¸æ¥á¥Ã¥»¡¼¥¸¤ÎŤµ¤Î
134 ¤Î¹ç·×¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£
140 À©¸æ¥á¥Ã¥»¡¼¥¸¥Ð¥Ã¥Õ¥¡¤¬Á´¤Æ¤Î¥á¥Ã¥»¡¼¥¸¤òǼ¤á¤ë¤Î¤Ë¤Ïû¤¹¤®¤ë¾ì¹ç¡¢
146 ¥Õ¥é¥°¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£
148 ¤³¤ÎÊä½õ¥Ç¡¼¥¿¥â¥Ç¥ë¤Ï¡¢POSIX.1g draft, 4.4BSD-Lite, RFC\ 2292 ¤Ë
149 µ½Ò¤µ¤ì¤Æ¤¤¤ë IPv6 advanced API, ¤½¤·¤Æ SUSv2
152 ¤Ï Linux ¤Î³ÈÄ¥¤Ç¤¢¤ë¡£
154 °Ü¿¢À¤Î¤¿¤á¤Ë¡¢Êä½õ¥Ç¡¼¥¿¤Ø¤Î¥¢¥¯¥»¥¹¤Ë¤Ï¡¢
155 ¤³¤³¤Ç½Ò¤Ù¤é¤ì¤Æ¤¤¤ë¥Þ¥¯¥í¤ò»È¤¦¤À¤±¤Ë¤¹¤Ù¤¤Ç¤¢¤ë¡£
157 ¤Ï Linux ¤Ç¤Î³ÈÄ¥¤Ç¤¢¤ê¡¢°Ü¿¢À¤ò¹Í¤¨¤¿¥×¥í¥°¥é¥à¤Ç¤Ï»È¤¦¤Ù¤¤Ç¤Ï¤Ê¤¤¡£
163 ¤ÏÄê¿ô¼°¤Ç¤¢¤ë (¤½¤ì¤é¤Î°ú¿ô¤¬Äê¿ô¤È¤ß¤Ê¤µ¤ì¤ë)¡£
164 ¤³¤Î¤³¤È¤Ï¡¢Âç°èÊÑ¿ô¤Î¥µ¥¤¥º¤òÀë¸À¤¹¤ë¤Î¤Ë»È¤¨¤ë¡£
165 ¤·¤«¤·°Ü¿¢À¤Ï¤Ê¤¯¤Ê¤ë¤À¤í¤¦¡£
167 ¼¡¤Î¥³¡¼¥É¤Ï¡¢¼õ¤±¼è¤Ã¤¿Êä½õ¥Ð¥Ã¥Õ¥¡¤«¤é
169 ¥ª¥×¥·¥ç¥ó¤òõ¤¹¤â¤Î¤Ç¤¢¤ë¡£
174 struct cmsghdr *cmsg;
178 /* Receive auxiliary data in msgh */
179 for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
180 cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
181 if (cmsg\->cmsg_level == IPPROTO_IP
182 && cmsg\->cmsg_type == IP_TTL) {
183 ttlptr = (int *) CMSG_DATA(cmsg);
184 received_ttl = *ttlptr;
190 * Error: IP_TTL not enabled or small buffer
199 ¤ò»È¤¤¡¢¥Õ¥¡¥¤¥ë¥Ç¥¹¥¯¥ê¥×¥¿¤ÎÇÛÎó¤ò
200 UNIX ¥É¥á¥¤¥ó¥½¥±¥Ã¥È¤òÄ̤·¤ÆÁ÷¤ë¤â¤Î¤Ç¤¢¤ë¡£
204 struct msghdr msg = {0};
205 struct cmsghdr *cmsg;
206 int myfds[NUM_FD]; /* Contains the file descriptors to pass. */
207 char buf[CMSG_SPACE(sizeof myfds)]; /* ancillary data buffer */
210 msg.msg_control = buf;
211 msg.msg_controllen = sizeof buf;
212 cmsg = CMSG_FIRSTHDR(&msg);
213 cmsg\->cmsg_level = SOL_SOCKET;
214 cmsg\->cmsg_type = SCM_RIGHTS;
215 cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
216 /* Initialize the payload: */
217 fdptr = (int *) CMSG_DATA(cmsg);
218 memcpy(fdptr, myfds, NUM_FD * sizeof(int));
219 /* Sum of the length of all control messages in the buffer: */
220 msg.msg_controllen = cmsg\->cmsg_len;