#include <strings.h> #include <unistd.h> #include <stdio.h> int main(){ char host__name[32] = {0}; bzero(host__name,32); char domainname[32] = {0}; bzero(domainname,32); int h = gethostname (host__name,32); int d = getdomainname(domainname,32); if (!h){ printf("host__name:%s ",host__name); } if (!d){ printf("domainname:%s ",domainname); } }