.\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 .\" %FreeBSD: src/lib/libc/net/getnetent.3,v 1.11.2.4 2001/12/14 18:33:55 ru Exp % .\" $FreeBSD$ .\" .Dd June 4, 1993 .Dt GETNETENT 3 .Os .Sh 名称 .Nm getnetent , .Nm getnetbyaddr , .Nm getnetbyname , .Nm setnetent , .Nm endnetent .Nd ネットワークエントリの取得 .Sh ライブラリ .Lb libc .Sh 書式 .In netdb.h .Ft struct netent * .Fn getnetent void .Ft struct netent * .Fn getnetbyname "const char *name" .Ft struct netent * .Fn getnetbyaddr "unsigned long net" "int type" .Ft void .Fn setnetent "int stayopen" .Ft void .Fn endnetent void .Sh 解説 .Fn getnetent , .Fn getnetbyname , .Fn getnetbyaddr 関数はそれぞれ、次に示す構造を持つオブジェクトへのポインタを返します。 構造体には、ネットワークデータベース .Pa /etc/networks にある行の内訳フィールドが含まれます。 .Bd -literal -offset indent struct netent { char *n_name; /* ネットワークの正式名 */ char **n_aliases; /* 別名リスト */ int n_addrtype; /* ネット番号のタイプ */ unsigned long n_net; /* ネット番号 */ }; .Ed .Pp この構造体のメンバは次のとおりです。 .Bl -tag -width n_addrtype .It Fa n_name ネットワークの正式名。 .It Fa n_aliases ネットワークの別名 (エイリアス) の 0 で終わるリスト。 .It Fa n_addrtype 返されるネットワーク番号のタイプであり、現在は .Dv AF_INET だけです。 .It Fa n_net ネットワーク番号。 ネットワーク番号は、マシンバイトオーダで返されます。 .El .Pp .Fn getnetent 関数はファイルの次の行を読み込みます。 この際、必要ならば目的のファイルをオープンします。 .Pp .Fn setnetent 関数は、目的のファイルをオープンしリワインドします。 .Fa stayopen フラグが 0 でなければ、 .Fn getnetbyname または .Fn getnetbyaddr のそれぞれの呼び出しの後でも、ネットデータベースはクローズされません。 .Pp .Fn endnetent 関数はファイルをクローズします。 .Pp .Fn getnetbyname 関数および .Fn getnetbyaddr は、適合するネット名またはネットアドレスおよびタイプが見つかるか、または .Dv EOF に達するまで、ファイルを最初から順次検索します。 .Fa type は .Dv AF_INET でなければなりません。 ネットワーク番号はホストオーダで返されます。 .Sh 関連ファイル .Bl -tag -width /etc/networks -compact .It Pa /etc/networks .El .Sh 診断 .Dv EOF またはエラーの場合は、 ヌルポインタ (0) が返ります。 .Sh 関連項目 .Xr networks 5 .Pp .%T RFC 1101 .Sh 歴史 .Fn getnetent , .Fn getnetbyaddr , .Fn getnetbyname , .Fn setnetent , .Fn endnetent 関数は、 .Bx 4.2 で登場しました。 .Sh バグ これらの関数で使用されるデータ空間は静的です。 後でこのデータを使う必要がある場合は、以後のこれら関数の呼び出しで データが上書きされる前に、コピーして保存する必要があります。 データとして受け入れられるのは現在、インターネットネットワーク番号だけです。 ネットワーク番号が 32 ビットを超えない範囲に収まっていると期待するのは、 おそらく素朴過ぎます。