예제 #1
0
파일: pcap-dag.c 프로젝트: ryo/netbsd-src
static void
dag_platform_cleanup(pcap_t *p)
{
    struct pcap_dag *pd;

    if (p != NULL) {
        pd = p->priv;
#ifdef HAVE_DAG_STREAMS_API
        if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
            fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));

        if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
            fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
#else
        if(dag_stop(p->fd) < 0)
            fprintf(stderr,"dag_stop: %s\n", strerror(errno));
#endif /* HAVE_DAG_STREAMS_API */
        if(p->fd != -1) {
            if(dag_close(p->fd) < 0)
                fprintf(stderr,"dag_close: %s\n", strerror(errno));
            p->fd = -1;
        }
        delete_pcap_dag(p);
        pcap_cleanup_live_common(p);
    }
    /* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
}
예제 #2
0
void
ReceiveErfDagCloseStream(int dagfd, int stream)
{
    dag_stop_stream(dagfd, stream);
    dag_detach_stream(dagfd, stream);
    dag_close(dagfd);
}
예제 #3
0
/* Destroys a DAG input trace */
static int dag_fin_input(libtrace_t *libtrace) {
        dag_close(FORMAT_DATA->fd);
	if (DUCK.dummy_duck)
                trace_destroy_dead(DUCK.dummy_duck);
        free(libtrace->format_data);
        return 0; /* success */
}
예제 #4
0
파일: dag.c 프로젝트: DPMI/mp
static int dagcapture_destroy_wiretap(struct dag_context* cap){
	dag_stop_stream(cap->fd, RX_STREAM);
	dag_stop_stream(cap->fd, TX_STREAM);
	dag_detach_stream(cap->fd, RX_STREAM);
	dag_detach_stream(cap->fd, TX_STREAM);
	dag_close(cap->fd);
	return 0;
}
예제 #5
0
static void endace_daq_shutdown(void *handle)
{
	EndaceDAGCtx_t *ctx = (EndaceDAGCtx_t *) handle;
	if (!ctx)
	{
		return;
	}
	dag_close(ctx->fd);
	free(ctx);
}
예제 #6
0
void pfring_dag_close(pfring *ring) {

  if(ring->priv_data == NULL) 
    return;

  pfring_dag *d = (pfring_dag *) ring->priv_data;

  dag_stop_stream(d->fd, d->stream_num);
  dag_detach_stream(d->fd, d->stream_num);
  dag_close(d->fd);

  free(d->device_name);
  free(ring->priv_data);
}
예제 #7
0
int close_device(void)
{
#if 0
    if( dag_stop_stream(dag_fd, dag_devnum) < 0 )
        dagutil_panic("dag_stop_stream %s:%u: %s\n", dagname, dag_devnum, strerror(errno));

    if(dag_detach_stream(dag_fd, dag_devnum) < 0)
        dagutil_panic("dag_detach_stream %s:%u: %s\n", dagname, dag_devnum, strerror(errno));

    if( dag_close(dag_fd) < 0 )
        dagutil_panic("dag_close %s:%u: %s\n", dagname, dag_devnum, strerror(errno));
#endif

    return 0;
}
예제 #8
0
파일: pcap-dag.c 프로젝트: ming-hai/libpcap
static void
dag_platform_cleanup(pcap_t *p)
{
	struct pcap_dag *pd = p->priv;

	if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
		fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));

	if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
		fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));

	if(p->fd != -1) {
		if(dag_close(p->fd) < 0)
			fprintf(stderr,"dag_close: %s\n", strerror(errno));
		p->fd = -1;
	}
	delete_pcap_dag(p);
	pcap_cleanup_live_common(p);
	/* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
}
예제 #9
0
파일: pcap-dag.c 프로젝트: DonCN/haiku
static void
dag_platform_close(pcap_t *p)
{
	
	if (p != NULL) {
#ifdef HAVE_DAG_STREAMS_API
		if(dag_stop_stream(p->fd, p->md.dag_stream) < 0)
			fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
		
		if(dag_detach_stream(p->fd, p->md.dag_stream) < 0)
			fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
#else
		if(dag_stop(p->fd) < 0)
			fprintf(stderr,"dag_stop: %s\n", strerror(errno));
#endif /* HAVE_DAG_STREAMS_API */
		if(dag_close(p->fd) < 0)
			fprintf(stderr,"dag_close: %s\n", strerror(errno));
#ifdef linux		
		free(p->md.device);
#endif
	}
	delete_pcap_dag(p);
	/* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
}
예제 #10
0
int pfring_dag_open(pfring *ring) {
  int i = 0;
  pfring_dag *d = NULL;
  uint32_t mindata;
  struct timeval maxwait;
  struct timeval poll;
  daginf_t* info;
  uint8_t stream_erf_types[MAX_CARD_ERF_TYPES];
  uint8_t supported = 0;

  ring->close = pfring_dag_close;
  ring->stats = pfring_dag_stats;
  ring->recv  = pfring_dag_recv;
  ring->set_poll_watermark = pfring_dag_set_poll_watermark;
  ring->set_poll_duration  = pfring_dag_set_poll_duration;
  ring->set_direction      = pfring_dag_set_direction;
  ring->enable_ring        = pfring_dag_enable_ring;

  ring->priv_data = malloc(sizeof(pfring_dag)); 

  if(ring->priv_data == NULL)
    goto ret_error; 
  
  memset(ring->priv_data, 0, sizeof(pfring_dag));
  d = ring->priv_data;

  if(ring->caplen > MAX_CAPLEN) 
    ring->caplen = MAX_CAPLEN;

  d->device_name = (char *) malloc(DAGNAME_BUFSIZE);

  if (d->device_name == NULL) {
    goto free_private;
  }

  if (dag_parse_name(ring->device_name, d->device_name, DAGNAME_BUFSIZE, &d->stream_num) < 0) {
    fprintf(stderr,"Error: device name not recognized\n");
    goto free_device_name;
  }

  if (d->stream_num % 2) {
    fprintf(stderr,"Error: odd-numbered streams are TX streams\n");
    goto free_device_name;
  }

  if((d->fd = dag_open((char *) d->device_name)) < 0) {
    fprintf(stderr, "Error opening %s\n", d->device_name);
    goto free_device_name;
  }

  if (dag_attach_stream(d->fd, d->stream_num, 0, 0) < 0) {
    fprintf(stderr, "Error attaching to stream %d: is it already attached to another application?\n", d->stream_num);
    goto dag_close;
  }

  if (dag_get_stream_poll(d->fd, d->stream_num, &mindata, &maxwait, &poll) < 0) {
    fprintf(stderr, "Error getting poll info\n");
    goto dag_detach;
  }
	
  ring->poll_duration = DEFAULT_POLL_DURATION;

  mindata = DEFAULT_MIN_PKT_QUEUED * AVG_PACKET_SIZE; //min_pkt=128, avg=512 -> min_bytes=65536

  maxwait.tv_sec  =  ring->poll_duration / 1000;
  maxwait.tv_usec = (ring->poll_duration % 1000) * 1000;

  if (dag_set_stream_poll(d->fd, d->stream_num, mindata, &maxwait, &poll) < 0) {
    fprintf(stderr, "Error setting poll info\n");
    goto dag_detach;
  }

  if(dag_start_stream(d->fd, d->stream_num) < 0) {
    fprintf(stderr, "Error starting stream\n");
    goto dag_detach;
  }

  d->bottom = NULL;
  d->top    = NULL;

  d->strip_crc = 1;

  info = dag_info(d->fd);
  if (info->device_code == 0x4200 || info->device_code == 0x4230) //these cards already strip the CRC
    d->strip_crc = 0;

  memset(stream_erf_types, 0, MAX_CARD_ERF_TYPES);

  if (dag_get_stream_erf_types(d->fd, d->stream_num, stream_erf_types, MAX_CARD_ERF_TYPES) < 0) {
    fprintf(stderr, "Error getting stream type\n");
    goto dag_stop;
  }

  while (stream_erf_types[i] && i<MAX_CARD_ERF_TYPES)
  switch(stream_erf_types[i++] & 0x7f) {
    case TYPE_ETH:
    case TYPE_COLOR_ETH:
    case TYPE_DSM_COLOR_ETH:
    case TYPE_COLOR_HASH_ETH:
      supported = 1;
      break;
    default:
      break;
  }
  
  if (!supported){
      fprintf(stderr, "Error: stream type not supported\n");
      goto dag_stop;
  }

  return 0;

dag_stop:
  dag_stop_stream(d->fd, d->stream_num);
	
dag_detach:
  dag_detach_stream(d->fd, d->stream_num);

dag_close:
  dag_close(ring->fd);

free_device_name:
  free(d->device_name);

free_private:
  free(ring->priv_data);

ret_error:
  return -1;
}
예제 #11
0
파일: dag.c 프로젝트: DPMI/mp
static int dagcapture_destroy(struct dag_context* cap){
	dag_close(cap->fd);
	return 0;
}