Hello,
I still have no clue how to use the local machine by default.
My /etc/hosts file and the result of ifconfig are attached.
I've tried gethostname() by myself but an abnormal result generated.
My code is:
///////////////////////////////////
#include <unistd.h>
#include <stdio.h>
int main() {
char name[20]; // a guess of the array size
size_t len;
int res;
res = gethostname(name, len);
printf("res = %d, name = %s, len = %lu", res, name, len); // on
my 64-bit machine, size_t is long unsigned, or?
return 0;
}
/////////////////////////////////
And the resulting output is:
"res = 0, name = W71c-140644, len = 140737469359496"
Where len is abnormally large.
Best regards
Sun
- application/octet-stream attachment: hosts.out
|