40 const struct addrinfo *hintsp,
41 struct addrinfo **result);
44 char *node,
int nodelen,
45 char *service,
int servicelen,
54 const struct addrinfo *hintp,
struct addrinfo **result)
61 if (hintp->ai_family == AF_UNIX)
66 servname, hintp, result);
84 if (hint_ai_family == AF_UNIX)
89 struct addrinfo *p = ai;
115 char *node,
int nodelen,
116 char *service,
int servicelen,
121 if (addr && addr->ss_family == AF_UNIX)
127 rc = getnameinfo((
const struct sockaddr *) addr, salen,
137 strlcpy(service,
"???", servicelen);
154 struct addrinfo **result)
156 struct addrinfo hints = {0};
157 struct addrinfo *aip;
162 if (strlen(path) >=
sizeof(unp->
sun_path))
167 hints.ai_family = AF_UNIX;
168 hints.ai_socktype = SOCK_STREAM;
171 memcpy(&hints, hintsp,
sizeof(hints));
173 if (hints.ai_socktype == 0)
174 hints.ai_socktype = SOCK_STREAM;
176 if (hints.ai_family != AF_UNIX)
182 aip =
calloc(1,
sizeof(
struct addrinfo));
193 aip->ai_family = AF_UNIX;
194 aip->ai_socktype = hints.ai_socktype;
195 aip->ai_protocol = hints.ai_protocol;
197 aip->ai_canonname = NULL;
201 aip->ai_addr = (
struct sockaddr *) unp;
229 char *node,
int nodelen,
230 char *service,
int servicelen,
236 if (
sa == NULL ||
sa->sun_family != AF_UNIX ||
237 (node == NULL && service == NULL))
242 ret =
snprintf(node, nodelen,
"%s",
"[local]");
243 if (ret < 0 || ret >= nodelen)
253 if (
sa->sun_path[0] ==
'\0' &&
sa->sun_path[1] !=
'\0')
254 ret =
snprintf(service, servicelen,
"@%s",
sa->sun_path + 1);
256 ret =
snprintf(service, servicelen,
"%s",
sa->sun_path);
257 if (ret < 0 || ret >= servicelen)
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
static int getnameinfo_unix(const struct sockaddr_un *sa, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
static int getaddrinfo_unix(const char *path, const struct addrinfo *hintsp, struct addrinfo **result)
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
size_t strlcpy(char *dst, const char *src, size_t siz)
unsigned short sun_family