コード例 #1
0
ファイル: capd_func.c プロジェクト: lanian09/mysource
int handle_ethernet(dag_record_t *cap_rec, int dDagNum )
{
    int caplen, eth_len, rlen, port, dRet;
    struct timeval captime;
    eth_rec_t *eth_rec = &cap_rec->rec.eth;

    eth_len = ETHERNET_WLEN(cap_rec);
    caplen = ETHERNET_SLEN(cap_rec);
    rlen = ntohs(cap_rec->rlen);
    conv_ts2tv(cap_rec->ts, &captime);
    port = cap_rec->flags.iface+1; /* iface = 0, 1 */

    /* FOR STAT
    llCount++;
    llBytes += caplen;
    */
    stPortStatus[port-1].uiCurrCnt++;

    if( fidb->mirrorActsts[port-1] == DEF_STANDBY )
        return 1;

    log_print(LOGN_INFO, "DAG_NUM[%02d] RLEN[%d] ETH_LEN[%d] CAPLEN[%d] CAPTIME[%ld.%06ld] PORT[%d]",
              dDagNum, rlen, eth_len, caplen, captime.tv_sec, captime.tv_usec, cap_rec->flags.iface);

    dRet = do_action(port, caplen, eth_rec->dst, &captime);
    if( dRet < 0 ) {
        log_print( LOGN_INFO, "[%s.%d] ERROR IN do_action dRet:%d", __FUNCTION__, __LINE__, dRet );
        return -1;
    }

    return 0;
}
コード例 #2
0
ファイル: erf_live.c プロジェクト: ol-kl/netsim
int
pread_erf_live (struct timeval *ptime,
		int *plen,
		int *ptlen,
		void **pphys, int *pphystype, struct ip **ppip, void **pplast)
{
  unsigned short ether_type = 0;
  erf_record_t *curr_erf = NULL;
  unsigned int len, old, new;
  Bool erftype_ok = FALSE;
#ifdef HAVE_LONG_LONG
  unsigned long long ts;
#endif
  int dagfd = erfbuf_ptr[0].dagfd;

  /* loop until isn't find an ERF of correct type (ETH, ATM, HDLC)
   * with IP packet inside
   */
  while (!erftype_ok)
    {
      curr_erf = (erf_record_t *) dag_rx_stream_next_record (dagfd, 0);
      if (curr_erf)
	{
	  len = ntohs (curr_erf->rlen);
	  /* User processing here */
	  if (debug > 1)
	    fprintf (fp_stderr, "Got a new packet from the buffer (len = %d)\n",
		     len);
	  if (debug > 2)
	    print_erf_record (curr_erf);

#ifdef HAVE_LONG_LONG
	  ts = pletohll (&curr_erf->ts);

	  ptime->tv_sec = ts >> 32;
	  ts = ((ts & 0xffffffffULL) * 1000 * 1000);
	  ts += (ts & 0x80000000ULL) << 1;	/* rounding */
	  ptime->tv_usec = ts >> 32;
	  if (ptime->tv_usec >= 1000000)
	    {
	      ptime->tv_usec -= 1000000;
	      ptime->tv_sec += 1;
	    }
#else
	  ptime->tv_sec = pletohl (&curr_erf->ts[1]);
	  ptime->tv_usec =
	    (unsigned long) ((pletohl (&curr_erf->ts[0]) * 1000000.0) /
			     0xffffffffUL);
#endif

	  switch (curr_erf->type)
	    {
	    case ERFT_ATM:
	      erftype_ok = TRUE;
	      *ptlen = ATM_SLEN (curr_erf);
	      *plen = ATM_WLEN (curr_erf);
	      *pphys = &eth_header;
	      ether_type =
		ntohs (((unsigned short *) &curr_erf->rec.atm.pload)[3]);
	      *ppip = (struct ip *) &curr_erf->rec.atm.pload[8];	/* skip snap/llc */
	      *pplast = ((char *) *ppip) + *ptlen - 8 - 1;
	      break;
	    case ERFT_ETH:
	      erftype_ok = TRUE;
	      *ptlen = ETHERNET_SLEN (curr_erf);
	      *plen = ETHERNET_WLEN (curr_erf);
	      *pphys = &curr_erf->rec.eth.dst;
	      ether_type = ntohs (curr_erf->rec.eth.etype);
	      *ppip = (struct ip *) &curr_erf->rec.eth.pload[0];
	      *pplast =
		((char *) *ppip) + *ptlen - sizeof (struct ether_header) - 1;
	      break;
	    case ERFT_HDLC_POS:
	      erftype_ok = TRUE;
	      *ptlen = HDLC_SLEN (curr_erf);
	      *plen = HDLC_WLEN (curr_erf);
	      *pphys = &eth_header;
	      /* Detect PPP and convert the Ethertype value */
	      if (ntohs (((unsigned short *) &curr_erf->rec.pos.hdlc)[0]) ==
		  0xff03)
		{
		  if (ntohs (((unsigned short *) &curr_erf->rec.pos.hdlc)[1])
		      == 0x0021)
		    {
		      ether_type = ETHERTYPE_IP;
		    }
		}
	      else
		{
		  ether_type =
		    ntohs (((unsigned short *) &curr_erf->rec.pos.hdlc)[1]);
		}
	      *ppip = (struct ip *) &curr_erf->rec.pos.pload[0];
	      *pplast = ((char *) *ppip) + *ptlen - 4 - 1;
	      break;
	    default:
	      fprintf (fp_stderr, "Unsupported ERF type: %d\n", curr_erf->type);
	    }
	  *pphystype = PHYS_ETHER;

	  /* if it's not IP, then skip it */
	  if (ether_type != ETHERTYPE_IP && ether_type != ETHERTYPE_IPV6)
	    {
	      if (debug > 2)
		fprintf (fp_stderr, "pread_erf: not an IP packet\n");
	      erftype_ok = FALSE;
	    }


	  /* return 0 mean EOF */
	  return 1;
	}
      else
	{			/* rec == NULL */
	  if (errno != EAGAIN)
	    {
	      fprintf (fp_stderr, "dag_get_next_record: %s\n", strerror (errno));
	      exit (1);
	    }
	}
    }