4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <avahi-client/client.h>
33 #include <avahi-common/strlst.h>
34 #include <avahi-common/malloc.h>
35 #include <avahi-common/domain.h>
39 int main(int argc, char*argv[]) {
42 gtk_init(&argc, &argv);
44 if (g_str_has_suffix(argv[0], "zvnc")) {
45 d = aui_service_dialog_new("Choose VNC server");
46 aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL);
48 d = aui_service_dialog_new("Choose SSH server");
49 aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_ssh._tcp", NULL);
52 aui_service_dialog_set_resolve_service(AUI_SERVICE_DIALOG(d), TRUE);
53 aui_service_dialog_set_resolve_host_name(AUI_SERVICE_DIALOG(d), !avahi_nss_support());
55 gtk_window_present(GTK_WINDOW(d));
57 if (gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_OK) {
58 char a[AVAHI_ADDRESS_STR_MAX], *u = NULL;
59 char *h = NULL, *t = NULL;
60 const AvahiStringList *txt;
62 t = g_strdup(aui_service_dialog_get_service_type(AUI_SERVICE_DIALOG(d)));
64 if (avahi_nss_support())
65 h = g_strdup(aui_service_dialog_get_host_name(AUI_SERVICE_DIALOG(d)));
67 h = g_strdup(avahi_address_snprint(a, sizeof(a), aui_service_dialog_get_address(AUI_SERVICE_DIALOG(d))));
69 if (avahi_domain_equal(t, "_rfb._tcp")) {
70 char p[AVAHI_DOMAIN_NAME_MAX+16];
71 snprintf(p, sizeof(p), "%s:%u", h, aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d))-5900);
73 gtk_widget_destroy(d);
75 g_print("xvncviewer %s\n", p);
76 execlp("xvncviewer", "xvncviewer", p, NULL);
80 snprintf(p, sizeof(p), "%u", aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d)));
82 for (txt = aui_service_dialog_get_txt_data(AUI_SERVICE_DIALOG(d)); txt; txt = txt->next) {
85 if (avahi_string_list_get_pair((AvahiStringList*) txt, &key, &value, NULL) < 0)
88 if (strcmp(key, "u") == 0)
95 gtk_widget_destroy(d);
98 g_print("ssh -p %s -l %s %s\n", p, u, h);
99 execlp("ssh", "ssh", "-p", p, "-l", u, h, NULL);
101 g_print("ssh -p %s %s\n", p, h);
102 execlp("ssh", "ssh", "-p", p, h, NULL);
106 g_warning("execlp() failed: %s", strerror(errno));
113 gtk_widget_destroy(d);
115 g_print("Canceled.\n");