X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_util.c;h=8c2a0312e24f000064e7c96db283815d58c00414;hb=3f79628becbd3b0eff1aef804902eb739fac4403;hp=287f12fd93781933a33887298c769dd16f089e47;hpb=d06857217328c2283a8956788d72646fc67216fb;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_util.c b/src/xcb_util.c index 287f12f..8c2a031 100644 --- a/src/xcb_util.c +++ b/src/xcb_util.c @@ -129,7 +129,7 @@ int xcb_parse_display(const char *name, char **host, int *displayp, return _xcb_parse_display(name, host, NULL, displayp, screenp); } -static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port); +static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port); static int _xcb_open_unix(char *protocol, const char *file); #ifdef DNETCONN static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port); @@ -138,24 +138,25 @@ static int _xcb_open_decnet(const char *host, char *protocol, const unsigned sho static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen); #endif -static int _xcb_open(char *host, char *protocol, const int display) +static int _xcb_open(const char *host, char *protocol, const int display) { -#ifdef HAVE_ABSTRACT_SOCKETS int fd; -#endif static const char unix_base[] = "/tmp/.X11-unix/X"; const char *base = unix_base; - char file[PATH_MAX + 1]; - int filelen; + size_t filelen; + char *file = NULL; + int actual_filelen; - if(*host) - { #ifdef HAVE_LAUNCHD if(strncmp(host, "/tmp/launch", 11) == 0) { - base = host; - } else { + base = host; + host = ""; + protocol = NULL; + } #endif + if(*host || protocol) + { #ifdef DNETCONN /* DECnet displays have two colons, so _xcb_parse_display will have left one at the end. However, an IPv6 address can end with *two* @@ -176,29 +177,40 @@ static int _xcb_open(char *host, char *protocol, const int display) unsigned short port = X_TCP_PORT + display; return _xcb_open_tcp(host, protocol, port); } -#ifdef HAVE_LAUNCHD - } -#endif } + filelen = strlen(base) + 1 + sizeof(display) * 3 + 1; + file = malloc(filelen); + if(file == NULL) + return -1; + /* display specifies Unix socket */ #ifdef HAVE_LAUNCHD - if(base == host) - filelen = snprintf(file, sizeof(file), "%s:%d", base, display); + if(strncmp(base, "/tmp/launch", 11) == 0) + actual_filelen = snprintf(file, filelen, "%s:%d", base, display); else #endif - filelen = snprintf(file, sizeof(file), "%s%d", base, display); - if(filelen < 0) + actual_filelen = snprintf(file, filelen, "%s%d", base, display); + if(actual_filelen < 0) + { + free(file); return -1; + } /* snprintf may truncate the file */ - filelen = MIN(filelen, sizeof(file) - 1); + filelen = MIN(actual_filelen, filelen - 1); #ifdef HAVE_ABSTRACT_SOCKETS fd = _xcb_open_abstract(protocol, file, filelen); if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED)) + { + free(file); return fd; + } #endif - return _xcb_open_unix(protocol, file); + fd = _xcb_open_unix(protocol, file); + free(file); + + return fd; } static int _xcb_socket(int family, int type, int proto) @@ -257,7 +269,7 @@ static int _xcb_open_decnet(const char *host, const char *protocol, const unsign } #endif -static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port) +static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port) { int fd = -1; struct addrinfo hints; @@ -265,8 +277,15 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port) struct addrinfo *results, *addr; char *bracket; - if (protocol && strcmp("tcp",protocol)) + if (protocol && strcmp("tcp",protocol) && strcmp("inet",protocol) +#ifdef AF_INET6 + && strcmp("inet6",protocol) +#endif + ) return -1; + + if (*host == '\0') + host = "localhost"; memset(&hints, 0, sizeof(hints)); #ifdef AI_ADDRCONFIG