ga_unixstruct.c 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "gai_hdr.h"
  2. #ifdef UNIXDOMAIN
  3. int
  4. ga_unixstruct(const char *path, struct addrinfo *hintsp,
  5. struct addrinfo **result, int socktype)
  6. {
  7. struct addrinfo *ai;
  8. struct sockaddr_un *unp;
  9. if ( (ai = calloc(1, sizeof(struct addrinfo))) == NULL)
  10. return(EAI_MEMORY);
  11. ai->ai_flags = 0;
  12. ai->ai_family = AF_LOCAL;
  13. ai->ai_socktype = socktype;
  14. ai->ai_protocol = 0;
  15. /* allocate and fill in a socket address structure */
  16. ai->ai_addrlen = sizeof(struct sockaddr_un);
  17. if ( (ai->ai_addr = malloc(ai->ai_addrlen)) == NULL)
  18. return(EAI_MEMORY);
  19. unp = (struct sockaddr_un *) ai->ai_addr;
  20. unp->sun_family = AF_UNIX;
  21. strncpy(unp->sun_path, path, sizeof(unp->sun_path));
  22. ai->ai_canonname = NULL;
  23. ai->ai_next = NULL;
  24. *result = ai;
  25. if (hintsp->ai_flags & AI_PASSIVE)
  26. unlink(path); /* OK if this fails */
  27. return(0); /* success */
  28. }
  29. #endif /* UNIXDOMAIN */