1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#define _GNU_SOURCE #include <sys/types.h> #include <sys/utsname.h> int gethostname(char *name,size_t len) { struct utsname u; int res=uname(&u); if (res==0) { int i; if (len>=_UTSNAME_NODENAME_LENGTH) len=_UTSNAME_NODENAME_LENGTH; for (i=0; i<len; i++) name[i]=u.nodename[i]; } return res; }