Hi Sun AFAIK, the second parameter (len) in gethostname is an input parameter, specifying the length of the array your passing as the first parameter. The name of the host will be placed in the array, but it will truncated after len characters.
I don't know how to determine the length of the host name, but i think on most systems it must be less than 255. Jody On Mon, Nov 17, 2008 at 10:31 AM, Sun, Yongqi (E F ES EN 72) <yongqi....@siemens.com> wrote: > 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 > > _______________________________________________ > users mailing list > us...@open-mpi.org > http://www.open-mpi.org/mailman/listinfo.cgi/users >