コード例 #1
0
ファイル: ssltrace.c プロジェクト: Correlsense/libdssl
/* the main processing function: opens pcap_t interface, creates and initializes 
the CapEnv instance, starts the data processing and handles deinitialization sequence */
int proceed( const SSTRACE_ARGS* args )
{
	pcap_t* p = NULL;
	CapEnv* env = NULL;
	int rc = 0;

	/* First, open the pcap adapter */
	p = open_adapter( args );
	if( !p ) return -1;

	/* Create and initialize the CapEnv structure */
	env = CapEnvCreate( p, 100, 0, 0, 0 );

	if( args->keyfile[0] != 0 ) {
		rc = CapEnvSetSSL_ServerInfo( env, &args->server_ip, args->port, 
			args->keyfile, args->pwd );
	}

	if (rc == 0 ) CapEnvSetSessionCallback( env, session_event_handler, NULL );

	if( rc == 0 ) 
	{
		rc = CapEnvCapture( env );
		if( rc != 0 )
		{
			sprintf( ErrBuffer, "CapEnvCapture failed. Pcap error message:%s", pcap_geterr(p) );
		}
	}

	if( env ) 
	{
		CapEnvDestroy( env );
		env = NULL;
	}

	if( p )
	{
		pcap_close( p );
		p = NULL;
	}

	return rc;
}
コード例 #2
0
ファイル: viewssld.c プロジェクト: Jonnyliu/viewssld
static int proceed(void)
{
	pcap_t* p = NULL;
	CapEnv* env = NULL;
	int rc = 0;
	struct bpf_program fp;		/* The compiled filter expression */
	char filter_exp[1024];

	p = pcap_open_live(config.cap[capindex]->src_interface, 1550, 1, 500, errbuf.common);
	if (!p)
	{
		if (config.daemon)
			syslog(LOG_CRIT, "pcap_open_live error: %s", errbuf.common);
		else
			fprintf(stderr, "ERROR: pcap_open_live error: %s\n", errbuf.common);
		return(-1);
	}

	sprintf( filter_exp, "ip host %s and tcp port %d",  inet_ntoa(config.cap[capindex]->server_ip), config.cap[capindex]->port );

	if (pcap_compile(p, &fp, filter_exp, 0, 0) == -1) 
	{
		 fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(p));
		 return(-1);
	}
	if (pcap_setfilter(p, &fp) == -1) 
	{
		 fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(p));
		 return(-1);
	 }

	// 255 is sessionTableSize
	// First 0 means use default key_timeout_interval - libdssl 2.1.1 will use 3600 here
	// Second 0 means use default tcp_timeout_interval - libdssl 2.1.1 will use 180 here
	env = CapEnvCreate(p, 255, 0, 0);

	rc = CapEnvSetSSL_ServerInfo(env, &config.cap[capindex]->server_ip, config.cap[capindex]->port, 
					config.cap[capindex]->keyfile, config.cap[capindex]->pwd);

	if (rc != 0)
	{
		if (config.daemon)
			syslog(LOG_CRIT, "CapEnvSetSSL_ServerInfo() failed, code %d: %s", \
			rc, dssl_error(rc));
		else
			fprintf(stderr,"ERROR: CapEnvSetSSL_ServerInfo() failed, code %d.\n", rc);
		return(-1);
	}

	CapEnvSetSessionCallback(env, session_event_handler, NULL);

	rc = CapEnvCapture(env);
	if (rc != 0)
	{
		if (config.daemon)
			syslog(LOG_CRIT, "CapEnvCapture() failed.");
		else
			fprintf(stderr,"CapEnvCapture() failed.\n");
		return(-1);
	}

	if (env)
	{
		CapEnvDestroy(env);
		env = NULL;
	}

	if (p)
	{
		pcap_close(p);
		p = NULL;
	}

	return(rc);
}