#include <unistd.h>
int gethostname(char *name, size_t namelen);
#include <sys/utsname.h>
int uname(struct utsname *name);
01 #include <sys/utsname.h>
02 #include <unistd.h>
03 #include <stdio.h>
04 #include <stdlib.h>
05
06 int main()
07 {
08 char computer[256];
09 struct utsname uts;
10
11 if(gethostname(computer, 255) != 0 || uname(&uts) < 0) {
12 fprintf(stderr, "Could not get host information\n");
13 exit(1);
14 }
15
16 printf("Computer host name is %s\n", computer);
17
18 printf("System is %s on %s hardware\n", uts.sysname, uts.machine);
19 printf("Nodename is %s\n", uts.nodename);
20 printf("Version is %s, %s\n", uts.release, uts.version);
21 exit(0);
22 }
[root@localhost C]# ./hostget.exe
Computer host name is localhost.localdomain
System is Linux on i686 hardware
Nodename is localhost.localdomain
Version is 2.6.18-92.1.22.el5xen, #1 SMP Tue Dec 16 13:08:49 EST 2008
#include <unistd.h>
long gethostid(void);
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |