Beispiel #1
0
void
ping_stop (Netinfo * netinfo)
{
	g_return_if_fail (netinfo != NULL);

	netinfo_stop_process_command (netinfo);
}
Beispiel #2
0
void
scan_do (Netinfo * netinfo)
{
	const gchar *host = NULL;
	GtkTreeModel *model;
	gint ip_version;
	gchar *program = NULL;
	gchar *command = NULL;
	GtkWidget *parent;

	g_return_if_fail (netinfo != NULL);

	/* Because of the delay, we can't check twice for a hostname/IP.
	 * It was made before this function was called.  Anyway, we
	 * check at least if we have a text as hostname */
	if (netinfo_validate_domain (netinfo) == FALSE) {
		netinfo_stop_process_command (netinfo);
		return;
	}

	host = netinfo_get_host (netinfo);

	if (netinfo->stbar_text)
		g_free (netinfo->stbar_text);
	netinfo->stbar_text = g_strdup_printf (_("Scanning %s for open ports"), host);

	/* Clear the current output */
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (netinfo->output));
	if (GTK_IS_LIST_STORE (model)) {
		gtk_list_store_clear (GTK_LIST_STORE (model));
	}

	parent = gtk_widget_get_toplevel (netinfo->output);
	program = util_find_program_dialog ("nmap", parent);

	if (program != NULL) {
		ip_version = netinfo_get_ip_version (netinfo);

		if (ip_version == IPV6) {
			command = g_strdup_printf ("%s %s %s %s", program,
						   "nmap", "-6", host);
		} else {
			command = g_strdup_printf ("%s %s %s", program,
						   "nmap", host);
		}
	
		g_strfreev (netinfo->command_line);
		netinfo->command_line = g_strsplit (command, " ", -1);
	
		netinfo_process_command (netinfo);
	}

	g_free (command);
	g_free (program);
}
Beispiel #3
0
void
ping_do (Netinfo * netinfo)
{
	gint count;
	const gchar *host = NULL;
	gchar *command = NULL;
	GtkTreeModel *model;
	GtkLabel *min, *avg, *max, *pkt_transmitted, *pkt_received,
	    *pkt_success;
	gchar stmp[128];
	gchar *program = NULL;
	gchar *count_string = NULL;
	GtkWidget *parent;
	gint ip_version;

	g_return_if_fail (netinfo != NULL);

	/* Because of the delay, we can't check twice for a hostname/IP.
	 * It was made before this function was called.  Anyway, we
	 * check at least if we have a text as hostname */
	if (netinfo_validate_domain (netinfo) == FALSE) {
		netinfo_stop_process_command (netinfo);
		return;
	}

	count = netinfo_get_count (netinfo);
	host = netinfo_get_host (netinfo);

	if (netinfo->stbar_text)
		g_free (netinfo->stbar_text);
	netinfo->stbar_text = g_strdup_printf (_("Sending ping requests to %s"), host);
	
	rttmin = rttavg = rttmax = 0.0;
	packets_transmitted = packets_received = packets_success = 0;

	/* Clear the statistics before starting a ping */

	min = GTK_LABEL (netinfo->min);
	avg = GTK_LABEL (netinfo->avg);
	max = GTK_LABEL (netinfo->max);
	gtk_label_set_text (min,
			    g_ascii_formatd (stmp, 128, "%0.2f", rttmin));
	gtk_label_set_text (avg,
			    g_ascii_formatd (stmp, 128, "%0.2f", rttavg));
	gtk_label_set_text (max,
			    g_ascii_formatd (stmp, 128, "%0.2f", rttmax));

	pkt_transmitted = GTK_LABEL (netinfo->packets_transmitted);
	pkt_received = GTK_LABEL (netinfo->packets_received);
	pkt_success = GTK_LABEL (netinfo->packets_success);
	g_sprintf (stmp, "%d", packets_transmitted);
	gtk_label_set_text (pkt_transmitted, stmp);
	g_sprintf (stmp, "%d", packets_received);
	gtk_label_set_text (pkt_received, stmp);
	g_sprintf (stmp, "%d%%", packets_success);
	gtk_label_set_text (pkt_success, stmp);

	model = gtk_tree_view_get_model (GTK_TREE_VIEW (netinfo->output));
	if (GTK_IS_LIST_STORE (model)) {
		gtk_list_store_clear (GTK_LIST_STORE (model));
	}

	draw_ping_graph (netinfo);

	parent = gtk_widget_get_toplevel (netinfo->output);

	ip_version = netinfo_get_ip_version (netinfo);
	switch (ip_version)
	{
	case IPV4:
		program = util_find_program_dialog ("ping", parent);
		break;
	case IPV6:
		program = util_find_program_dialog ("ping6", parent);
		
		break;
	case -1:
	default:
		/*invalid host or ip address*/
		return;
	}
	
	if (program != NULL) {
		/* unlimited or limited ping? */
		if (count == -1) {
			count_string = g_strdup_printf(" ");
		} else {
#if defined(__sun__) || defined(__hpux__)
			count_string = g_strdup_printf("%d", count);
#else
			count_string = g_strdup_printf(" -c %d ", count);
#endif
		}

		if (ip_version == IPV4) {
			command =
#if defined(__sun__) || defined(__hpux__)
				g_strdup_printf (PING_PROGRAM_FORMAT, program, 
						host, count_string);
#else
				g_strdup_printf (PING_PROGRAM_FORMAT, program, 
						count_string, host);
#endif
		} else {
			command =
#if defined(__sun__) || defined(__hpux__)
				g_strdup_printf (PING_PROGRAM_FORMAT_6, program, 
						host, count_string);
#else
				g_strdup_printf (PING_PROGRAM_FORMAT_6, program, 
						count_string, host);
#endif
		}
#ifdef DEBUG
		g_print("command: %s\n", command);
#endif
		g_strfreev (netinfo->command_line);
		netinfo->command_line = g_strsplit (command, " ", -1);
	
		netinfo_process_command (netinfo);
	}
	
	g_free (count_string);
	g_free (command);
	g_free (program);
}
Beispiel #4
0
void
scan_do (Netinfo * netinfo)
{
	const gchar *host = NULL;
	GtkTreeModel *model;
	
	struct sockaddr_in addr;
	struct sockaddr_in6 addr6;
	struct hostent *hp = NULL;
	struct servent *service = NULL;
	gint i, sock, start_port = 1, end_port = 65535;
	GIOChannel *channel;
	GIOChannel *channel2;
	gint pfd[2];
	gint pid;
	gchar buf[SIZE];
	gchar *service_name = NULL;
	gint ip_version, pf;
	struct sockaddr *addr_ptr;
	gint size;

	g_return_if_fail (netinfo != NULL);

	/* Because of the delay, we can't check twice for a hostname/IP.
	 * It was made before this function was called.  Anyway, we
	 * check at least if we have a text as hostname */
	if (netinfo_validate_domain (netinfo) == FALSE) {
		netinfo_stop_process_command (netinfo);
		return;
	}

	/* signal handling */
	signal (SIGCHLD, wait_for_child);

	host = netinfo_get_host (netinfo);

	if (netinfo->stbar_text)
		g_free (netinfo->stbar_text);
	netinfo->stbar_text = g_strdup_printf (_("Scanning %s for open ports"), host);

	/* Clear the current output */
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (netinfo->output));
	if (GTK_IS_LIST_STORE (model)) {
		gtk_list_store_clear (GTK_LIST_STORE (model));
	}
	
	switch (ip_version = netinfo_get_ip_version (netinfo))
	{
	case IPV4:
		pf = PF_INET;
		break;
	case IPV6:
		pf = PF_INET6;
		break;
	case -1:
	default:
#ifdef DEBUG
		g_print ("Error: Host unkown\n");
#endif /* DEBUG */
		return;
		/*g_return_if_fail (hp != NULL);*/
		break;
	}

	hp = gethostbyname2 (host, pf);

	if (pipe (pfd) == -1) {
		perror ("pipe failed");
		return;
	}

        netinfo_toggle_state (netinfo, INACTIVE, NULL);

	if ((pid = fork ()) < 0) {
		perror ("fork failed");
		return;
	}

	if (pid == 0) {
		/* child */
		close (pfd[0]);
		for (i = start_port; i <= end_port; i++) {
			if ((sock = socket (pf, SOCK_STREAM, 0)) == -1) {
#ifdef DEBUG			
				g_print ("Unable to create socket\n");
#endif /* DEBUG */
				continue;
			}

			channel = g_io_channel_unix_new (sock);

			if (ip_version == IPV4) {
				addr.sin_family = PF_INET;
				bcopy (hp->h_addr, &addr.sin_addr, hp->h_length);
				addr.sin_port = htons (i);
				addr_ptr = (struct sockaddr *) &addr;
				size = sizeof (addr);
			}
			else {
				addr6.sin6_family = PF_INET6;
				addr6.sin6_flowinfo = 0;
				bcopy (hp->h_addr, &addr6.sin6_addr, hp->h_length);
				addr6.sin6_port = htons (i);
				addr_ptr = (struct sockaddr *) &addr6;
				size = sizeof (addr6);
			}
			
			if (connect (sock, addr_ptr, size) == 0) {
				service = getservbyport (htons (i), "tcp");

				if (service != NULL) {
					service_name = g_strdup (service->s_name);
				} else {
					service_name = g_strdup (_("unknown"));
				}

				/* Translators: "open" is a network status and should be one word. */
				g_sprintf (buf, "%d %s %s\n", i, _("open"), service_name);
				g_free (service_name);
				write (pfd[1], buf, strlen (buf));
			}
			/* close (sock); */
			g_io_channel_shutdown (channel, FALSE, NULL);
		}
		close (pfd[1]);
		exit (0);
	} else {
		/* parent */
		close (pfd[1]);

		netinfo->child_pid = pid;
		netinfo->pipe_out = pfd[0];

		channel2 = g_io_channel_unix_new (pfd[0]);
		g_io_add_watch (channel2,
				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
				netinfo_io_text_buffer_dialog, netinfo);
		g_io_channel_unref (channel2);
	}
	
}