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.
76 はリンクレベルヘッダを含む raw パケットを、
78 はリンクレベルヘッダが削除された加工済みパケットを示す。
83 には IEEE 802.3 プロトコル番号を
85 指定できるプロトコルのリストは、インクルードファイル
90 外部から来たパケットのうち指定したプロトコルのものは、
91 カーネルに実装されているプロトコルに渡される前の段階で、
94 .\"O Only processes with effective UID 0 or the
96 .\"O capability may open packet sockets.
97 packet ソケットをオープンできるのは、
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
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 はやや高位のレベルで動作する。物理ヘッダは、パケットがユーザーに
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 に渡されると、 (バッファサイズより大きかったとしても) 常に実際に通信された
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 は標準的なイーサネットプロトコルのタイプで、
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>
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 はパケット種別である。指定できる種別は以下のいずれかである:
284 (物理層のマルチキャストアドレスに送るパケット)、
287 無差別モード (promiscuous mode: 後述) のデバイスドライバにより補足されたもの)、
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 の) アドレスとその長さである。
304 .\"O When you send packets it is enough to specify
305 .\"O .IR sll_family ,
308 .\"O .IR sll_ifindex .
315 .\"O The other fields should be 0.
316 その他のフィールドは 0 にしておくべきである。
320 .\"O are set on received packets for your information.
335 .\"O .SS Socket Options
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) を設定して使うことができる。
359 .B PACKET_ADD_MEMBERSHIP
361 .B PACKET_DROP_MEMBERSHIP
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 は、ステータスを変更したいインターフェースの
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.
432 .\"O can be used to receive the timestamp of the last received packet.
434 .\"O .IR "struct timeval" .
436 を用いると、最後に受信したパケットのタイムスタンプを得ることができる。
440 .\" FIXME Document SIOCGSTAMPNS
442 .\"O In addition all standard ioctls defined in
443 .\"O .BR netdevice (7)
446 .\"O are valid on packet sockets.
451 で定義されている標準の ioctl はいずれも
453 .\"O .SS Error Handling
455 .\"O Packet sockets do no error handling other than errors occurred
456 .\"O while passing the packet to the device driver.
457 .\"O They don't have the concept of a pending error.
458 packet ソケットは、パケットをデバイスドライバに渡すときに
459 起きたエラーしか処理しない。遅延エラー (pending error)
465 .\"O Unknown multicast group address passed.
466 不明なマルチキャストグループアドレスが渡された。
469 .\"O User passed invalid memory address.
473 .\"O Invalid argument.
477 .\"O Packet is bigger than interface MTU.
478 パケットがインターフェースの MTU より大きい。
481 .\"O Interface is not up.
485 .\"O Not enough memory to allocate the packet.
489 .\"O Unknown device name or interface index specified in interface address.
490 デバイス名が不明。あるいはインターフェースアドレスで指定された
494 .\"O No packet received.
498 .\"O No interface address passed.
499 インターフェースアドレスが渡されなかった。
502 .\"O Interface address contained an invalid interface index.
503 インターフェースアドレスに不正なインターフェースインデックスが含まれている。
506 .\"O User has insufficient privileges to carry out this operation.
507 この操作を行うのに必要な権限をユーザが持っていない。
509 .\"O In addition other errors may be generated by the low-level driver.
510 上記以外のエラーが、低レベルのドライバで生成されることがある。
514 .\"O is a new feature in Linux 2.2.
515 .\"O Earlier Linux versions supported only
516 .\"O .BR SOCK_PACKET .
518 は Linux 2.2 の新機能である。これより古いバージョンの Linux では
522 .\"O The include file
523 .\"O .I <netpacket/packet.h>
524 .\"O is present since glibc 2.1.
525 .\"O Older systems need:
527 .I <netpacket/packet.h>
528 が存在するのは glibc 2.1 以降である。
529 それ以前のシステムでは以下のようにする必要がある:
533 #include <asm/types.h>
534 #include <linux/if_packet.h>
535 #include <linux/if_ether.h> /* The L2 protocols */
540 .\"O For portable programs it is suggested to use
544 .\"O although this only covers a subset of the
551 を用いることをお薦めする。ただし、この方法では
557 .\"O packet sockets make no attempt to create or parse the IEEE 802.2 LLC
558 .\"O header for a IEEE 802.3 frame.
561 .\"O is specified as protocol for sending the kernel creates the
562 .\"O 802.3 frame and fills out the length field; the user has to supply the LLC
563 .\"O header to get a fully conforming packet.
564 .\"O Incoming 802.3 packets are not multiplexed on the DSAP/SSAP protocol
565 .\"O fields; instead they are supplied to the user as protocol
567 .\"O with the LLC header prepended.
568 .\"O It is thus not possible to bind to
569 .\"O .BR ETH_P_802_3 ;
572 .\"O instead and do the protocol multiplex yourself.
573 .\"O The default for sending is the standard Ethernet DIX
574 .\"O encapsulation with the protocol filled in.
576 packet ソケットは、IEEE 802.3 フレームの IEEE 802.2 LLC ヘッダの
579 が送信プロトコルに指定されると、カーネルは 802.3 フレームを
580 生成して length フィールドに書き込む。
581 完全に準拠したパケットを得るためにはユーザーが LLC ヘッダを
582 与える必要がある。到着した 802.3 パケットでは、
583 DSAP/SSAP protocol の各フィールドは多重化 (multiplex) されていない。
584 代わりにこれらは LLC ヘッダが前置された
590 にバインドし、自分自身でプロトコルの多重化を行うこと。
591 送信のデフォルトは、プロトコルフィールドを持つ
592 標準の Ethernet DIX encapsulation である。
594 .\"O Packet sockets are not subject to the input or output firewall chains.
595 packet ソケットは入出力の firewall chain に影響をうけない。
596 .\"O .SS Compatibility
598 .\"O In Linux 2.0, the only way to get a packet socket was by calling
599 .\"O .BI "socket(AF_INET, SOCK_PACKET, " protocol )\fR.
600 .\"O This is still supported but strongly deprecated.
601 .\"O The main difference between the two methods is that
604 .\"O .I struct sockaddr_pkt
605 .\"O to specify an interface, which doesn't provide physical layer
607 Linux 2.0 では、 packet ソケットを得る方法は
608 .BI "socket(AF_INET, SOCK_PACKET, " protocol )\fR
609 を呼ぶやり方しかなかった。この方法はまだサポートされているが、
610 用いないことを強く推奨する。現在の方法との主な違いは、
613 .I struct sockaddr_pkt
614 を用いる点である。これには物理層からの独立性がない。
618 struct sockaddr_pkt {
619 unsigned short spkt_family;
620 unsigned char spkt_device[14];
621 unsigned short spkt_protocol;
628 .\"O the device type,
629 .\"O .I spkt_protocol
630 .\"O is the IEEE 802.3 protocol type as defined in
631 .\"O .I <sys/if_ether.h>
634 .\"O is the device name as a null-terminated string, for example, eth0.
640 で定義されている IEEE 802.3 プロトコルタイプ、
642 はデバイスの名前を NULL 終端された文字列で与えたもの (例: eth0) である。
644 .\"O This structure is obsolete and should not be used in new code.
646 新しくコードを書く時には用いるべきでない。
649 .\"O glibc 2.1 does not have a define for
650 .\"O .BR SOL_PACKET .
651 .\"O The suggested workaround is to use:
654 の定義がない。回避策としては、以下のようにするとよい。
659 #define SOL_PACKET 263
664 .\"O This is fixed in later glibc versions and also does not occur on
666 この問題は新しいバージョンの glibc では修正されている。
667 libc5 のシステムにはこの問題はない。
669 .\"O The IEEE 802.2/803.3 LLC handling could be considered as a bug.
670 IEEE 802.2/803.3 の LLC の扱い方は、バグと考えても良いだろう。
672 .\"O Socket filters are not documented.
673 ソケットフィルターについて記載されていない。
678 .\"O extension is an ugly hack and should be replaced by a control message.
679 .\"O There is currently no way to get the original destination address of
681 .\"O .BR SOCK_DGRAM .
684 拡張は非常にまずい対処であり、制御メッセージで置き換えるべきである。
687 経由でパケットについていた宛先アドレスを得る方法がない。
690 .\"O .\" This man page was written by Andi Kleen with help from Matthew Wilcox.
691 .\"O .\" AF_PACKET in Linux 2.2 was implemented
692 .\"O .\" by Alexey Kuznetsov, based on code by Alan Cox and others.
693 .\" この man ページは Matthew Wilcox の助力のもとに Andi Kleen が書いた。
694 .\" Linux 2.2 の AF_PACKET は、
695 .\" Alan Cox たちのコードをもとにして Alexey Kuznetsov が実装した。
700 .BR capabilities (7),
705 .\"O RFC\ 894 for the standard IP Ethernet encapsulation.
706 標準 IP Ethernet encapsulation に関する情報は RFC\ 894 にある。
708 .\"O RFC\ 1700 for the IEEE 802.3 IP encapsulation.
709 IEEE 802.3 IP encapsulation に関する情報は RFC\ 1700 にある。
712 .\"O .I <linux/if_ether.h>
713 .\"O include file for physical layer protocols.
715 .I <linux/if_ether.h>