#include #include #include #include #include int main() { int retval; char hostname[__NEW_UTS_LEN]; // Print out current hostname if ((retval = gethostname(hostname, __NEW_UTS_LEN)) == -1) { printf("call to gethostname() failed, retval=%d: %s\n", retval, strerror(errno)); return 1; }; printf("gethostname()=\"%s\"\n", hostname); // Set "new" hostname if ((retval = sethostname((char *)-1, 10)) != -1) { // We really EXPECT this to fail! printf("The Penguin is in trouble!\n"); return 2; } else printf("sethostname(INVALID, 10)=%d (error \"%s\")\n", retval, strerror(errno)); // And now once again: if ((retval = gethostname(hostname, __NEW_UTS_LEN)) == -1) { printf("call to gethostname() failed, retval=%d: %s\n", retval, strerror(errno)); return 1; }; printf("gethostname()=\"%s\"\n", hostname); return 0; };