/* This file is part of Lcrzo.
*/

#ifdef LCRZODEF_SYSTEM_Unix
  /* this function is not needed*/

#elif defined LCRZODEF_SYSTEM_Windows

/*-------------------------------------------------------------*/
/* This critical section is for PacketOpenAdapter
   (PacketGetAdapterNames and pcap_open_live internally call it).
   We also use it for close functions. */
CRITICAL_SECTION lcrzo_priv_criticalsection_packetdll;

/*-------------------------------------------------------------*/
int lcrzo_priv_criticalsection_init(void)
{
  InitializeCriticalSection(&lcrzo_priv_criticalsection_packetdll);

  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_criticalsection_close(void)
{
  DeleteCriticalSection(&lcrzo_priv_criticalsection_packetdll);

  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
BOOLEAN lcrzo_priv_cs_PacketGetAdapterNames(PTSTR pStr, PULONG BufferSize)
{ BOOLEAN err;

  EnterCriticalSection(&lcrzo_priv_criticalsection_packetdll);
  err=PacketGetAdapterNames(pStr, BufferSize);
  LeaveCriticalSection(&lcrzo_priv_criticalsection_packetdll);

  return(err);
}

/*-------------------------------------------------------------*/
LPADAPTER lcrzo_priv_cs_PacketOpenAdapter(LPTSTR AdapterName)
{ LPADAPTER p;

  EnterCriticalSection(&lcrzo_priv_criticalsection_packetdll);
  p=PacketOpenAdapter(AdapterName);
  LeaveCriticalSection(&lcrzo_priv_criticalsection_packetdll);

  return(p);
}

/*-------------------------------------------------------------*/
pcap_t* lcrzo_priv_cs_pcap_open_live(char *dev, int mtu, int promisc, int toms, char *err)
{ pcap_t* p;

  EnterCriticalSection(&lcrzo_priv_criticalsection_packetdll);
  p=pcap_open_live(dev, mtu, promisc, toms, err);
  LeaveCriticalSection(&lcrzo_priv_criticalsection_packetdll);

  return(p);
}

/*-------------------------------------------------------------*/
VOID lcrzo_priv_cs_PacketCloseAdapter(LPADAPTER lpAdapter)
{ EnterCriticalSection(&lcrzo_priv_criticalsection_packetdll);
  PacketCloseAdapter(lpAdapter);
  LeaveCriticalSection(&lcrzo_priv_criticalsection_packetdll);
}

/*-------------------------------------------------------------*/
void lcrzo_priv_cs_pcap_close(pcap_t *pt)
{ EnterCriticalSection(&lcrzo_priv_criticalsection_packetdll);
  pcap_close(pt);
  LeaveCriticalSection(&lcrzo_priv_criticalsection_packetdll);
}


#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif
