Exemplo n.º 1
0
static gboolean
check_for_dns (void)
{
#ifdef HAVE_GETADDRINFO
  struct addrinfo *result = NULL;
  struct addrinfo  hints;
#endif
  char   buffer[256];
  gchar *hostname;

  hostname = queryhostname (buffer, 256, FALSE);
  if (hostname == NULL)
    return FALSE;

#ifdef HAVE_GETADDRINFO
  bzero (&hints, sizeof (hints));
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_CANONNAME;

  if (getaddrinfo (hostname, NULL, &hints, &result) != 0)
    return FALSE;

  if (g_ascii_strncasecmp (result->ai_canonname, hostname, 0) != 0)
    return FALSE;
#else
#ifdef HAVE_GETHOSTBYNAME
  if (gethostbyname (hostname) == NULL)
    {
      return FALSE;
    }
#endif
#endif

  return TRUE;
}
Exemplo n.º 2
0
void
xfsm_dns_check (void)
{
  GtkWidget *msgbox = NULL;
  gchar      hostname[256];
  gint       response;

  while (!check_for_dns ())
    {
      if (msgbox == NULL)
        {
          GdkScreen *screen = xfce_gdk_screen_get_active (NULL);

          queryhostname (hostname, 256, TRUE);

          msgbox = gtk_message_dialog_new (NULL, 0,
                                           GTK_MESSAGE_WARNING,
                                           GTK_BUTTONS_NONE,
                                           _("Could not look up internet address for %s.\n"
                                             "This will prevent Xfce from operating correctly.\n"
                                             "It may be possible to correct the problem by adding\n"
                                             "%s to the file /etc/hosts on your system."),
                                           hostname, hostname);

          gtk_dialog_add_buttons (GTK_DIALOG (msgbox),
                                  _("Continue anyway"), RESPONSE_LOG_IN,
                                  _("Try again"), RESPONSE_TRY_AGAIN,
                                  NULL);

          gtk_window_set_screen (GTK_WINDOW (msgbox), screen);
          gtk_container_set_border_width (GTK_CONTAINER (msgbox), 6);
          gtk_window_set_position (GTK_WINDOW (msgbox), GTK_WIN_POS_CENTER);
        }

      gtk_dialog_set_default_response (GTK_DIALOG (msgbox), RESPONSE_TRY_AGAIN);

      response = gtk_dialog_run (GTK_DIALOG (msgbox));
      if (response != RESPONSE_TRY_AGAIN)
        break;

      gtk_widget_hide (msgbox);
    }

  if (msgbox != NULL)
    gtk_widget_destroy (msgbox);
}