hostname.c 421 B

123456789101112131415161718192021222324
  1. /* hostname.c - poe@daimi.aau.dk */
  2. #include "sash.h"
  3. #include <sys/types.h>
  4. #include <sys/param.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. void do_hostname(int argc, char **argv)
  8. {
  9. char hn[PATHLEN + 1];
  10. if(argc >= 2) {
  11. if(strlen(argv[1]) > PATHLEN) {
  12. printf("That name is too long.\n");
  13. } else {
  14. sethostname(argv[1], strlen(argv[1]));
  15. }
  16. } else {
  17. gethostname(hn, PATHLEN);
  18. printf("%s\n", hn);
  19. }
  20. }