getdnnm.c 376 B

123456789101112131415161718192021222324
  1. #include <string.h>
  2. #include <unistd.h>
  3. #include <sys/utsname.h>
  4. #include <errno.h>
  5. int
  6. getdomainname(char *name, size_t len)
  7. {
  8. struct utsname uts;
  9. if (name == NULL) {
  10. errno = EINVAL;
  11. return -1;
  12. }
  13. if (uname(&uts) == -1) return -1;
  14. if (strlen(uts.domainname)+1 > len) {
  15. errno = EINVAL;
  16. return -1;
  17. }
  18. strcpy(name, uts.domainname);
  19. return 0;
  20. }