Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    unsigned int start = 0;
    unsigned int total_iter = 0;

    if (argc != 3)
        usage(argv[0]);

    if (argv[1])
        start = (unsigned int)atoi(argv[1]);
    else
        usage(argv[0]);

    if (argv[2])
        total_iter = (unsigned int)atoi(argv[2]);
    else
        usage(argv[0]);


    // Current sequence.
    unsigned int *seq = NULL;
    unsigned int seq_size = count_digits(start);

    seq = malloc(seq_size * sizeof(unsigned int));

    // Convert the starting number in a number sequence
    int d = 0;
    for(d = seq_size - 1; d >= 0;d--)
    {
        seq[d] = start % 10;
        start /= 10;
    }

    // New sequence.
    unsigned int *new_seq = NULL;
    unsigned int new_seq_size = 0;

    unsigned int i = 0;
    for (i = 0;i<total_iter;i++)
    {

        update_seq(seq, seq_size, &new_seq, &new_seq_size);

        if (i == total_iter - 1)
            print_seq(new_seq, new_seq_size);

        seq_size = new_seq_size;
        new_seq_size = 0;

        swap_ptr(&seq, &new_seq);

        if (new_seq)
            free(new_seq);
    }

    if (seq)
        free(seq);

    return 0;
}
Exemplo n.º 2
0
void init_seq(sequencer_t *seq)
{
    for(int i=0; i<8; ++i)
        seq->freq[i] = 80*i;
    seq->noise_decay = 0.0;
    seq->noise_level = 0.0;
    seq->noise_state = 0.0;
    seq->bpm = 120.0;
    seq->t = 0.0;
    update_seq(seq);
}
Exemplo n.º 3
0
BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
                              int first, int last, int fixed, int id)
{
    if (first < 0  ||  last < 0  ||  last < first)
        return nullptr;

    /* Empty tree -> build one */
    if (t == nullptr)
    {
        if ((t=bddtree_new(id)) == nullptr)
            return nullptr;
        t->first = first;
        t->fixed = fixed;
        t->seq = NEW(int,last-first+1);
        t->last = last;
        update_seq(t);
        t->prev = prev;
        return t;
    }

    /* Check for identity */
    if (first == t->first  &&  last == t->last)
        return t;

    /* Before this section -> insert */
    if (last < t->first)
    {
        BddTree *tnew = bddtree_new(id);
        if (tnew == nullptr)
            return nullptr;
        tnew->first = first;
        tnew->last = last;
        tnew->fixed = fixed;
        tnew->seq = NEW(int,last-first+1);
        update_seq(tnew);
        tnew->next = t;
        tnew->prev = t->prev;
        t->prev = tnew;
        return tnew;
    }
Exemplo n.º 4
0
void gen_seq(float *out_f, float *out_amp, sequencer_t *seq, unsigned nframes)
{
    update_seq(seq);
    const float dt = seq->bpm/(Fs*60);
    int ti = seq->t;

    for(unsigned i=0; i<nframes; ++i) {
        int nti = seq->t;
        seq->t += dt;
        if(seq->t >= 8)
            seq->t -= 8;
        if(nti != ti)
            seq->noise_state = 0.2;
        out_f[i]   = seq->norm_freq[nti];
        out_amp[i] = seq->noise_level*seq->noise_state;
        seq->noise_state *= seq->noise_decay_internal;
    }
}
Exemplo n.º 5
0
Arquivo: rtp.c Projeto: unusedPhD/ndpi
static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
			    struct ndpi_flow_struct *flow,
			    const u_int8_t * payload, const u_int16_t payload_len)
{
  struct ndpi_packet_struct *packet = &flow->packet;
	
  u_int8_t stage;
  u_int16_t seqnum = ntohs(get_u_int16_t(payload, 2));

  NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "search rtp.\n");

  if (payload_len == 4 && get_u_int32_t(packet->payload, 0) == 0 && flow->packet_counter < 8) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "need next packet, maybe ClearSea out calls.\n");
    return;
  }

  if (payload_len == 5 && memcmp(payload, "hello", 5) == 0) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG,
	     "need next packet, initial hello packet of SIP out calls.\n");
    return;
  }

  if (payload_len == 1 && payload[0] == 0) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG,
	     "need next packet, payload_packet_len == 1 && payload[0] == 0.\n");
    return;
  }

  if (payload_len == 3 && memcmp(payload, "png", 3) == 0) {
    /* weird packet found in Ninja GlobalIP trace */
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "skipping packet with len = 3 and png payload.\n");
    return;
  }

  if (payload_len < 12) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "minimal packet size for rtp packets: 12.\n");
    goto exclude_rtp;
  }

  if (payload_len == 12 && get_u_int32_t(payload, 0) == 0 && get_u_int32_t(payload, 4) == 0 && get_u_int32_t(payload, 8) == 0) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "skipping packet with len = 12 and only 0-bytes.\n");
    return;
  }

  if ((payload[0] & 0xc0) == 0xc0 || (payload[0] & 0xc0) == 0x40 || (payload[0] & 0xc0) == 0x00) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "version = 3 || 1 || 0, maybe first rtp packet.\n");
    return;
  }

  if ((payload[0] & 0xc0) != 0x80) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct,
	     NDPI_LOG_DEBUG, "rtp version must be 2, first two bits of a packets must be 10.\n");
    goto exclude_rtp;
  }

  /* rtp_payload_type are the last seven bits of the second byte */
  if (flow->rtp_payload_type[packet->packet_direction] != (payload[1] & 0x7F)) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "payload_type has changed, reset stages.\n");
    packet->packet_direction == 0 ? (flow->rtp_stage1 = 0) : (flow->rtp_stage2 = 0);
  }
  /* first bit of first byte is not part of payload_type */
  flow->rtp_payload_type[packet->packet_direction] = payload[1] & 0x7F;

  stage = (packet->packet_direction == 0 ? flow->rtp_stage1 : flow->rtp_stage2);

  if (stage > 0) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct,
	     NDPI_LOG_DEBUG, "stage = %u.\n", packet->packet_direction == 0 ? flow->rtp_stage1 : flow->rtp_stage2);
    if (flow->rtp_ssid[packet->packet_direction] != get_u_int32_t(payload, 8)) {
      NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "ssid has changed, goto exclude rtp.\n");
      goto exclude_rtp;
    }

    if (seqnum == flow->rtp_seqnum[packet->packet_direction]) {
      NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "maybe \"retransmission\", need next packet.\n");
      return;
    } else if ((u_int16_t) (seqnum - flow->rtp_seqnum[packet->packet_direction]) < RTP_MAX_OUT_OF_ORDER) {
      NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG,
	       "new packet has larger sequence number (within valid range)\n");
      update_seq(ndpi_struct, flow, packet->packet_direction, seqnum);
    } else if ((u_int16_t) (flow->rtp_seqnum[packet->packet_direction] - seqnum) < RTP_MAX_OUT_OF_ORDER) {
      NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG,
	       "new packet has smaller sequence number (within valid range)\n");
      init_seq(ndpi_struct, flow, packet->packet_direction, seqnum, 1);
    } else {
      NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG,
	       "sequence number diff is too big, goto exclude rtp.\n");
      goto exclude_rtp;
    }
  } else {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct,
	     NDPI_LOG_DEBUG, "rtp_ssid[%u] = %u.\n", packet->packet_direction,
	     flow->rtp_ssid[packet->packet_direction]);
    flow->rtp_ssid[packet->packet_direction] = get_u_int32_t(payload, 8);
    if (flow->packet_counter < 3) {
      NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "packet_counter < 3, need next packet.\n");
    }
    init_seq(ndpi_struct, flow, packet->packet_direction, seqnum, 1);
  }
  if (seqnum <= 3) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct,
	     NDPI_LOG_DEBUG, "sequence_number = %u, too small, need next packet, return.\n", seqnum);
    return;
  }

  if (stage == 3) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "add connection I.\n");
    ndpi_int_rtp_add_connection(ndpi_struct, flow);
  } else {
    packet->packet_direction == 0 ? flow->rtp_stage1++ : flow->rtp_stage2++;
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "stage[%u]++; need next packet.\n",
	     packet->packet_direction);
  }
  return;

 exclude_rtp:
#ifdef NDPI_PROTOCOL_STUN
  if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_STUN
      || packet->real_protocol_read_only == NDPI_PROTOCOL_STUN) {
    NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "STUN: is detected, need next packet.\n");
    return;
  }
#endif							/*  NDPI_PROTOCOL_STUN */
  NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "exclude rtp.\n");
  NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RTP);
}