Skip to content

Instantly share code, notes, and snippets.

@pystone
Created June 18, 2014 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pystone/87ead03a9c3a75660bb9 to your computer and use it in GitHub Desktop.
Save pystone/87ead03a9c3a75660bb9 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main() {
char hostname[100] = {0};
int res = gethostname(hostname, sizeof(hostname));
printf("Old host name: %s. (Return %d)\n", hostname, res);
strcpy(hostname, "bambooshark.ics.cs.cmu.edu");
res = sethostname(hostname, strlen(hostname));
gethostname(hostname, sizeof(hostname));
printf("New host name: %s. (Return %d)\n", hostname, res);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment