Exemplo n.º 1
0
int read_file(const char *file, uint32_t *no_pkts, uint8_t *data, uint32_t max)
{
    int fd, rbytes;
    pcap_hdr_t h;
    pcaprec_hdr_t rh;
    uint32_t cur = 0;
    uint32_t pkts = 0;

    fd = open(file, O_RDONLY);
    if (fd < 0) {
        fprintf(stderr, "Unable to read file: %s\n", file);
        return fd;
    }

    assert(read(fd, &h, sizeof(h)) == sizeof(h));
    while ((rbytes = read(fd, &rh, sizeof(rh)))) {
        assert(rbytes == sizeof(rh));
        //fprintf(stdout, "packet (inc-len=%u, orig-len=%u)\n",
        //        rh.incl_len, rh.orig_len);
        //lseek(fd, rh.incl_len, SEEK_CUR);
        rbytes = read_pkt(&rh, fd, data, cur, max);
        if (rbytes > 0) cur += rbytes, pkts++;
    }

    fprintf(stdout, "data in mem: %u pkts, %u bytes.\n", pkts, cur);
    if (no_pkts) *no_pkts = pkts;

    return 0;
}
Exemplo n.º 2
0
int process_input_fromport(VhostServer* vhost_server,VhostServer* send_vhost_server)
{
	int v_idx = VHOST_CLIENT_VRING_IDX_TX;
	VringTable* vring_table= &vhost_server->vring_table;
    struct vring_avail* avail = vring_table->vring[v_idx].avail;
    struct vring_used* used = vring_table->vring[v_idx].used;
    unsigned int num = vring_table->vring[v_idx].num;
    int loop;

    uint32_t count = 0;
    if (avail==0 || vhost_server->vring_table.vring[v_idx].avail==0){
    	return 0;
    }
    uint16_t a_idx = vring_table->vring[v_idx].last_avail_idx % num;

    // Loop all avail descriptors
    for (loop=0; loop<10; loop++) {
        /* we reached the end of avail */
        if (vring_table->vring[v_idx].last_avail_idx == avail->idx) {
            break;
        }

        read_pkt(send_vhost_server,vring_table, v_idx, a_idx);
        a_idx = (a_idx + 1) % num;
        vring_table->vring[v_idx].last_avail_idx++;
        vring_table->vring[v_idx].last_used_idx++;
        count++;

#ifdef DUMP_PACKETS1
            fprintf(stdout, "Recevied inside count :%d used->idx :%d \n",count,used->idx);
#endif

    }
    if (count ==0){
    	return 0;
    }
	sync_shm();  /* all memory buffers are seen before used-idx is seen */
    used->idx = vring_table->vring[v_idx].last_used_idx;
    sync_shm();  /* used->idx  need to seen by others */

#ifdef DUMP_PACKETS1
     fprintf(stdout, "vhost:%p Recevied count :%d used->idx :%d \n",(void *)vhost_server,count,used->idx);
#endif
    return count;
}
Exemplo n.º 3
0
 bool read_pkt(buf_ptr &buf)
 {
     return read_pkt(buf, buf->max_len());
 }
Exemplo n.º 4
0
int nrf24l01_term_main(int argc, char *argv[])
{
  int ret;
  bool quit = false;

  int wl_fd;

  wl_fd = wireless_open();
  if (wl_fd < 0)
    {
      return -1;
    }

  usage();

  pfds[0].fd = STDIN_FILENO;
  pfds[0].events = POLLIN;

#ifdef CONFIG_WL_NRF24L01_RXSUPPORT
  pfds[1].fd = wl_fd;
  pfds[1].events = POLLIN;
#endif

  while (!quit)
    {
      ret = poll(pfds, N_PFDS, -1);
      if (ret < 0)
        {
          perror("Error polling console / wireless");
          goto out;
        }

      if (pfds[0].revents & POLLIN)
        {
          char c;
          read(STDIN_FILENO, &c, 1);

          if (c < ' ')
            {
              /* Any non printable char -> exits */

              quit = true;
            }
          else
            {
              printf("Message to send > %c", c);
              fflush(stdout);

              /* Prepend the initial character */

              buff[0] = c;

#ifndef CONFIG_SYSTEM_READLINE
              /* Use fgets if readline utility method is not enabled */

              if (fgets(&buff[1], sizeof(buff) - 1, stdin) == NULL)
                {
                  printf("ERROR: fgets failed: %d\n", errno);
                  goto out;
                }
#else
              ret = readline(&buff[1], sizeof(buff) - 1, stdin, stdout);

              /* Readline normally returns the number of characters read,
               * but will return EOF on end of file or if an error occurs.  Either
               * will cause the session to terminate.
               */

              if (ret == EOF)
                {
                  printf("ERROR: readline failed: %d\n", ret);
                  goto out;
                }
#endif
              /* Send content */

              send_pkt(wl_fd);
            }
        }

#ifdef CONFIG_WL_NRF24L01_RXSUPPORT
      if (!quit && (pfds[1].revents & POLLIN))
        {
          read_pkt(wl_fd);
        }
#endif
    }

out:
  close(wl_fd);

  printf ("Bye !\n");
  return 0;
}