+
+ /* Set up a suitable value for the DISPLAY variable. */
+ if (gethostname(hostname, sizeof(hostname)) < 0)
+ fatal("gethostname: %.100s", strerror(errno));
+ /*
+ * auth_display must be used as the displayname when the
+ * authorization entry is added with xauth(1). This will be
+ * different than the DISPLAY string for localhost displays.
+ */
+ s->auth_display[1] = NULL;
+ if (!options.gateway_ports) {
+ struct utsname uts;
+
+ snprintf(display, sizeof display, "localhost:%d.%d",
+ s->display_number, s->screen);
+ snprintf(auth_display, sizeof auth_display, "%.400s/unix:%d.%d",
+ hostname, s->display_number, s->screen);
+ s->display = xstrdup(display);
+ s->auth_display[0] = xstrdup(auth_display);
+ /*
+ * Xlib may use gethostbyname() or uname() hostname to
+ * look up authorization data for FamilyLocal; see:
+ * xc/lib/xtrans/Xtrans.c:TRANS(GetHostname)
+ * We just add authorization entries with both
+ * hostname and nodename if they are different.
+ */
+ if (uname(&uts) == -1)
+ fatal("uname: %.100s", strerror(errno));
+ if (strcmp(hostname, uts.nodename) != 0) {
+ snprintf(auth_display, sizeof auth_display,
+ "%.400s/unix:%d.%d", uts.nodename,
+ s->display_number, s->screen);
+ s->auth_display[1] = xstrdup(auth_display);
+ }
+ } else {
+#ifdef IPADDR_IN_DISPLAY
+ struct hostent *he;
+ struct in_addr my_addr;
+
+ he = gethostbyname(hostname);
+ if (he == NULL) {
+ error("Can't get IP address for X11 DISPLAY.");
+ packet_send_debug("Can't get IP address for X11 DISPLAY.");
+ return 0;
+ }
+ memcpy(&my_addr, he->h_addr_list[0], sizeof(struct in_addr));
+ snprintf(display, sizeof display, "%.50s:%d.%d", inet_ntoa(my_addr),
+ s->display_number, s->screen);
+#else
+ snprintf(display, sizeof display, "%.400s:%d.%d", hostname,
+ s->display_number, s->screen);
+#endif
+ s->display = xstrdup(display);
+ s->auth_display[0] = xstrdup(display);
+ }
+