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: packet.7,v 1.12 2001/06/19 07:07:38 argrath Exp $
8 .\" Japanese Version Copyright (c) 1999 NAKANO Takeo all rights reserved.
9 .\" Translated 1999-12-06, NAKANO Takeo <nakano@apm.seikei.ac.jp>
10 .\" Updated 2001-02-13, Kentaro Shirakata <argrath@ub32.org>
11 .\" Updated 2005-02-21, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
13 .\"WORD physical layer ʪÍýÁØ
14 .\"WORD link level header(s) ¥ê¥ó¥¯¥ì¥Ù¥ë¥Ø¥Ã¥À
15 .\"WORD phyxical header(s) ʪÍý¥Ø¥Ã¥À
16 .\"WORD effective user id ¼Â¸ú¥æ¡¼¥¶¡¼ ID
17 .\"WORD capability ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£
18 .\"WORD pending error Ãٱ䥨¥é¡¼
19 .\"WORD promiscuous mode ̵º¹Ê̥⡼¥É
21 .TH PACKET 7 2008-08-08 "Linux" "Linux Programmer's Manual"
24 .\"O packet, AF_PACKET \- packet interface on device level.
25 packet, AF_PACKET \- ¥Ç¥Ð¥¤¥¹¥ì¥Ù¥ë¤Î¥Ñ¥±¥Ã¥È¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹
29 .B #include <sys/socket.h>
31 .B #include <netpacket/packet.h>
33 .B #include <net/ethernet.h> /* the L2 protocols */
35 .BI "packet_socket = socket(AF_PACKET, int " socket_type ", int "protocol );
39 .\"O Packet sockets are used to receive or send raw packets at the device driver
40 .\"O (OSI Layer 2) level.
41 .\"O They allow the user to implement protocol modules in user space
42 .\"O on top of the physical layer.
43 packet ¥½¥±¥Ã¥È¤Ï¡¢¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð (OSI ¥ì¥¤¥ä 2) ¥ì¥Ù¥ë¤Ç
44 À¸¤Î¥Ñ¥±¥Ã¥È (raw packet) ¤òÁ÷¼õ¿®¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
45 packet ¥½¥±¥Ã¥È¤ò»È¤¦¤È¡¢¥æ¡¼¥¶¡¼¶õ´Ö¤ÇʪÍýÁؤξå¤Ë
46 ¥×¥í¥È¥³¥ë¥â¥¸¥å¡¼¥ë¤ò¼ÂÁõ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
52 .\"O for raw packets including the link level header or
54 .\"O for cooked packets with the link level header removed.
56 .\"O header information is available in a common format in a
57 .\"O .IR sockaddr_ll .
59 .\"O is the IEEE 802.3 protocol number in network order.
61 .\"O .I <linux/if_ether.h>
62 .\"O include file for a list of allowed protocols.
65 .\"O .B htons(ETH_P_ALL)
66 .\"O then all protocols are received.
67 .\"O All incoming packets of that protocol type will be passed to the packet
68 .\"O socket before they are passed to the protocols implemented in the kernel.
74 ¤Î¤¤¤º¤ì¤«¤ò»ØÄꤹ¤ë¡£
76 ¤Ï¥ê¥ó¥¯¥ì¥Ù¥ë¥Ø¥Ã¥À¤ò´Þ¤à raw ¥Ñ¥±¥Ã¥È¤ò¡¢
78 ¤Ï¥ê¥ó¥¯¥ì¥Ù¥ë¥Ø¥Ã¥À¤¬ºï½ü¤µ¤ì¤¿²Ã¹©ºÑ¤ß¥Ñ¥±¥Ã¥È¤ò¼¨¤¹¡£
79 ¥ê¥ó¥¯¥ì¥Ù¥ë¥Ø¥Ã¥À¾ðÊó¤Ï
81 ¤Ç¶¦Ä̤Υե©¡¼¥Þ¥Ã¥È¤ÇÆþ¼ê¤Ç¤¤ë¡£
83 ¤Ë¤Ï IEEE 802.3 ¥×¥í¥È¥³¥ëÈÖ¹æ¤ò
84 ¥Í¥Ã¥È¥ï¡¼¥¯¥Ð¥¤¥È¥ª¡¼¥À¡¼¤Ç»ØÄꤹ¤ë¡£
85 »ØÄê¤Ç¤¤ë¥×¥í¥È¥³¥ë¤Î¥ê¥¹¥È¤Ï¡¢¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë
89 ¤Ë¤¹¤ë¤È¡¢Á´¤Æ¤Î¥×¥í¥È¥³¥ë¤¬¼õ¿®¤µ¤ì¤ë¡£
90 ³°Éô¤«¤éÍ褿¥Ñ¥±¥Ã¥È¤Î¤¦¤Á»ØÄꤷ¤¿¥×¥í¥È¥³¥ë¤Î¤â¤Î¤Ï¡¢
91 ¥«¡¼¥Í¥ë¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¥×¥í¥È¥³¥ë¤ËÅϤµ¤ì¤ëÁ°¤ÎÃʳ¬¤Ç¡¢
92 packet ¥½¥±¥Ã¥È¤ËÅϤµ¤ì¤ë¡£
94 .\"O Only processes with effective UID 0 or the
96 .\"O capability may open packet sockets.
97 packet ¥½¥±¥Ã¥È¤ò¥ª¡¼¥×¥ó¤Ç¤¤ë¤Î¤Ï¡¢
98 ¼Â¸ú¥æ¡¼¥¶¡¼ID ¤¬ 0 ¤Î¥×¥í¥»¥¹¤«¡¢
100 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£¤ò»ý¤Ä¥×¥í¥»¥¹¤À¤±¤Ç¤¢¤ë¡£
103 .\"O packets are passed to and from the device driver without any changes in
104 .\"O the packet data.
105 .\"O When receiving a packet, the address is still parsed and
106 .\"O passed in a standard
108 .\"O address structure.
109 .\"O When transmitting a packet, the user supplied buffer
110 .\"O should contain the physical layer header.
111 .\"O That packet is then
112 .\"O queued unmodified to the network driver of the interface defined by the
113 .\"O destination address.
114 .\"O Some device drivers always add other headers.
116 .\"O is similar to but not compatible with the obsolete
117 .\"O .B AF_INET/SOCK_PACKET
120 ¥Ñ¥±¥Ã¥È¤Ç¤Ï¡¢¥Ñ¥±¥Ã¥È¤ò¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤È¼õ¤±ÅϤ·¤¹¤ëºÝ¡¢
121 ¥Ñ¥±¥Ã¥È¥Ç¡¼¥¿¤ËÊѹ¹¤¬¹Ô¤ï¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£
122 ¥Ñ¥±¥Ã¥È¤Î¼õ¿®»þ¤Ë¤Ï¡¢¥¢¥É¥ì¥¹¤Î²òÀϤÀ¤±¤Ï¹Ô¤ï¤ì¡¢
125 ¥¢¥É¥ì¥¹¹½Â¤ÂΤËÅϤµ¤ì¤ë¡£¥Ñ¥±¥Ã¥È¤ÎÁ÷¿®»þ¤Ë¤Ï¡¢¥æ¡¼¥¶¤¬»ØÄꤹ¤ë
126 ¥Ð¥Ã¥Õ¥¡¤ËʪÍýÁؤΥإåÀ¤¬´Þ¤Þ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£
127 ¥Ñ¥±¥Ã¥È¤Ï¤½¤Î¤Þ¤Þ½¤Àµ¤ò¼õ¤±¤º¤Ë¡¢¹Ô¤À襢¥É¥ì¥¹¤«¤é·èÄꤵ¤ì¤ë
128 ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥É¥é¥¤¥Ð¤Ë¥¥å¡¼¥¤¥ó¥°¤µ¤ì¤ë¡£
129 ¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤Ë¤è¤Ã¤Æ¤Ï¡¢Â¾¤Î¥Ø¥Ã¥À¤ò¾ï¤ËÄɲ乤ë¤â¤Î¤â¤¢¤ë¡£
131 ¤Ï Linux 2.0 ¤Î obosolete ¤Ê
132 .B AF_INET/SOCK_PACKET
133 ¤È»÷¤Æ¤¤¤ë¤¬¡¢¸ß´¹À¤¬¤¢¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
136 .\"O operates on a slightly higher level.
137 .\"O The physical header is removed before the packet is passed to the user.
138 .\"O Packets sent through a
140 .\"O packet socket get a suitable physical layer header based on the
141 .\"O information in the
143 .\"O destination address before they are queued.
145 ¤Ï¤ä¤ä¹â°Ì¤Î¥ì¥Ù¥ë¤ÇÆ°ºî¤¹¤ë¡£ÊªÍý¥Ø¥Ã¥À¤Ï¡¢¥Ñ¥±¥Ã¥È¤¬¥æ¡¼¥¶¡¼¤Ë
146 ÅϤµ¤ì¤ëÁ°¤Ëºï½ü¤µ¤ì¤ë¡£
148 ¤Î packet ¥½¥±¥Ã¥È¤òÄ̤·¤ÆÁ÷¤é¤ì¤ë¥Ñ¥±¥Ã¥È¤Ï¡¢
150 ¤Î¹Ô¤À襢¥É¥ì¥¹¤Î¾ðÊó¤Ë´ð¤Å¤¡¢Å¬ÀÚ¤ÊʪÍýÁؤΥإåÀ¤¬Éղ䵤ì¤Æ¤«¤é¡¢
153 .\"O By default all packets of the specified protocol type
154 .\"O are passed to a packet socket.
155 .\"O To only get packets from a specific interface use
157 .\"O specifying an address in a
158 .\"O .I struct sockaddr_ll
159 .\"O to bind the packet socket to an interface.
164 .\"O address fields are used for purposes of binding.
165 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢»ØÄꤷ¤¿¥×¥í¥È¥³¥ë·¿¤Î¥Ñ¥±¥Ã¥È¤Ï¤¹¤Ù¤Æ packet
166 ¥½¥±¥Ã¥È¤ËÁ÷¤é¤ì¤ë¡£ÆÃÄê¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤«¤é¤Î¥Ñ¥±¥Ã¥È¤À¤±¤ò
168 .I struct sockaddr_ll
171 ¤ò¸Æ¤Ó¡¢ packet ¥½¥±¥Ã¥È¤ò¤½¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë·ë¤ÓÉÕ¤±¤ë (¥Ð¥¤¥ó¥É¤¹¤ë)¡£
172 ¥Ð¥¤¥ó¥É¤ÎºÝ¤Ë¤Ï¡¢¥¢¥É¥ì¥¹¥Õ¥£¡¼¥ë¥É¤Î¤¦¤Á
180 .\"O operation is not supported on packet sockets.
182 Áàºî¤Ï packet ¥½¥±¥Ã¥È¤Ç¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
186 .\"O flag is passed to
187 .\"O .BR recvmsg (2),
189 .\"O .BR recvfrom (2)
190 .\"O the real length of the packet on the wire is always returned,
191 .\"O even when it is longer than the buffer.
197 ¤ËÅϤµ¤ì¤ë¤È¡¢ (¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤è¤êÂ礤«¤Ã¤¿¤È¤·¤Æ¤â) ¾ï¤Ë¼ÂºÝ¤ËÄÌ¿®¤µ¤ì¤¿
198 ¥Ñ¥±¥Ã¥È¤ÎŤµ¤¬ÊÖ¤µ¤ì¤ë¡£
199 .\"O .SS Address Types
201 .\"O The sockaddr_ll is a device independent physical layer address.
202 sockaddr_ll ¤Ï¥Ç¥Ð¥¤¥¹¤Ë°Í¸¤·¤Ê¤¤ÊªÍýÁؤΥ¢¥É¥ì¥¹¤Ç¤¢¤ë¡£
206 .\"O struct sockaddr_ll {
207 .\"O unsigned short sll_family; /* Always AF_PACKET */
208 .\"O unsigned short sll_protocol; /* Physical layer protocol */
209 .\"O int sll_ifindex; /* Interface number */
210 .\"O unsigned short sll_hatype; /* Header type */
211 .\"O unsigned char sll_pkttype; /* Packet type */
212 .\"O unsigned char sll_halen; /* Length of address */
213 .\"O unsigned char sll_addr[8]; /* Physical layer address */
216 unsigned short sll_family; /* ¾ï¤Ë AF_PACKET */
217 unsigned short sll_protocol; /* ʪÍýÁؤΥץí¥È¥³¥ë */
218 int sll_ifindex; /* ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ÈÖ¹æ */
219 unsigned short sll_hatype; /* ¥Ø¥Ã¥À¼ïÊÌ */
220 unsigned char sll_pkttype; /* ¥Ñ¥±¥Ã¥È¼ïÊÌ */
221 unsigned char sll_halen; /* ¥¢¥É¥ì¥¹¤ÎŤµ */
222 unsigned char sll_addr[8]; /* ʪÍýÁؤΥ¢¥É¥ì¥¹ */
228 .\"O is the standard ethernet protocol type in network order as defined
230 .\"O .I <linux/if_ether.h>
232 .\"O It defaults to the socket's protocol.
234 ¤Ïɸ½àŪ¤Ê¥¤¡¼¥µ¥Í¥Ã¥È¥×¥í¥È¥³¥ë¤Î¥¿¥¤¥×¤Ç¡¢
235 ¥Í¥Ã¥È¥ï¡¼¥¯¥Ð¥¤¥È¥ª¡¼¥À¡¼¤Çµ½Ò¤¹¤ë¡£
237 .I <linux/if_ether.h>
239 ¤³¤ì¤¬¤³¤Î¥½¥±¥Ã¥È¤Î¥×¥í¥È¥³¥ë¤Î¥Ç¥Õ¥©¥ë¥È¤È¤Ê¤ë¡£
242 .\"O is the interface index of the interface
244 .\"O .BR netdevice (7));
245 .\"O 0 matches any interface (only permitted for binding).
247 ¤Ï¤½¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î interface index ¤Ç¤¢¤ë
250 0 ¤Ï (¥Ð¥¤¥ó¥É¤¬µö²Ä¤µ¤ì¤Æ¤¤¤ë) Ǥ°Õ¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë¥Þ¥Ã¥Á¤¹¤ë¡£
253 .\"O is a ARP type as defined in the
254 .\"O .I <linux/if_arp.h>
257 ¤Ï¡¢¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë
259 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë ARP ¼ïÊ̤Ǥ¢¤ë¡£
262 .\"O contains the packet type.
265 .\"O for a packet addressed to the local host,
266 .\"O .B PACKET_BROADCAST
267 .\"O for a physical layer broadcast packet,
268 .\"O .B PACKET_MULTICAST
269 .\"O for a packet sent to a physical layer multicast address,
270 .\"O .B PACKET_OTHERHOST
271 .\"O for a packet to some other host that has been caught by a device driver
272 .\"O in promiscuous mode, and
273 .\"O .B PACKET_OUTGOING
274 .\"O for a packet originated from the local host that is looped back to a packet
276 .\"O These types make only sense for receiving.
278 ¤Ï¥Ñ¥±¥Ã¥È¼ïÊ̤Ǥ¢¤ë¡£»ØÄê¤Ç¤¤ë¼ïÊ̤ϰʲ¼¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë:
280 (¥í¡¼¥«¥ë¥Û¥¹¥È¸þ¤±¤Î¥Ñ¥±¥Ã¥È)¡¢
282 (ʪÍýÁØ¤Î¥Ö¥í¡¼¥É¥¥ã¥¹¥È¥Ñ¥±¥Ã¥È)¡¢
284 (ʪÍýÁؤΥޥë¥Á¥¥ã¥¹¥È¥¢¥É¥ì¥¹¤ËÁ÷¤ë¥Ñ¥±¥Ã¥È)¡¢
286 (¾¤Î¥Û¥¹¥È¤Ë¸þ¤±¤é¤ì¤¿¥Ñ¥±¥Ã¥È¤Î¤¦¤Á¡¢
287 ̵º¹Ê̥⡼¥É (promiscuous mode: ¸å½Ò) ¤Î¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤Ë¤è¤êÊ䤵¤ì¤¿¤â¤Î)¡¢
289 (¥í¡¼¥«¥ë¥Û¥¹¥È¤«¤éȯ¿®¤µ¤ì¡¢
290 packet ¥½¥±¥Ã¥È¤Ë¥ë¡¼¥×¥Ð¥Ã¥¯¤·¤Æ¤¤¿¥Ñ¥±¥Ã¥È)¡£
291 ¤³¤ì¤é¤Î¼ïÊ̤¬°ÕÌ£¤ò»ý¤Ä¤Î¤Ï¼õ¿®»þ¤Î¤ß¤Ç¤¢¤ë¡£
296 .\"O contain the physical layer (e.g., IEEE 802.3) address and its length.
297 .\"O The exact interpretation depends on the device.
301 ¤Ï¡¢ÊªÍýÁؤΠ(¤Ä¤Þ¤ê IEEE 802.3 ¤Î) ¥¢¥É¥ì¥¹¤È¤½¤ÎŤµ¤Ç¤¢¤ë¡£
302 ¸·Ì©¤Ê²ò¼á¤Ï¥Ç¥Ð¥¤¥¹¤Ë°Í¸¤¹¤ë¡£
304 .\"O When you send packets it is enough to specify
305 .\"O .IR sll_family ,
308 .\"O .IR sll_ifindex .
309 ¥Ñ¥±¥Ã¥È¤òÁ÷¤ë¾ì¹ç¤Ï¡¢
314 ¤ò»ØÄꤹ¤ì¤Ð½½Ê¬¤Ç¤¢¤ë¡£
315 .\"O The other fields should be 0.
316 ¤½¤Î¾¤Î¥Õ¥£¡¼¥ë¥É¤Ï 0 ¤Ë¤·¤Æ¤ª¤¯¤Ù¤¤Ç¤¢¤ë¡£
320 .\"O are set on received packets for your information.
324 ¤Ë¤Ï¼õ¿®¤·¤¿¥Ñ¥±¥Ã¥È¤Î¾ðÊó¤¬ÀßÄꤵ¤ì¤ë¡£
335 .\"O .SS Socket Options
336 .SS ¥½¥±¥Ã¥È¥ª¥×¥·¥ç¥ó
337 .\"O Packet sockets can be used to configure physical layer multicasting
338 .\"O and promiscuous mode.
339 .\"O It works by calling
340 .\"O .BR setsockopt (2)
341 .\"O on a packet socket for
343 .\"O and one of the options
344 .\"O .B PACKET_ADD_MEMBERSHIP
345 .\"O to add a binding or
346 .\"O .B PACKET_DROP_MEMBERSHIP
348 .\"O They both expect a
350 .\"O structure as argument:
351 packet ¥½¥±¥Ã¥È¤Ï¡¢ÊªÍýÁؤΥޥë¥Á¥¥ã¥¹¥È¤ä
352 ̵º¹Ê̥⡼¥É (promiscuous mode) ¤òÀßÄꤷ¤Æ»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
355 ¤È°Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤Î¤¤¤º¤ì¤«¤ò»ØÄꤷ¤Æ
358 ¥Ð¥¤¥ó¥É¤òÄɲ乤ë¾ì¹ç¤Ï
359 .B PACKET_ADD_MEMBERSHIP
360 ¤Ç¤¢¤ê¡¢¼è¤êµî¤ë¾ì¹ç¤Ï
361 .B PACKET_DROP_MEMBERSHIP
362 ¤Ç¤¢¤ë¡£¤³¤ì¤é¤Ï¤¤¤º¤ì¤â
364 ¹½Â¤ÂΤò°ú¤¿ô¤Ë¼è¤ë¡£
368 .\"O struct packet_mreq {
369 .\"O int mr_ifindex; /* interface index */
370 .\"O unsigned short mr_type; /* action */
371 .\"O unsigned short mr_alen; /* address length */
372 .\"O unsigned char mr_address[8]; /* physical layer address */
375 int mr_ifindex; /* ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ÈÖ¹æ */
376 unsigned short mr_type; /* Æ°ºî */
377 unsigned short mr_alen; /* ¥¢¥É¥ì¥¹¤ÎŤµ */
378 unsigned char mr_address[8]; /* ʪÍýÁؤΥ¢¥É¥ì¥¹ */
384 .\"O contains the interface index for the interface whose status
385 .\"O should be changed.
388 .\"O parameter specifies which action to perform.
389 .\"O .B PACKET_MR_PROMISC
390 .\"O enables receiving all packets on a shared medium (often known as
391 .\"O "promiscuous mode"),
392 .\"O .B PACKET_MR_MULTICAST
393 .\"O binds the socket to the physical layer multicast group specified in
398 .\"O .B PACKET_MR_ALLMULTI
399 .\"O sets the socket up to receive all multicast packets arriving at
402 ¤Ï¡¢¥¹¥Æ¡¼¥¿¥¹¤òÊѹ¹¤·¤¿¤¤¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î
403 ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ÈÖ¹æ¤Ç¤¢¤ë¡£
405 ¥Ñ¥é¥á¡¼¥¿¤Ï¼Â¹Ô¤¹¤ëÆ°ºî¤ò»ØÄꤹ¤ë:
407 ¤Ï¡¢¶¦Í¤·¤Æ¤¤¤ëÇÞÂΤ«¤é¤ÎÁ´¤Æ¤Î¥Ñ¥±¥Ã¥È¤ò¼õ¿®¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë
408 (¤·¤Ð¤·¤Ð "̵º¹Ê̥⡼¥É (promiscuous mode)" ¤È¸Æ¤Ð¤ì¤ë)¡£
409 .B PACKET_MR_MULTICAST
414 ¤Ç»ØÄꤵ¤ì¤ëʪÍýÁؤΥޥë¥Á¥¥ã¥¹¥È¥Ö¥ë¡¼¥×¤Ë¥Ð¥¤¥ó¥É¤¹¤ë¡£
415 .B PACKET_MR_ALLMULTI
416 ¤Ï socket ¤ò up ¤Ë¤·¤Æ¡¢¤½¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ËÅþ㤷¤¿¤¹¤Ù¤Æ¤Î
417 ¥Þ¥ë¥Á¥¥ã¥¹¥È¥Ñ¥±¥Ã¥È¤ò¼õ¿®¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë¡£
419 .\"O In addition the traditional ioctls
420 .\"O .BR SIOCSIFFLAGS ,
421 .\"O .BR SIOCADDMULTI ,
423 .\"O can be used for the same purpose.
424 ÀΤ«¤é¤¢¤ë ioctl ¤À¤±¤Ç¤Ê¤¯¡¢
428 ¤òƱ¤¸ÌÜŪ¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤¤ë¡£
432 .\"O can be used to receive the timestamp of the last received packet.
434 .\"O .IR "struct timeval" .
436 ¤òÍѤ¤¤ë¤È¡¢ºÇ¸å¤Ë¼õ¿®¤·¤¿¥Ñ¥±¥Ã¥È¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤òÆÀ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
441 .\"O In addition all standard ioctls defined in
442 .\"O .BR netdevice (7)
445 .\"O are valid on packet sockets.
450 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ëɸ½à¤Î ioctl ¤Ï¤¤¤º¤ì¤â
451 packet ¥½¥±¥Ã¥È¤Ë»ØÄê²Äǽ¤Ç¤¢¤ë¡£
452 .\"O .SS Error Handling
454 .\"O Packet sockets do no error handling other than errors occurred
455 .\"O while passing the packet to the device driver.
456 .\"O They don't have the concept of a pending error.
457 packet ¥½¥±¥Ã¥È¤Ï¡¢¥Ñ¥±¥Ã¥È¤ò¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤ËÅϤ¹¤È¤¤Ë
458 µ¯¤¤¿¥¨¥é¡¼¤·¤«½èÍý¤·¤Ê¤¤¡£Ãٱ䥨¥é¡¼ (pending error)
459 ¤Ë´Ø¤¹¤ë³µÇ°¤Ï»ý¤Ã¤Æ¤¤¤Ê¤¤¡£
464 .\"O Unknown multicast group address passed.
465 ÉÔÌÀ¤Ê¥Þ¥ë¥Á¥¥ã¥¹¥È¥°¥ë¡¼¥×¥¢¥É¥ì¥¹¤¬ÅϤµ¤ì¤¿¡£
468 .\"O User passed invalid memory address.
469 ¥æ¡¼¥¶¤¬ÅϤ·¤¿¥á¥â¥ê¥¢¥É¥ì¥¹¤¬ÉÔÀµ¡£
472 .\"O Invalid argument.
476 .\"O Packet is bigger than interface MTU.
477 ¥Ñ¥±¥Ã¥È¤¬¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î MTU ¤è¤êÂ礤¤¡£
480 .\"O Interface is not up.
481 ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤¬ up ¤Ç¤Ê¤¤¡£
484 .\"O Not enough memory to allocate the packet.
485 ¥Ñ¥±¥Ã¥È¤Ë³ä¤êÅö¤Æ¤ë¥á¥â¥ê¤¬Â¤ê¤Ê¤¤¡£
488 .\"O Unknown device name or interface index specified in interface address.
489 ¥Ç¥Ð¥¤¥¹Ì¾¤¬ÉÔÌÀ¡£¤¢¤ë¤¤¤Ï¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¥¢¥É¥ì¥¹¤Ç»ØÄꤵ¤ì¤¿
490 ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬ÉÔÌÀ¡£
493 .\"O No packet received.
494 ¥Ñ¥±¥Ã¥È¤ò°ì¤Ä¤â¼õ¿®¤·¤Æ¤¤¤Ê¤¤¡£
497 .\"O No interface address passed.
498 ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¥¢¥É¥ì¥¹¤¬ÅϤµ¤ì¤Ê¤«¤Ã¤¿¡£
501 .\"O Interface address contained an invalid interface index.
502 ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¥¢¥É¥ì¥¹¤ËÉÔÀµ¤Ê¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¡£
505 .\"O User has insufficient privileges to carry out this operation.
506 ¤³¤ÎÁàºî¤ò¹Ô¤¦¤Î¤ËɬÍפʸ¢¸Â¤ò¥æ¡¼¥¶¤¬»ý¤Ã¤Æ¤¤¤Ê¤¤¡£
508 .\"O In addition other errors may be generated by the low-level driver.
509 ¾åµ°Ê³°¤Î¥¨¥é¡¼¤¬¡¢Äã¥ì¥Ù¥ë¤Î¥É¥é¥¤¥Ð¤ÇÀ¸À®¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¡£
513 .\"O is a new feature in Linux 2.2.
514 .\"O Earlier Linux versions supported only
515 .\"O .BR SOCK_PACKET .
517 ¤Ï Linux 2.2 ¤Î¿·µ¡Ç½¤Ç¤¢¤ë¡£¤³¤ì¤è¤ê¸Å¤¤¥Ð¡¼¥¸¥ç¥ó¤Î Linux ¤Ç¤Ï
519 ¤Î¤ß¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤¿¡£
521 .\"O The include file
522 .\"O .I <netpacket/packet.h>
523 .\"O is present since glibc 2.1.
524 .\"O Older systems need:
526 .I <netpacket/packet.h>
527 ¤¬Â¸ºß¤¹¤ë¤Î¤Ï glibc 2.1 °Ê¹ß¤Ç¤¢¤ë¡£
528 ¤½¤ì°ÊÁ°¤Î¥·¥¹¥Æ¥à¤Ç¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ëɬÍפ¬¤¢¤ë:
532 #include <asm/types.h>
533 #include <linux/if_packet.h>
534 #include <linux/if_ether.h> /* The L2 protocols */
539 .\"O For portable programs it is suggested to use
543 .\"O although this only covers a subset of the
546 °Ü¿¢À¤ÎɬÍ×¤Ê¥×¥í¥°¥é¥à¤Ç¤Ï¡¢
550 ¤òÍѤ¤¤ë¤³¤È¤ò¤ªÁ¦¤á¤¹¤ë¡£¤¿¤À¤·¡¢¤³¤ÎÊýË¡¤Ç¤Ï
552 ¤Îµ¡Ç½¤¹¤Ù¤Æ¤òÍøÍѤ¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
556 .\"O packet sockets make no attempt to create or parse the IEEE 802.2 LLC
557 .\"O header for a IEEE 802.3 frame.
560 .\"O is specified as protocol for sending the kernel creates the
561 .\"O 802.3 frame and fills out the length field; the user has to supply the LLC
562 .\"O header to get a fully conforming packet.
563 .\"O Incoming 802.3 packets are not multiplexed on the DSAP/SSAP protocol
564 .\"O fields; instead they are supplied to the user as protocol
566 .\"O with the LLC header prepended.
567 .\"O It is thus not possible to bind to
568 .\"O .BR ETH_P_802_3 ;
571 .\"O instead and do the protocol multiplex yourself.
572 .\"O The default for sending is the standard Ethernet DIX
573 .\"O encapsulation with the protocol filled in.
575 packet ¥½¥±¥Ã¥È¤Ï¡¢IEEE 802.3 ¥Õ¥ì¡¼¥à¤Î IEEE 802.2 LLC ¥Ø¥Ã¥À¤Î
576 À¸À®¤ä²òÀϤò¹Ô¤ª¤¦¤È¤·¤Ê¤¤¡£
578 ¤¬Á÷¿®¥×¥í¥È¥³¥ë¤Ë»ØÄꤵ¤ì¤ë¤È¡¢¥«¡¼¥Í¥ë¤Ï 802.3 ¥Õ¥ì¡¼¥à¤ò
579 À¸À®¤·¤Æ length ¥Õ¥£¡¼¥ë¥É¤Ë½ñ¤¹þ¤à¡£
580 ´°Á´¤Ë½àµò¤·¤¿¥Ñ¥±¥Ã¥È¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¥æ¡¼¥¶¡¼¤¬ LLC ¥Ø¥Ã¥À¤ò
581 Í¿¤¨¤ëɬÍפ¬¤¢¤ë¡£ÅþÃ夷¤¿ 802.3 ¥Ñ¥±¥Ã¥È¤Ç¤Ï¡¢
582 DSAP/SSAP protocol ¤Î³Æ¥Õ¥£¡¼¥ë¥É¤Ï¿½Å²½ (multiplex) ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
583 Âå¤ï¤ê¤Ë¤³¤ì¤é¤Ï LLC ¥Ø¥Ã¥À¤¬Á°ÃÖ¤µ¤ì¤¿
585 ¥×¥í¥È¥³¥ë¤È¤·¤ÆÍ¿¤¨¤é¤ì¤ë¡£¤·¤¿¤¬¤Ã¤Æ¡¢
587 ¤Ë¥Ð¥¤¥ó¥É¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£¤«¤ï¤ê¤Ë
589 ¤Ë¥Ð¥¤¥ó¥É¤·¡¢¼«Ê¬¼«¿È¤Ç¥×¥í¥È¥³¥ë¤Î¿½Å²½¤ò¹Ô¤¦¤³¤È¡£
590 Á÷¿®¤Î¥Ç¥Õ¥©¥ë¥È¤Ï¡¢¥×¥í¥È¥³¥ë¥Õ¥£¡¼¥ë¥É¤ò»ý¤Ä
591 ɸ½à¤Î Ethernet DIX encapsulation ¤Ç¤¢¤ë¡£
593 .\"O Packet sockets are not subject to the input or output firewall chains.
594 packet ¥½¥±¥Ã¥È¤ÏÆþ½ÐÎϤΠfirewall chain ¤Ë±Æ¶Á¤ò¤¦¤±¤Ê¤¤¡£
595 .\"O .SS Compatibility
597 .\"O In Linux 2.0, the only way to get a packet socket was by calling
598 .\"O .BI "socket(AF_INET, SOCK_PACKET, " protocol )\fR.
599 .\"O This is still supported but strongly deprecated.
600 .\"O The main difference between the two methods is that
603 .\"O .I struct sockaddr_pkt
604 .\"O to specify an interface, which doesn't provide physical layer
606 Linux 2.0 ¤Ç¤Ï¡¢ packet ¥½¥±¥Ã¥È¤òÆÀ¤ëÊýË¡¤Ï
607 .BI "socket(AF_INET, SOCK_PACKET, " protocol )\fR
608 ¤ò¸Æ¤Ö¤ä¤êÊý¤·¤«¤Ê¤«¤Ã¤¿¡£¤³¤ÎÊýË¡¤Ï¤Þ¤À¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤¬¡¢
609 ÍѤ¤¤Ê¤¤¤³¤È¤ò¶¯¤¯¿ä¾©¤¹¤ë¡£¸½ºß¤ÎÊýË¡¤È¤Î¼ç¤Ê°ã¤¤¤Ï¡¢
611 ¤Ç¤Ï¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î»ØÄê¤Ë¸Å¤¤
612 .I struct sockaddr_pkt
613 ¤òÍѤ¤¤ëÅÀ¤Ç¤¢¤ë¡£¤³¤ì¤Ë¤ÏʪÍýÁؤ«¤é¤ÎÆÈΩÀ¤¬¤Ê¤¤¡£
617 struct sockaddr_pkt {
618 unsigned short spkt_family;
619 unsigned char spkt_device[14];
620 unsigned short spkt_protocol;
627 .\"O the device type,
628 .\"O .I spkt_protocol
629 .\"O is the IEEE 802.3 protocol type as defined in
630 .\"O .I <sys/if_ether.h>
633 .\"O is the device name as a null-terminated string, for example, eth0.
639 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë IEEE 802.3 ¥×¥í¥È¥³¥ë¥¿¥¤¥×¡¢
641 ¤Ï¥Ç¥Ð¥¤¥¹¤Î̾Á°¤ò NULL ½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤ÇÍ¿¤¨¤¿¤â¤Î (Îã: eth0) ¤Ç¤¢¤ë¡£
643 .\"O This structure is obsolete and should not be used in new code.
644 ¤³¤Î¹½Â¤ÂÎ¤Ï obsolete ¤Ç¤¢¤ê¡¢
645 ¿·¤·¤¯¥³¡¼¥É¤ò½ñ¤¯»þ¤Ë¤ÏÍѤ¤¤ë¤Ù¤¤Ç¤Ê¤¤¡£
648 .\"O glibc 2.1 does not have a define for
649 .\"O .BR SOL_PACKET .
650 .\"O The suggested workaround is to use:
653 ¤ÎÄêµÁ¤¬¤Ê¤¤¡£²óÈòºö¤È¤·¤Æ¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¤È¤è¤¤¡£
658 #define SOL_PACKET 263
663 .\"O This is fixed in later glibc versions and also does not occur on
665 ¤³¤ÎÌäÂê¤Ï¿·¤·¤¤¥Ð¡¼¥¸¥ç¥ó¤Î glibc ¤Ç¤Ï½¤Àµ¤µ¤ì¤Æ¤¤¤ë¡£
666 libc5 ¤Î¥·¥¹¥Æ¥à¤Ë¤Ï¤³¤ÎÌäÂê¤Ï¤Ê¤¤¡£
668 .\"O The IEEE 802.2/803.3 LLC handling could be considered as a bug.
669 IEEE 802.2/803.3 ¤Î LLC ¤Î°·¤¤Êý¤Ï¡¢¥Ð¥°¤È¹Í¤¨¤Æ¤âÎɤ¤¤À¤í¤¦¡£
671 .\"O Socket filters are not documented.
672 ¥½¥±¥Ã¥È¥Õ¥£¥ë¥¿¡¼¤Ë¤Ä¤¤¤ÆµºÜ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
677 .\"O extension is an ugly hack and should be replaced by a control message.
678 .\"O There is currently no way to get the original destination address of
680 .\"O .BR SOCK_DGRAM .
683 ³ÈÄ¥¤ÏÈó¾ï¤Ë¤Þ¤º¤¤Âнè¤Ç¤¢¤ê¡¢À©¸æ¥á¥Ã¥»¡¼¥¸¤ÇÃÖ¤´¹¤¨¤ë¤Ù¤¤Ç¤¢¤ë¡£
686 ·Ðͳ¤Ç¥Ñ¥±¥Ã¥È¤Ë¤Ä¤¤¤Æ¤¤¤¿°¸À襢¥É¥ì¥¹¤òÆÀ¤ëÊýË¡¤¬¤Ê¤¤¡£
689 .\"O .\" This man page was written by Andi Kleen with help from Matthew Wilcox.
690 .\"O .\" AF_PACKET in Linux 2.2 was implemented
691 .\"O .\" by Alexey Kuznetsov, based on code by Alan Cox and others.
692 .\" ¤³¤Î man ¥Ú¡¼¥¸¤Ï Matthew Wilcox ¤Î½õÎϤΤâ¤È¤Ë Andi Kleen ¤¬½ñ¤¤¤¿¡£
693 .\" Linux 2.2 ¤Î AF_PACKET ¤Ï¡¢
694 .\" Alan Cox ¤¿¤Á¤Î¥³¡¼¥É¤ò¤â¤È¤Ë¤·¤Æ Alexey Kuznetsov ¤¬¼ÂÁõ¤·¤¿¡£
699 .BR capabilities (7),
704 .\"O RFC\ 894 for the standard IP Ethernet encapsulation.
705 ɸ½à IP Ethernet encapsulation ¤Ë´Ø¤¹¤ë¾ðÊó¤Ï RFC\ 894 ¤Ë¤¢¤ë¡£
707 .\"O RFC\ 1700 for the IEEE 802.3 IP encapsulation.
708 IEEE 802.3 IP encapsulation ¤Ë´Ø¤¹¤ë¾ðÊó¤Ï RFC\ 1700 ¤Ë¤¢¤ë¡£
711 .\"O .I <linux/if_ether.h>
712 .\"O include file for physical layer protocols.
713 ʪÍýÁؤΥץí¥È¥³¥ë¤Ë´Ø¤¹¤ëµ½Ò¤Ï
714 .I <linux/if_ether.h>
715 ¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë¤Ë¤¢¤ë¡£