Unix-system-calls-gethostname
[top]#
|http://www.google.com/[Google] | a|
Web | This Site |
選択した読書 Copyright©2014 by finddevguides |
[cols=",,,,,,,",] |
| | Home | | References | | Discussion Forums | | About TP
[width="100%",cols="100%",] |
a| == gethostname()-Unix、Linuxシステムコール
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] image:http://www.finddevguides.com/add- this.gif [AddThisソーシャルブックマークボタン]
広告
NAME
gethostname、sethostname-ホスト名の取得/設定
概要
- #include <unistd.h> *
- int gethostname(char * name 、size_t len ); * * int sethostname(const char * name 、size_t len *); * *
説明
これらのシステムコールは、現在のプロセッサのホスト名へのアクセスまたは変更に使用されます。* gethostname ()システムコールは、_len_バイトの長さを持つ配列_name_に、( *sethostname ()で以前に設定された)ヌルで終了するホスト名を返します。 nullで終わるホスト名が収まらない場合、エラーは返されませんが、ホスト名は切り捨てられます。 切り捨てられたホスト名がヌルで終了するかどうかは指定されていません。
返り値
成功すると、ゼロが返されます。 エラーの場合、-1が返され、_errno_が適切に設定されます。
エラー
Tag | Description |
---|---|
EFAULT | name is an invalid address. |
*EINVAL * | len is negative or, for* sethostname*(), len is larger than the maximum allowed size, or, for gethostname() on Linux/i386, len is smaller than the actual size. (In this last case glibc 2.1 uses ENAMETOOLONG.) |
*EPERM * | For* sethostname*(), the caller did not have the CAP_SYS_ADMIN capability. |
準拠
SVr4、4.4BSD(このインターフェースは4.2BSDで初めて登場しました)。 POSIX.1-2001は gethostname ()を指定しますが、 sethostname ()は指定しません。
ノート
SUSv2は、「ホスト名が255バイトに制限される」ことを保証します。 POSIX.1-2001は、「ホスト名(終端のヌルバイトを含まない)はHOST_NAME_MAXバイトに制限される」ことを保証します。
GLIBCノート
GNU Cライブラリは gethostname ()を uname (2)を呼び出すライブラリ関数として実装し、返された_nodename_フィールドから_len_バイトまでを_name_にコピーします。 コピーを実行すると、関数は_nodename_の長さが_len_以上であるかどうかを確認し、そうである場合、_errno_を ENAMETOOLONG に設定して-1を返します。 2.2より前のglibcのバージョンは、_nodename_の長さが_len_以上の場合を処理します。_name_には何もコピーされず、関数は_errno_が ENAMETOOLONG に設定された-1を返します。
関連項目
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] [[File:]]
広告
|
[cols="^",] |
|Advertisements