#ifdef HAVE_CONFIG_H#include#endif#include "roken.h"#ifndef HAVE_GETHOSTNAME#ifdef HAVE_SYS_UTSNAME_H#include #endif/** * Return the local host's name in "name", up to "namelen" characters. * "name" will be null-terminated if "namelen" is big enough. * The return code is 0 on success, -1 on failure. (The calling * interface is identical to gethostname(2).) */int ROKEN_LIB_FUNCTIONgethostname(char *name, int namelen){#if defined(HAVE_UNAME) { struct utsname utsname; int ret; ret = uname (&utsname); if (ret < 0) return ret; strlcpy (name, utsname.nodename, namelen); return 0; }#else strlcpy (name, "some.random.host", namelen); return 0;#endif}#endif /** GETHOSTNAME *//*utsname结构体在sys/utsname.h里面定义struct utsname{ char sysname[_SYS_NMLN]; 系统名称 uname -s char nodename[_SYS_NMLN]; 主机节点名称 uname -n char release[_SYS_NMLN]; 系统发布版本 uame -r char version[_SYS_NMLN]; 系统版本 uname -v char machine[_SYS_NMLN]; 系统硬件架构 uname -m};*/