「C ホスト情報」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==C ホスト情報== [Programming C] ====gethostname==== #include <unistd.h> int gethostname(char *name, size_t namelen); *machine の network名を文字列…」) |
|||
1行目: | 1行目: | ||
==C ホスト情報== | ==C ホスト情報== | ||
− | [Programming C] | + | [[Programming C]] |
====gethostname==== | ====gethostname==== | ||
− | #include | + | #include <unistd.h> |
int gethostname(char *name, size_t namelen); | int gethostname(char *name, size_t namelen); | ||
10行目: | 10行目: | ||
*成功すると、0、それ以外は、-1を返す。 | *成功すると、0、それ以外は、-1を返す。 | ||
− | #include | + | #include <unistd.h> |
− | #include | + | #include <stdio.h> |
− | #include | + | #include <stdlib.h> |
int main() | int main() | ||
27行目: | 27行目: | ||
====uname==== | ====uname==== | ||
− | #include | + | #include <sys/utsname.h> |
int uname(struct utsname *name); | int uname(struct utsname *name); | ||
53行目: | 53行目: | ||
|} | |} | ||
− | #include | + | #include <sys/utsname.h> |
− | #include | + | #include <stdio.h> |
− | #include | + | #include <stdlib.h> |
int main() | int main() | ||
{ | { | ||
71行目: | 71行目: | ||
====gethostid==== | ====gethostid==== | ||
− | #include | + | #include <unistd.h> |
long gethostid(void); | long gethostid(void); | ||
*host computer が持つ一意の値を返す。 | *host computer が持つ一意の値を返す。 | ||
− | #include | + | #include <unistd.h> |
− | #include | + | #include <stdio.h> |
− | #include | + | #include <stdlib.h> |
int main() | int main() |
2020年2月15日 (土) 08:01時点における版
C ホスト情報
gethostname
#include <unistd.h> int gethostname(char *name, size_t namelen);
- machine の network名を文字列 name に書き込みます。
- 文字列nameは、少なくとも namelen文字の長さを持つものとして扱われる。
- 成功すると、0、それ以外は、-1を返す。
#include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { char computer[256]; if ( gethostname(computer, 255) != 0 ) { printf("Can't get hostname.\n"); exit(1); } printf("hostname : %s\n", computer); exit(0); }
uname
#include <sys/utsname.h> int uname(struct utsname *name);
- host computer に対してさらに詳しい情報を得る。
member | 説明 |
---|---|
char sysname[] | operationg system 名 |
char nodename[] | host名 |
char release[] | systemのrelease level |
char version[] | systemのversion 番号 |
char machine[] | hardware の種類 |
#include <sys/utsname.h> #include <stdio.h> #include <stdlib.h> int main() { struct utsname uts; if ( uname(&uts) != 0 ) { printf("Can't get information.\n"); exit(1); } printf("os name : %s\n", uts.sysname ); printf("host name : %s\n", uts.nodename ); printf("release : %s\n", uts.release ); printf("version : %s\n", uts.version ); printf("machine : %s\n", uts.machine ); }
gethostid
#include <unistd.h> long gethostid(void);
- host computer が持つ一意の値を返す。
#include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { long hid = gethostid(); printf("host id : %x\n", hid); exit(0); }
この本からの覚書。
© 2006 矢木浩人