ga_unix.c 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "gai_hdr.h"
  2. #include <sys/utsname.h>
  3. #ifdef UNIXdomain
  4. /* include ga_unix */
  5. int
  6. ga_unix(const char *path, struct addrinfo *hintsp, struct addrinfo **result)
  7. {
  8. int rc;
  9. struct addrinfo *aihead, **aipnext;
  10. aihead = NULL;
  11. aipnext = &aihead;
  12. if (hintsp->ai_family != AF_UNSPEC && hintsp->ai_family != AF_LOCAL)
  13. return(EAI_ADDRFAMILY);
  14. if (hintsp->ai_socktype == 0) {
  15. /* 4no socket type specified: return stream then dgram */
  16. hintsp->ai_socktype = SOCK_STREAM;
  17. if ( (rc = ga_aistruct(&aipnext, hintsp, path, AF_LOCAL)) != 0)
  18. return(rc);
  19. hintsp->ai_socktype = SOCK_DGRAM;
  20. }
  21. if ( (rc = ga_aistruct(&aipnext, hintsp, path, AF_LOCAL)) != 0)
  22. return(rc);
  23. if (hintsp->ai_flags & AI_CANONNAME) {
  24. struct utsname myname;
  25. if (uname(&myname) < 0)
  26. return(EAI_SYSTEM);
  27. if ( (aihead->ai_canonname = strdup(myname.nodename)) == NULL)
  28. return(EAI_MEMORY);
  29. }
  30. *result = aihead; /* pointer to first structure in linked list */
  31. return(0);
  32. }
  33. /* end ga_unix */
  34. #endif /* UNIXdomain */