diff options
author | Pierre Ossman <ossman@cendio.se> | 2006-01-05 17:43:06 +0000 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2006-01-05 17:43:06 +0000 |
commit | 70223bac46f53f89041db61d2a06ea772968ce2d (patch) | |
tree | eb5ed55d62e1e65258051e2f8d41a41cf4b45c34 | |
parent | 3f2ac7eb8ce8db8947f1bfc195f845be0d409fde (diff) |
Fallbacks for systems that do not have getaddrinfo(). Does not handle
IPv6 though.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/ossman@369 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | polyp/socket-client.c | 32 | ||||
-rw-r--r-- | polyp/util.c | 6 |
3 files changed, 37 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index c8511643..450f18ad 100644 --- a/configure.ac +++ b/configure.ac @@ -166,8 +166,8 @@ AC_CHECK_LIB([m], [pow]) AC_FUNC_FORK AC_FUNC_GETGROUPS AC_FUNC_SELECT_ARGTYPES -AC_CHECK_FUNCS([ftruncate getgrgid_r getpwuid_r gettimeofday getuid \ - inet_ntop mkfifo nanosleep sigaction sleep]) +AC_CHECK_FUNCS([getaddrinfo ftruncate getgrgid_r getpwuid_r gettimeofday \ + getuid inet_ntop mkfifo nanosleep sigaction sleep]) AM_CONDITIONAL(HAVE_MKFIFO, test "x$HAVE_MKFIFO" = "x1") diff --git a/polyp/socket-client.c b/polyp/socket-client.c index f02b74bd..40bbcc3e 100644 --- a/polyp/socket-client.c +++ b/polyp/socket-client.c @@ -426,8 +426,9 @@ struct pa_socket_client* pa_socket_client_new_string(struct pa_mainloop_api *m, assert(c->asyncns_query); start_timeout(c); } -#else +#else /* HAVE_LIBASYNCNS */ { +#ifdef HAVE_GETADDRINFO int ret; struct addrinfo *res = NULL; @@ -438,12 +439,37 @@ struct pa_socket_client* pa_socket_client_new_string(struct pa_mainloop_api *m, if (res->ai_addr) { if ((c = pa_socket_client_new_sockaddr(m, res->ai_addr, res->ai_addrlen))) - start_timeout(c); + start_timeout(c); } freeaddrinfo(res); +#else /* HAVE_GETADDRINFO */ + struct hostent *host = NULL; + struct sockaddr_in s; + + /* FIXME: PF_INET6 support */ + if (hints.ai_family != PF_INET) + goto finish; + + host = gethostbyname(a.path_or_host); + if (!host) { + unsigned int addr = inet_addr(a.path_or_host); + if (addr != INADDR_NONE) + host = gethostbyaddr((char*)&addr, 4, AF_INET); + } + + if (!host) + goto finish; + + s.sin_family = AF_INET; + memcpy(&s.sin_addr, host->h_addr, sizeof(struct in_addr)); + s.sin_port = port; + + if ((c = pa_socket_client_new_sockaddr(m, &s, sizeof(s)))) + start_timeout(c); +#endif /* HAVE_GETADDRINFO */ } -#endif +#endif /* HAVE_LIBASYNCNS */ } } diff --git a/polyp/util.c b/polyp/util.c index 699480af..2c4285fb 100644 --- a/polyp/util.c +++ b/polyp/util.c @@ -831,11 +831,14 @@ size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) { /* Return the fully qualified domain name in *s */ char *pa_get_fqdn(char *s, size_t l) { char hn[256]; +#ifdef HAVE_GETADDRINFO struct addrinfo *a, hints; +#endif if (!pa_get_host_name(hn, sizeof(hn))) return NULL; +#ifdef HAVE_GETADDRINFO memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_CANONNAME; @@ -846,6 +849,9 @@ char *pa_get_fqdn(char *s, size_t l) { pa_strlcpy(s, a->ai_canonname, l); freeaddrinfo(a); return s; +#else + return pa_strlcpy(s, hn, l); +#endif } /* Returns nonzero when *s starts with *pfx */ |