[gnet] Reading data from a socket



I'm trying to write some code with GNet that will connect to some ports
on a machine and read any data (ie. software banners) that might be
available.  

The problem I'm currently having is that I make a call to 
gnet_io_channel_readline there are times it never returns.  If there is
no data to read it doesn't just fail it seems to get stuck in an
infinite loop and I have to kill -9 the process.

I've tried using g_timeout_add to timeout the socket but that didn't
help either. 

Here is a stripped down version of my code.  Am I doing something wrong
or is this a bug?


#include <glib.h>
#include <gnet.h>

gint main (gint argc, gchar *argv[]) {

	gint ports[4];
	gint i;

	ports[0] = 22;
	ports[1] = 111;
	ports[2] = 825;
	ports[3] = 1241;

	for (i = 0; i < 4; i++) {

		GTcpSocket *socket = gnet_tcp_socket_connect ("localhost", ports[i]);
		GIOChannel *gio = gnet_tcp_socket_get_io_channel (socket);
		gchar *buf = g_malloc (255);
		gsize bytes_read;

		g_print ("before read\n");
		gnet_io_channel_readline (gio, buf, sizeof(buf), &bytes_read);
		g_print ("after read\n");			
	}

	return 0;
}


-- 
Loren Bandiera <lorenb mmgsecurity com>
MMG Security, Inc.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]