/* 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; }
/* 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; }
/** * @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; }