ipv6のヘルプ・マニュアル
日本語 英語
ipv6 --help
man ipv6
IPV6(7) Linux Programmer’s Manual IPV6(7)
名前
ipv6, AF_INET6 - Linux の IPv6 プロトコル実装
書式
#include
#include
tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);
説明
Linux 2.2 では、Internet Protocol, version 6 をオプションとして実装して
いる。この man ページでは、Linux カーネルと glibc 2.1 での実装に基づ い
て 、 IPv6 の基本的な API を解説する。インターフェースは BSD ソケットイ
ンターフェースをもとにしている。 socket(7) を参照。
IPv6 API は、 IPv4 API (ip(7) 参照) とほぼ互換になることを目指してい る
。この man ページでは相違点のみを解説する。
AF_INET6 ソケットを何らかのプロセスにバインドするには、ローカルアドレス
を in6_addr 型の変数 in6addr_any からコピーしてくる必要がある。 static
な 初期値 IN6ADDR_ANY_INIT も用いることができ、これは定数式に展開される
。これらの両者はネットワークバイトオーダーである。
IPv6 のループバックアドレス (::1) は global 変数 in6addr_loopback か ら
取得できる。初期化には IN6ADDR_LOOPBACK_INIT を用いるべきである。
v4-mapped-on-v6 アドレス型を用いることで、 IPv4 接続も v6 API で扱うこ
とができる。こうすれば、プログラムは v6 の API をサポートするだけで、両
方 のプロトコルをサポートできる。 v4-mapped-on-v6 アドレス型は C ライブ
ラリ内部のアドレスを扱う関数によって透過的に処理される。
IPv4 と IPv6 はローカルポート空間を共有する。 IPv4 の接続 (またはパケッ
ト) を IPv6 ソケットが取得すると、発信元アドレスが v6 にマップされ、そ
の接続 (パケット) も v6 にマップされる。
アドレスのフォーマット
struct sockaddr_in6 {
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* port number */
uint32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* Scope ID (new in 2.4) */
};
struct in6_addr {
unsigned char s6_addr[16]; /* IPv6 address */
};
sin6_family は常に AF_INET6 に設定される。 sin6_port はプロトコルポート
で ある (ip(7) の sin_port を参照)。 sin6_flowinfo は IPv6 のフロー指定
子 (flow identifier) である。 sin6_addr は 128 ビットの IPv6 アドレスで
あ る 。 sin6_scope_id はアドレスのスコープに依存した ID である (これは
Linux 2.4 で導入された)。 Linux の場合は、これはリンクスコープアドレ ス
でしかサポートされない。この場合 sin6_scope_id にはインターフェースのイ
ンデックスが含まれることになる (netdevice(7) を参照)。
IPv6 は何種類かのアドレスタイプをサポートしている。単一のホストをアドレ
ス するための unicast、ホストのグループをアドレスするための multicast、
ホストのグループ中で最も近くにいるものをアドレスするための anycast ( こ
れ は Linux で は実装されていない)、 IPv4 ホストをアドレスするための
IPv4-on-IPv6。他にも予約済みのアドレスタイプがある。
IPv6 でのアドレス表記は 2 桁の 16 進数 16 個からなり、 ':' は区切り文字
は で、"::" は 0 ビットの文字列を表す。特殊なアドレスとして、ループバッ
クを表す ::1、 IPv4-mapped-on-IPv6 を表す ::FFFF:: が あ
る。
IPv6 のポート空間は IPv4 と共有されている。
ソケットオプション
IPv6 はプロトコル固有のソケットオプションをいくつかサポートしている。こ
れらは setsockopt(2) で設定でき、 getsockopt(2) で取得できる。 IPv6 の
ソケットオプションレベルは IPPROTO_IPV6 である。ブール整数のフラグは、0
が偽であり、それ以外は真である。
IPV6_ADDRFORM
AF_INET6 ソケットを別のアドレスファミリーのソケットに変える。 現
在 は AF_INET のみが変更先のアドレスファミリーとしてサポートされ
ている。これが許可されるのは、IPv6 が接続され、 v4-mapped-on-v6
ア ドレスにバインドされた場合に限られる。引き数は AF_INET が入っ
ている整数へのポインタである。 v4-mapped ソケットを、IPv6 API を
扱えないプログラムに対してファイルディスクリプターとして渡す場合
に便利。
IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP
multicast グループのメンバーを制 御 す る 。 引 き 数 は struct
ipv6_mreq 構造体へのポインタ。
IPV6_MTU
そのソケットに対して用いる MTU の値を設定する。 MTU の大きさは、
そのデバイスの MTU または (Path MTU Discovery が可能なら) その経
路 の MTU の大きさ以下でなければならない。引き数は整数へのポイン
タ。
IPV6_MTU_DISCOVER
そのソケットでの Path MTU Discovery を制御する。詳細は ip(7) の
IP_MTU_DISCOVER を参照。
IPV6_MULTICAST_HOPS
そのソケットでの multicast の hop 数の上限値を設定する。引き数は
整数へのポインタである。 -1 を指定すると経路のデフォルトを用いる
ことを意味する。それ以外の場合は 0 から 255 の範囲を指定する。
IPV6_MULTICAST_IF
そ のソケットでの、送信 multicast パケットに用いるデバイスを設定
する。これは SOCK_DGRAM および SOCK_RAW 各ソケットでのみ許される
。 引 き数はインターフェースのインデックスの整数値 (netdevice(7)
を参照) へのポインタである。
IPV6_MULTICAST_LOOP
ソケットが、自分自身の送信した multicast パケットを監視するか ど
うかを制御する。引き数はブール値へのポインタ。
IPV6_PKTINFO
データグラムの到着時における IPV6_PKTINFO 制御メッセージを配送す
るかどうかを設定する。 SOCK_DGRAM ソケットまたは SOCK_RAW ソケッ
トに対してのみ許可される。引き数はブール値の入った整数。
IPV6_RTHDR, IPV6_AUTHHDR, IPV6_DSTOPS, IPV6_HOPOPTS, IPV6_FLOWINFO,
IPV6_HOPLIMIT
受信パケットのデータグラムに拡張ヘッダが含まれている場合の、制御
メッセージの配送を設定する。 IPV6_RTHDR: routing ヘッダを配送 す
るかどうか。 IPV6_AUTHHDR: authentication ヘッダを配送するかどう
か。 IPV6_DSTOPTS: destination オプションを配送するかど う か 。
IPV6_HOPOPTS: hop オプションを配送するかどうか。 IPV6_FLOWINFO:
flow ID を含む整数を配送するかどうか。 IPV6_HOPLIMIT: パケットの
hop カウントを含む整数を配送するかどうか。制御メッセージはソケッ
トオプションのものと同じタイプを持つ。これらのすべてのヘッダオプ
ションは、適切な制御メッセージを sendmsg(2) の制御バッファーに書
きこめば、送信パケットにでも設定できる。 SOCK_DGRAM ソケットまた
は SOCK_RAW ソケットでのみ許される。引き数はブール値へのポインタ
。
IPV6_RECVERR
非同期エラー (asynchronous error) オプションの受信を制御する。詳
細は ip(7) の IP_RECVERR を参照。引き数はブール値へのポインタ。
IPV6_ROUTER_ALERT
このソケットで、router alert hop-by-hop オプションの付いた転送パ
ケットを通すかどうかを制御する。 SOCK_RAW ソケットでのみ許可され
る 。 tap されたパケットはカーネルによっては転送されない。そうし
たパケットを再度送信するのはユーザーの責任である。引き数は 整 数
(integer) へのポインタ。正の整数は傍受を行う router alert オプシ
ョン値を示す。オプション値がこの整数である router alert オプショ
ンの付いたパケットはソケットに配送される。負の整数を指定すると、
このソケットへの router alert オプションの付いたパケットの配送が
行われない。
IPV6_UNICAST_HOPS
そのソケットでの unicast の hop 数の上限値を設定する。引き数は整
数へのポインタである。 -1 を指定すると経路のデフォルトを用いるこ
とを意味する。それ以外の場合は 0 から 255 の範囲を指定する。
IPV6_V6ONLY (Linux 2.4.21 以降および 2.6 以降)
このフラグを真 (0 以外) に設定すると、そのソケットは IPv6 パケッ
トだけを送受信するように制限される。この場合、IPv4 アプリケー シ
ョンと IPv6 アプリケーションが同時に一つのポートをバインドできる
。
このフラグを偽 (0) に設定すると、そのソケットはパケットの送受 信
に IPv6 アドレスと IPv4-mapped IPv6 アドレスの両方を使用できる。
引き数はブール値の入った整数へのポインタである。
このフラグのデフォルト値はファイル /proc/sys/net/ipv6/bindv6only
の内容により定義される。このファイルのデフォルト値は 0 (偽) であ
る。
バージョン
IPv6 API を libc5 ベースで Linux 向けに実装した、以前の libinet6 につい
て はここでは記述していない。おそらく細かいところには相違点があるだろう
。
Linux 2.4 では 64 ビットのホストに対して sockaddr_in6 のバイナリ互換 性
が 保 た れ て い な い 。 in6_addr のアラインメントが変更され、また
sin6_scope_id フィールドが新たに追加されたからである。カーネルインタ ー
フ ェースの互換性は保たれているが、 sockaddr_in6 や in6_addr を他の構造
体に含んでいるようなプログラムでは保たれないかもしれない。これ は i386
のような 32 ビットのホストでは問題にならない。
sin6_flowinfo フィールドは Linux 2.4 で登場した。これが渡されたアドレス
長に含まれていると、カーネルに透過的に渡され、読まれる。より長いアド レ
ス バッファを渡し、そして送信アドレスの長さをチェックするようなプログラ
ムはうまく動かないかもしれない。
注意
sockaddr_in6 構造体はジェネリックな sockaddr よりも大きい。すべてのアド
レスタイプが struct sockaddr の中に安全に納められると仮定しているプログ
ラムは、代わりに struct sockaddr_storage を用いるように変更する必要があ
る。
バグ
IPv6 拡張 API は、現在まだ RFC 2292 を完全には実装していない。 2.2 カー
ネルは受信オプションをほぼ完全にサポートサポートしているが 、 glibc2.1
には IPv6 オプションを生成するマクロが存在していない。
EH および AH ヘッダ での IPSec のサポートは存在しない。
フローラベル管理はまだ完全でなく、ここにも記述されていない。
この man ページはまだ完成していない。
関連項目
cmsg(3), ip(7)
RFC 2553: IPv6 BASIC API. Linux はこの RFC に準拠するようにしている。
RFC 2460: IPv6 specification.
Linux 2009-02-28 IPV6(7)
IPV6(7) Linux Programmer’s Manual IPV6(7)
NAME
ipv6, AF_INET6 - Linux IPv6 protocol implementation
SYNOPSIS
#include
#include
tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);
DESCRIPTION
Linux 2.2 optionally implements the Internet Protocol, version 6. This
man page contains a description of the IPv6 basic API as implemented by
the Linux kernel and glibc 2.1. The interface is based on the BSD
sockets interface; see socket(7).
The IPv6 API aims to be mostly compatible with the IPv4 API (see
ip(7)). Only differences are described in this man page.
To bind an AF_INET6 socket to any process, the local address should be
copied from the in6addr_any variable which has in6_addr type. In
static initializations, IN6ADDR_ANY_INIT may also be used, which
expands to a constant expression. Both of them are in network byte
order.
The IPv6 loopback address (::1) is available in the global
in6addr_loopback variable. For initializations, IN6ADDR_LOOPBACK_INIT
should be used.
IPv4 connections can be handled with the v6 API by using the v4-mapped-
on-v6 address type; thus a program only needs to support this API type
to support both protocols. This is handled transparently by the
address handling functions in the C library.
IPv4 and IPv6 share the local port space. When you get an IPv4 connec-
tion or packet to a IPv6 socket, its source address will be mapped to
v6 and it will be mapped to v6.
Address Format
struct sockaddr_in6 {
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* port number */
uint32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* Scope ID (new in 2.4) */
};
struct in6_addr {
unsigned char s6_addr[16]; /* IPv6 address */
};
sin6_family is always set to AF_INET6; sin6_port is the protocol port
(see sin_port in ip(7)); sin6_flowinfo is the IPv6 flow identifier;
sin6_addr is the 128-bit IPv6 address. sin6_scope_id is an ID depend-
ing on the scope of the address. It is new in Linux 2.4. Linux only
supports it for link scope addresses, in that case sin6_scope_id con-
tains the interface index (see netdevice(7))
IPv6 supports several address types: unicast to address a single host,
multicast to address a group of hosts, anycast to address the nearest
member of a group of hosts (not implemented in Linux), IPv4-on-IPv6 to
address a IPv4 host, and other reserved address types.
The address notation for IPv6 is a group of 16 2-digit hexadecimal num-
bers, separated with a ':'. "::" stands for a string of 0 bits. Spe-
cial addresses are ::1 for loopback and ::FFFF: for
IPv4-mapped-on-IPv6.
The port space of IPv6 is shared with IPv4.
Socket Options
IPv6 supports some protocol-specific socket options that can be set
with setsockopt(2) and read with getsockopt(2). The socket option
level for IPv6 is IPPROTO_IPV6. A boolean integer flag is zero when it
is false, otherwise true.
IPV6_ADDRFORM
Turn an AF_INET6 socket into a socket of a different address
family. Only AF_INET is currently supported for that. It is
only allowed for IPv6 sockets that are connected and bound to a
v4-mapped-on-v6 address. The argument is a pointer to an inte-
ger containing AF_INET. This is useful to pass v4-mapped sock-
ets as file descriptors to programs that don’t know how to deal
with the IPv6 API.
IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP
Control membership in multicast groups. Argument is a pointer
to a struct ipv6_mreq structure.
IPV6_MTU
Set the MTU to be used for the socket. The MTU is limited by
the device MTU or the path mtu when path mtu discovery is
enabled. Argument is a pointer to integer.
IPV6_MTU_DISCOVER
Control path mtu discovery on the socket. See IP_MTU_DISCOVER
in ip(7) for details.
IPV6_MULTICAST_HOPS
Set the multicast hop limit for the socket. Argument is a
pointer to an integer. -1 in the value means use the route
default, otherwise it should be between 0 and 255.
IPV6_MULTICAST_IF
Set the device for outgoing multicast packets on the socket.
This is only allowed for SOCK_DGRAM and SOCK_RAW socket. The
argument is a pointer to an interface index (see netdevice(7))
in an integer.
IPV6_MULTICAST_LOOP
Control whether the socket sees multicast packets that it has
send itself. Argument is a pointer to boolean.
IPV6_PKTINFO
Set delivery of the IPV6_PKTINFO control message on incoming
datagrams. Only allowed for SOCK_DGRAM or SOCK_RAW sockets.
Argument is a pointer to a boolean value in an integer.
IPV6_RTHDR, IPV6_AUTHHDR, IPV6_DSTOPS, IPV6_HOPOPTS, IPV6_FLOWINFO,
IPV6_HOPLIMIT
Set delivery of control messages for incoming datagrams contain-
ing extension headers from the received packet. IPV6_RTHDR de-
livers the routing header, IPV6_AUTHHDR delivers the authentica-
tion header, IPV6_DSTOPTS delivers the destination options,
IPV6_HOPOPTS delivers the hop options, IPV6_FLOWINFO delivers an
integer containing the flow ID, IPV6_HOPLIMIT delivers an inte-
ger containing the hop count of the packet. The control mes-
sages have the same type as the socket option. All these header
options can also be set for outgoing packets by putting the ap-
propriate control message into the control buffer of sendmsg(2).
Only allowed for SOCK_DGRAM or SOCK_RAW sockets. Argument is a
pointer to a boolean value.
IPV6_RECVERR
Control receiving of asynchronous error options. See IP_RECVERR
in ip(7) for details. Argument is a pointer to boolean.
IPV6_ROUTER_ALERT
Pass forwarded packets containing a router alert hop-by-hop op-
tion to this socket. Only allowed for SOCK_RAW sockets. The
tapped packets are not forwarded by the kernel, it is the user’s
responsibility to send them out again. Argument is a pointer to
an integer. A positive integer indicates a router alert option
value to intercept. Packets carrying a router alert option with
a value field containing this integer will be delivered to the
socket. A negative integer disables delivery of packets with
router alert options to this socket.
IPV6_UNICAST_HOPS
Set the unicast hop limit for the socket. Argument is a pointer
to an integer. -1 in the value means use the route default,
otherwise it should be between 0 and 255.
IPV6_V6ONLY (since Linux 2.4.21 and 2.6)
If this flag is set to true (non-zero), then the socket is re-
stricted to sending and receiving IPv6 packets only. In this
case, an IPv4 and an IPv6 application can bind to a single port
at the same time.
If this flag is set to false (zero), then the socket can be used
to send and receive packets to and from an IPv6 address or an
IPv4-mapped IPv6 address.
The argument is a pointer to a boolean value in an integer.
The default value for this flag is defined by the contents of
the file /proc/sys/net/ipv6/bindv6only. The default value for
that file is 0 (false).
VERSIONS
The older libinet6 libc5 based IPv6 API implementation for Linux is not
described here and may vary in details.
Linux 2.4 will break binary compatibility for the sockaddr_in6 for
64-bit hosts by changing the alignment of in6_addr and adding an addi-
tional sin6_scope_id field. The kernel interfaces stay compatible, but
a program including sockaddr_in6 or in6_addr into other structures may
not be. This is not a problem for 32-bit hosts like i386.
The sin6_flowinfo field is new in Linux 2.4. It is transparently
passed/read by the kernel when the passed address length contains it.
Some programs that pass a longer address buffer and then check the out-
going address length may break.
NOTES
The sockaddr_in6 structure is bigger than the generic sockaddr. Pro-
grams that assume that all address types can be stored safely in a
struct sockaddr need to be changed to use struct sockaddr_storage for
that instead.
BUGS
The IPv6 extended API as in RFC 2292 is currently only partly imple-
mented; although the 2.2 kernel has near complete support for receiving
options, the macros for generating IPv6 options are missing in glibc
2.1.
IPSec support for EH and AH headers is missing.
Flow label management is not complete and not documented here.
This man page is not complete.
SEE ALSO
cmsg(3), ip(7)
RFC 2553: IPv6 BASIC API. Linux tries to be compliant to this.
RFC 2460: IPv6 specification.
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-02-28 IPV6(7)