windisplay.c revision 35c4bbdf
135c4bbdfSmrg/*
235c4bbdfSmrg * File: windisplay.c
335c4bbdfSmrg * Purpose: Retrieve server display name
435c4bbdfSmrg *
535c4bbdfSmrg * Copyright (C) Jon TURNEY 2009
635c4bbdfSmrg *
735c4bbdfSmrg * Permission is hereby granted, free of charge, to any person obtaining a
835c4bbdfSmrg * copy of this software and associated documentation files (the "Software"),
935c4bbdfSmrg * to deal in the Software without restriction, including without limitation
1035c4bbdfSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1135c4bbdfSmrg * and/or sell copies of the Software, and to permit persons to whom the
1235c4bbdfSmrg * Software is furnished to do so, subject to the following conditions:
1335c4bbdfSmrg *
1435c4bbdfSmrg * The above copyright notice and this permission notice (including the next
1535c4bbdfSmrg * paragraph) shall be included in all copies or substantial portions of the
1635c4bbdfSmrg * Software.
1735c4bbdfSmrg *
1835c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1935c4bbdfSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2035c4bbdfSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2135c4bbdfSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2235c4bbdfSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2335c4bbdfSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2435c4bbdfSmrg * DEALINGS IN THE SOFTWARE.
2535c4bbdfSmrg *
2635c4bbdfSmrg */
2735c4bbdfSmrg
2835c4bbdfSmrg#ifdef HAVE_XWIN_CONFIG_H
2935c4bbdfSmrg#include <xwin-config.h>
3035c4bbdfSmrg#endif
3135c4bbdfSmrg
3235c4bbdfSmrg#include <opaque.h>             // for display
3335c4bbdfSmrg#include "windisplay.h"
3435c4bbdfSmrg#include "winmsg.h"
3535c4bbdfSmrg
3635c4bbdfSmrg#define XSERV_t
3735c4bbdfSmrg#define TRANS_SERVER
3835c4bbdfSmrg#include <X11/Xtrans/Xtrans.h>
3935c4bbdfSmrg
4035c4bbdfSmrg/*
4135c4bbdfSmrg  Generate a display name string referring to the display of this server,
4235c4bbdfSmrg  using a transport we know is enabled
4335c4bbdfSmrg*/
4435c4bbdfSmrg
4535c4bbdfSmrgvoid
4635c4bbdfSmrgwinGetDisplayName(char *szDisplay, unsigned int screen)
4735c4bbdfSmrg{
4835c4bbdfSmrg    if (_XSERVTransIsListening("local")) {
4935c4bbdfSmrg        snprintf(szDisplay, 512, ":%s.%d", display, screen);
5035c4bbdfSmrg    }
5135c4bbdfSmrg    else if (_XSERVTransIsListening("inet")) {
5235c4bbdfSmrg        snprintf(szDisplay, 512, "127.0.0.1:%s.%d", display, screen);
5335c4bbdfSmrg    }
5435c4bbdfSmrg    else if (_XSERVTransIsListening("inet6")) {
5535c4bbdfSmrg        snprintf(szDisplay, 512, "::1:%s.%d", display, screen);
5635c4bbdfSmrg    }
5735c4bbdfSmrg    else {
5835c4bbdfSmrg        // this can't happen!
5935c4bbdfSmrg        ErrorF("winGetDisplay: Don't know what to use for DISPLAY\n");
6035c4bbdfSmrg        snprintf(szDisplay, 512, "localhost:%s.%d", display, screen);
6135c4bbdfSmrg    }
6235c4bbdfSmrg
6335c4bbdfSmrg    winDebug("winGetDisplay: DISPLAY=%s\n", szDisplay);
6435c4bbdfSmrg}
65