.\" 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. .\" .\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94 .\" %Id: getservent.3,v 1.5 1997/02/22 15:00:13 peter Exp % .\" .Dd July 9, 1995 .Dt GETSERVENT 3 .Os BSD 4.2 .Sh 名称 .Nm getservent , .Nm getservbyport , .Nm getservbyname , .Nm setservent , .Nm endservent .Nd サービスエントリを取得 .Sh 書式 .Fd #include .Ft struct servent * .Fn getservent .Ft struct servent * .Fn getservbyname "const char *name" "const char *proto" .Ft struct servent * .Fn getservbyport "int port" "const char *proto" .Ft void .Fn setservent "int stayopen" .Ft void .Fn endservent void .Sh 解説 .Fn getservent 、 .Fn getservbyname および .Fn getservbyport 関数はそれぞれ、次に 示す構造体を持つオブジェクトのポインタを返します。構造体には ネットワークサービスデータベース .Pa /etc/services にある、行の内訳フィールドが 含まれます。 .Bd -literal -offset indent struct servent { char *s_name; /* サービスのオフィシャル名 */ char **s_aliases; /* エイリアスリスト */ int s_port; /* サービスが常駐するポート */ char *s_proto; /* 使用するプロトコル */ }; .Ed この構造体のメンバは次のとおりです。 .Bl -tag -width s_aliases .It Fa s_name サービスのオフィシャル名。 .It Fa s_aliases サービスのゼロで終わる別名 (エイリアス) リスト。 .It Fa s_port サービスが常駐するポート番号。ポート番号は ネットワークバイト順で返されます。 .It Fa s_proto サービスとのコンタクト中に使用するプロトコル名。 .El .Pp .Fn getservent 関数は、必要ならばファイルをオープンして次の行を読み込みます。 .Pp .Fn setservent 関数はファイルをオープンしリワインドします。 .Fa stayopen フラグがゼロでなければ、 .Fn getservbyname または .Fn getservbyport の各呼び出し後に、 ネットデータベースはクローズされません。 .Pp .Fn endservent 関数はファイルをクローズします。 .Pp 適合するプロトコル名またはポート番号が見付かるか、さもなければ .Dv EOF に 出会うまで、 .Fn getservbyname および .Fn getservbyport 関数は最初から順次 ファイルを検索します。プロトコル名が供給されていても( .Dv NULL でなくても) 、検索は適合するプロトコルが見付かるまで続けられます。 .ne 1i .Sh 関連ファイル .Bl -tag -width /etc/services -compact .It Pa /etc/services .El .Sh 診断 .Dv EOF またはエラーの場合、 Null ポインタ (0) が返ります。 .Sh 関連項目 .Xr getprotoent 3 、 .Xr services 5 .Sh 歴史 .Fn getservent 、 .Fn getservbyport 、 .Fn getservbyname 、 .Fn setservent および .Fn endservent 関数は、 .Bx 4.2 で最初に取り入れられました。 .Sh バグ これらの関数は静的データストレージを使用します。後で使用する必要があれば、 以後の呼び出しで上書きする前にデータをコピーして保存する必要があります。 ポート番号がすべて 32 ビットに適合すると考えるのは、たぶん素朴過ぎます。