ga_unix.lc 2.0 KB

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