/* This file is part of Lcrzo.
*/

/*-------------------------------------------------------------*/
#if LCRZODEF_LIBPCAPINSTALLED==1
int lcrzo_sniff_close(lcrzo_sniff *psniff)
{ 
  /*parameters verification*/
  if (psniff==NULL) return(LCRZO_ERR_PANULLPTR);

  /*ferme les listes des packets fragmentes et TCP*/
  if ( psniff->snifftype==LCRZO_SNIFF_TYPE_IPREAS ||
       psniff->snifftype==LCRZO_SNIFF_TYPE_TCPREOR )
  { lcrzo_er(lcrzo_list_close(&(psniff->waitingippackets)));
    lcrzo_er(lcrzo_list_close(&(psniff->seenippackets)));
  }
  if ( psniff->snifftype==LCRZO_SNIFF_TYPE_TCPREOR )
  { lcrzo_er(lcrzo_list_close(&(psniff->waitingtcppackets)));
    lcrzo_er(lcrzo_list_close(&(psniff->seentcppackets)));
  }

  /* free stored data */
  if (psniff->storeddata==NULL && psniff->storeddatasize)
    return(LCRZO_ERR_PANULLPTRSIZE);
  if (psniff->storeddatasize)
  { lcrzo_er(lcrzo_data_free(psniff->storeddata));
    psniff->storeddata=NULL;
    psniff->storeddatasize=0;
  }

  /*ferme pcap*/
#if defined LCRZODEF_SYSTEM_Unix
  pcap_close(psniff->ppcapt);
#elif defined LCRZODEF_SYSTEM_Windows
  lcrzo_priv_cs_pcap_close(psniff->ppcapt);
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif
  
  psniff->pcapfd=-1;
  psniff->dataend=LCRZO_TRUE;
  return (LCRZO_ERR_OK);
}
#else
int lcrzo_sniff_close(lcrzo_sniff *psniff)
{ return (LCRZO_ERR_IEUNIMPLEMENTED);
  /* just for the compiler warning */
  psniff=psniff;
}
#endif


