Ejemplo n.º 1
0
/**
 * @brief IPv4 callback function
 */
void ipv4_callback ( pntoh_ipv4_flow_t flow , pntoh_ipv4_tuple4_t tuple , unsigned char *data , size_t len , unsigned short reason )
{
        i = 0;

        if (DEBUG)
        {
                fprintf( stderr, "\n\n[i] Got an IPv4 datagram! (%s) %s --> ", ntoh_get_reason(reason) , inet_ntoa( *(struct in_addr*) &tuple->source ) );
                fprintf( stderr, "%s | %i/%i bytes - Key: %04x - ID: %02x - Proto: %d (%s)\n\n", inet_ntoa( *(struct in_addr*) &tuple->destination ), (int)len, (int)(flow->total) , flow->key, ntohs( tuple->id ), tuple->protocol, get_proto_description( tuple->protocol ) );
        }

        if ( tuple->protocol == IPPROTO_TCP )
        {
                send_tcp_segment ( (struct ip*) data , &tcp_callback );
        }
        else
        {
                if (DEBUG)
                {
                        for ( i = 0; i < flow->total ; i++ )
                        {
                                fprintf( stderr, "%02x ", data[i] );
                        }
                }
        }

        if (DEBUG)
        {
                write(2, "\n", 1);
        }

        return;
}
Ejemplo n.º 2
0
/* IPv4 Callback */
void ipv4_callback ( pntoh_ipv4_flow_t flow , pntoh_ipv4_tuple4_t tuple , unsigned char *data , size_t len , unsigned short reason )
{
	unsigned int i = 0;

	fprintf( stderr, "\n\n[i] Got an IPv4 datagram! (%s) %s --> ", ntoh_get_reason(reason) , inet_ntoa( *(struct in_addr*) &tuple->source ) );
	fprintf( stderr, "%s | %zu/%zu bytes - Key: %04x - ID: %02x - Proto: %d (%s)\n\n", inet_ntoa( *(struct in_addr*) &tuple->destination ), len, flow->total , flow->key, ntohs( tuple->id ), tuple->protocol, get_proto_description( tuple->protocol ) );

	if ( tuple->protocol == IPPROTO_TCP )
		send_tcp_segment ( (struct ip*) data , &tcp_callback );
	else
		for ( i = 0; i < flow->total ; i++ )
			fprintf( stderr, "%02x ", data[i] );

	fprintf( stderr, "\n" );

	return;
}
Ejemplo n.º 3
0
/* IPv6 Callback */
void ipv6_callback ( pntoh_ipv6_flow_t flow , pntoh_ipv6_tuple4_t tuple , unsigned char *data , size_t len , unsigned short reason )
{
	unsigned int	i = 0;
	char		src[INET6_ADDRSTRLEN] = {0};
	char		dst[INET6_ADDRSTRLEN] = {0};

	inet_ntop ( AF_INET6 , (void*) &tuple->source , src , INET6_ADDRSTRLEN );
	inet_ntop ( AF_INET6 , (void*) &tuple->destination , src , INET6_ADDRSTRLEN );

	fprintf( stderr, "\n\n[i] Got an IPv6 datagram! (%s - %d) %s --> ", ntoh_get_reason(reason) , reason , src );
	fprintf( stderr, "%s | %zu/%zu bytes - Key: %04x - ID: %02x - Proto: %d (%s)\n\n", dst , len, flow->total , flow->key, ntohs( tuple->id ), tuple->protocol, get_proto_description( tuple->protocol ) );

	for ( i = 0; i < flow->total ; i++ )
		fprintf( stderr, "%02x ", data[i] );

	fprintf( stderr, "\n" );

	return;
}
Ejemplo n.º 4
0
/* TCP Callback */
void tcp_callback ( pntoh_tcp_stream_t stream , pntoh_tcp_peer_t orig , pntoh_tcp_peer_t dest , pntoh_tcp_segment_t seg , int reason , int extra )
{
	/* receive data only from the peer given by the user */
	if ( receive == RECV_CLIENT && stream->server.receive )
	{
		stream->server.receive = 0;
		return;
	}else if ( receive == RECV_SERVER && stream->client.receive )
	{
		stream->client.receive = 0;
		return;
	}

	fprintf ( stderr , "\n[%s] %s:%d (%s | Window: %lu) ---> " , ntoh_tcp_get_status ( stream->status ) , inet_ntoa( *(struct in_addr*) &orig->addr ) , ntohs(orig->port) , ntoh_tcp_get_status ( orig->status ) , orig->totalwin );
	fprintf ( stderr , "%s:%d (%s | Window: %lu)\n\t" , inet_ntoa( *(struct in_addr*) &dest->addr ) , ntohs(dest->port) , ntoh_tcp_get_status ( dest->status ) , dest->totalwin );

	if ( seg != 0 )
		fprintf ( stderr , "SEQ: %lu ACK: %lu Next SEQ: %lu" , seg->seq , seg->ack , orig->next_seq );

	switch ( reason )
	{
		/* Data segment */
		case NTOH_REASON_DATA:
			fprintf ( stderr , " | Data segment | Bytes: %i" , seg->payload_len );

			/* write data */
			write_data( (ppeer_info_t) seg->user_data );

			if ( extra != 0 )
					fprintf ( stderr , " - %s" , ntoh_get_reason ( extra ) );

			break;

		default:
			switch ( extra )
			{
			    case NTOH_REASON_MAX_SYN_RETRIES_REACHED:
			    case NTOH_REASON_MAX_SYNACK_RETRIES_REACHED:
			    case NTOH_REASON_HSFAILED:
			    case NTOH_REASON_EXIT:
			    case NTOH_REASON_TIMEDOUT:
			    case NTOH_REASON_CLOSED:
				if ( extra == NTOH_REASON_CLOSED )
				    fprintf ( stderr , "\n\t+ Connection closed by %s (%s)" , stream->closedby == NTOH_CLOSEDBY_CLIENT ? "Client" : "Server" , inet_ntoa( *(struct in_addr*) &(stream->client.addr) ) );
				else
				    fprintf ( stderr , "\n\t+ %s/%s - %s" , ntoh_get_reason ( reason ) , ntoh_get_reason ( extra ) , ntoh_tcp_get_status ( stream->status ) );

				break;

			    default:
				break;
			}
			break;
	}

	if ( seg != 0 )
		free_peer_info ( (ppeer_info_t) seg->user_data );

	fprintf ( stderr , "\n" );

	return;
}