diff options
Diffstat (limited to 'polyp')
-rw-r--r-- | polyp/pax11publish.c | 13 | ||||
-rw-r--r-- | polyp/util.c | 20 | ||||
-rw-r--r-- | polyp/util.h | 1 |
3 files changed, 32 insertions, 2 deletions
diff --git a/polyp/pax11publish.c b/polyp/pax11publish.c index d1391dcf..fc1d6ab7 100644 --- a/polyp/pax11publish.c +++ b/polyp/pax11publish.c @@ -87,7 +87,12 @@ int main(int argc, char *argv[]) { dname = optarg; break; case 'h': - printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n", pa_path_get_filename(argv[0])); + printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n" + " -d Show current Polypaudio data attached to X11 display (default)\n" + " -e Export local Polypaudio data to X11 display\n" + " -i Import Polypaudio data from X11 display to local environment variables and cookie file.\n" + " -r Remove Polypaudio data from X11 display\n", + pa_path_get_filename(argv[0])); ret = 0; goto finish; case 'd': @@ -195,7 +200,11 @@ int main(int argc, char *argv[]) { set_x11_prop(d, "POLYP_SERVER", c->default_server); else { char hn[256]; - pa_get_host_name(hn, sizeof(hn)); + if (!pa_get_fqdn(hn, sizeof(hn))) { + fprintf(stderr, "Failed to get FQDN.\n"); + goto finish; + } + set_x11_prop(d, "POLYP_SERVER", hn); } diff --git a/polyp/util.c b/polyp/util.c index b4c16dbb..ad91a307 100644 --- a/polyp/util.c +++ b/polyp/util.c @@ -43,6 +43,7 @@ #include <limits.h> #include <unistd.h> #include <grp.h> +#include <netdb.h> #include <samplerate.h> @@ -773,3 +774,22 @@ size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) { return j; } + +char *pa_get_fqdn(char *s, size_t l) { + char hn[256]; + struct addrinfo *a, hints; + + if (!pa_get_host_name(hn, sizeof(hn))) + return NULL; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + + if (getaddrinfo(hn, NULL, &hints, &a) < 0 || !a || !a->ai_canonname || !*a->ai_canonname) + return pa_strlcpy(s, hn, l); + + pa_strlcpy(s, a->ai_canonname, l); + freeaddrinfo(a); + return s; +} diff --git a/polyp/util.h b/polyp/util.h index 2448b0fa..3f09a9a7 100644 --- a/polyp/util.h +++ b/polyp/util.h @@ -46,6 +46,7 @@ char *pa_strlcpy(char *b, const char *s, size_t l); char *pa_get_user_name(char *s, size_t l); char *pa_get_host_name(char *s, size_t l); +char *pa_get_fqdn(char *s, size_t l); char *pa_get_binary_name(char *s, size_t l); char *pa_get_home_dir(char *s, size_t l); |