/*en    Laurent Constantin's network library (lcrzo)
                 lcrzo_sysdep module

  Functions herein contains system dependant functions.
*/
/*fr    Bibliotheque reseau de Laurent Constantin (lcrzo)
                 Module lcrzo_sysdep

  Les fonctions presentes dans ce module contiennent les fonctions
dependantes du systeme.
*/


/*-------------------------------------------------------------*/
#define LCRZO_PRIV_WRITEMAXMSGSIZE      500
#if defined LCRZODEF_SYSTEM_Linux || defined LCRZODEF_SYSTEM_FreeBSD || defined LCRZODEF_SYSTEM_OpenBSD || defined LCRZODEF_SYSTEM_Solaris
 #define LCRZO_PRIV_READMAXMSGSIZE   0x1FFFF
#elif defined LCRZODEF_SYSTEM_Windows
 /* with a bigger value, Windows doesn't have sufficient memory */
 #define LCRZO_PRIV_READMAXMSGSIZE   0x7000
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

/*-------------------------------------------------------------*/
int lcrzo_priv_stdin(lcrzo_string *puserstring,
		     lcrzo_int32 *puserstringsize);
int lcrzo_priv_passwd(lcrzo_string *puserstring,
		      lcrzo_int32 *puserstringsize);

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Solaris
int lcrzo_priv_dlpi_putmsg(int fd, char *ptr, int len, int flags);
int lcrzo_priv_dlpi_getmsg(int fd, int size, char *bufp);
int lcrzo_priv_dlpi_open(lcrzo_constdevice device, int *pfd);
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Windows
int lcrzo_priv_winreg_uint32_get(HKEY hive,
                                 lcrzo_conststring key,
                                 lcrzo_conststring name,
                                 lcrzo_uint32 *pvalue);
int lcrzo_priv_winreg_data_get(HKEY hive,
                               lcrzo_conststring key,
                               lcrzo_conststring name,
                               lcrzo_data *pvalue,
                               lcrzo_int32 *pvaluesize);
int lcrzo_priv_winreg_datalist_get(HKEY hive,
                                   lcrzo_conststring key,
                                   lcrzo_conststring name,
                                   lcrzo_list *plist);
int lcrzo_priv_winreg_subkeylist_get(HKEY hive,
                                     lcrzo_conststring key,
                                     lcrzo_list *plist);
int lcrzo_priv_winreg_subvallist_get(HKEY hive,
                                     lcrzo_conststring key,
                                     lcrzo_list *plist);
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Windows
typedef BOOL(WINAPI * pSnmpExtensionQuery) (
        IN BYTE requestType,
        IN OUT RFC1157VarBindList * variableBindings,
        OUT AsnInteger * errorStatus,
        OUT AsnInteger * errorIndex);
typedef struct {
  HINSTANCE hinstance;
  pSnmpExtensionQuery snmpqueryfunction;
} lcrzo_priv_snmpdll;
typedef struct {
  RFC1157VarBindList varBindList;
  RFC1157VarBind varBind[5];
} lcrzo_priv_snmpdllreq;
int lcrzo_priv_AsnOid_init(OUT AsnObjectIdentifier *DstObjId, ...);
int lcrzo_priv_AsnOid_close(OUT AsnObjectIdentifier *ObjId);
int lcrzo_priv_snmpdll_init(lcrzo_priv_snmpdll *psnmpdll);
int lcrzo_priv_snmpdll_close(lcrzo_priv_snmpdll *psnmpdll);
int lcrzo_priv_snmpdllreq_init(lcrzo_priv_snmpdllreq *psnmpdllreq,
                               AsnObjectIdentifier *poid1,
                               AsnObjectIdentifier *poid2,
                               AsnObjectIdentifier *poid3,
                               AsnObjectIdentifier *poid4,
                               AsnObjectIdentifier *poid5);
int lcrzo_priv_snmpdllreq_close(lcrzo_priv_snmpdllreq *psnmpdllreq);
int lcrzo_priv_snmpdllreq_print(lcrzo_priv_snmpdllreq *psnmpdllreq);
int lcrzo_priv_snmpdllreq__uint32(lcrzo_priv_snmpdllreq *psnmpdllreq,
                                  lcrzo_uint8 index,
                                  lcrzo_uint32 *pnumber);
int lcrzo_priv_snmpdllreq__data(lcrzo_priv_snmpdllreq *psnmpdllreq,
                                lcrzo_uint8 index,
                                lcrzo_data *pdata,
                                lcrzo_int32 *pdatasize);
int lcrzo_priv_snmpdllreq__etha(lcrzo_priv_snmpdllreq *psnmpdllreq,
                                lcrzo_uint8 index,
                                lcrzo_etha etha);
int lcrzo_priv_snmpdllreq_getnext(lcrzo_priv_snmpdll *psnmpdll,
                                  lcrzo_priv_snmpdllreq *psnmpdllreq);
int lcrzo_priv_snmpdll_printall();
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Windows
typedef DWORD (WINAPI*pGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder);
typedef DWORD (WINAPI*pGetIpNetTable) (PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder);
typedef DWORD (WINAPI*pGetIpForwardTable) (PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder);
typedef DWORD (WINAPI*pGetIfEntry) (PMIB_IFROW pIfRow);
typedef DWORD (WINAPI*pSendARP) (IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen);
typedef DWORD (WINAPI*pGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder);
typedef struct {
  HINSTANCE hinstance;
  pGetIpAddrTable GetIpAddrTable;
  pGetIpNetTable GetIpNetTable;
  pGetIpForwardTable GetIpForwardTable;
  pGetIfEntry GetIfEntry;
  pSendARP SendARP;
  pGetIfTable GetIfTable;
} lcrzo_priv_iphlpapidll;
int lcrzo_priv_iphlpapidll_init(lcrzo_priv_iphlpapidll *piphlpapidll);
int lcrzo_priv_iphlpapidll_close(lcrzo_priv_iphlpapidll *piphlpapidll);
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Unix
int lcrzo_priv_fd_block_set(int fd, 
			    lcrzo_bool beblocking);
int lcrzo_priv_fd_block_get(int fd, 
			    lcrzo_bool *pbeblocking);
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Windows
int lcrzo_priv_winsock_init(void);
int lcrzo_priv_winsock_close(void);
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Windows
int lcrzo_priv_wait_winmsec_init_time(lcrzo_time *ptime, 
				      lcrzo_uint32 *pmsec);
#endif

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Windows
int lcrzo_priv_criticalsection_init(void);
int lcrzo_priv_criticalsection_close(void);
BOOLEAN lcrzo_priv_cs_PacketGetAdapterNames(PTSTR pStr, PULONG BufferSize);
LPADAPTER lcrzo_priv_cs_PacketOpenAdapter(LPTSTR AdapterName);
pcap_t* lcrzo_priv_cs_pcap_open_live(char *dev, int mtu, int promisc, int toms, char *err);
VOID lcrzo_priv_cs_PacketCloseAdapter(LPADAPTER lpAdapter);
void lcrzo_priv_cs_pcap_close(pcap_t *pt);
#endif
