/* This file is part of Lcrzo.
*/

/*-------------------------------------------------------------*/
#if defined LCRZODEF_SYSTEM_Unix
lcrzo_priv_globalvars *lcrzo_priv_globalvars_ptr=NULL;
#elif defined LCRZODEF_SYSTEM_Windows
lcrzo_uint32 lcrzo_priv_globaltlsindex=0xFFFFFFFFu;
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

/*-------------------------------------------------------------*/
int lcrzo_priv_globalvars_init(void)
{ lcrzo_priv_globalvars *ptr;

#if defined LCRZOTEST_HOOK_GLOBALSIZE
 #if defined LCRZODEF_SYS_Linux_X_ia64
  if (sizeof(lcrzo_priv_globalvars)!=952)
 #else
  if (sizeof(lcrzo_priv_globalvars)!=648)
 #endif
  { if (LCRZODEF_LANG==1)
      puts("Size of lcrzo_priv_globalvars changed, but not the initialization function");
    else
      puts("La taille de lcrzo_priv_globalvars a change, mais pas sa fonction d'initialisation");
    printf("sizeof(lcrzo_priv_globalvars)=%lu\n", (unsigned long int)sizeof(lcrzo_priv_globalvars));
    exit(LCRZO_ERR_IEINTERNALERROR);
  }
#endif

  /* allocate memory */
#if defined LCRZODEF_SYSTEM_Unix
  lcrzo_er(lcrzo_data_alloc(sizeof(lcrzo_priv_globalvars),
			    (lcrzo_data*)&lcrzo_priv_globalvars_ptr));
  ptr=lcrzo_priv_globalvars_ptr;
#elif defined LCRZODEF_SYSTEM_Windows
  { BOOL err;
    ptr=LocalAlloc(LPTR, sizeof(lcrzo_priv_globalvars));
    if (ptr==NULL) return(LCRZO_ERR_FULOCALALLOC);
    err=TlsSetValue(lcrzo_priv_globaltlsindex, ptr);
    if (!err) return(LCRZO_ERR_FUTLSSETVALUE);
  }
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

  /* set global parameters */
  ptr->errmsglcrzo=NULL;
  ptr->errmsgsys=NULL;
  ptr->language=(LCRZODEF_LANG==1)?LCRZO_GLOBAL_LANG_EN:LCRZO_GLOBAL_LANG_FR;
  
  ptr->sock_tcpser_backlog=5;

  ptr->time_sleep_threshold1=1000;
  ptr->time_sleep_threshold2=100000;
  ptr->time_sleep_threshold3=10000000;
  
  ptr->record_open_mustbeanexistentfile=LCRZO_FALSE;
  ptr->record_open_mustbeanewfile=LCRZO_FALSE;

  ptr->hdr_compfields=LCRZO_TRUE;
  ptr->hdr_compfield_ethtype=LCRZO_TRUE;
  ptr->hdr_compfield_iptotlen=LCRZO_TRUE;
  ptr->hdr_compfield_ipihl=LCRZO_TRUE;
  ptr->hdr_compfield_ipcheck=LCRZO_TRUE;
  ptr->hdr_compfield_ipprotocol=LCRZO_TRUE;
  ptr->hdr_compfield_udplen=LCRZO_TRUE;
  ptr->hdr_compfield_udpcheck=LCRZO_TRUE;
  ptr->hdr_compfield_tcpdoff=LCRZO_TRUE;
  ptr->hdr_compfield_tcpcheck=LCRZO_TRUE;
  ptr->hdr_compfield_icmpcheck=LCRZO_TRUE;

  ptr->intspoof_eth_type=LCRZO_INTSPOOF_TYPE_CONF;
  lcrzo_er(lcrzo_etha_initdefault(ptr->intspoof_eth_address));
  ptr->intspoof_ip_type=LCRZO_INTSPOOF_TYPE_CONF;
  lcrzo_er(lcrzo_ipa_initdefault(ptr->intspoof_ip_address));

  ptr->resolver_timeout=4;

  ptr->sniff_ipreastimeout1=30;
  ptr->sniff_ipreastimeout2=5;
  ptr->sniff_tcpreortimeout1=30;
  ptr->sniff_tcpreortimeout2=5;

  ptr->spoof_fragoctosize=8192;
  ptr->spoof_printbeforesending=LCRZO_FALSE;
  ptr->spoof_printprofile=LCRZO_PRINTPROFILE_ARRAYDUMP;
#if defined LCRZODEF_SYSTEM_Unix
  ptr->spoof_useethforip=LCRZO_FALSE;
#elif defined LCRZODEF_SYSTEM_Windows
  /* because there is no way to spoof at IP level with Windows */
  ptr->spoof_useethforip=LCRZO_TRUE;
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

  ptr->sock_virt_answeralive=LCRZO_TRUE;

  ptr->data_regexp_casesensitive=LCRZO_TRUE;

  ptr->pprocess_int2uint8=&lcrzo_process_int2uint8_std;
  ptr->perr_displayfunction=NULL;

#if defined LCRZODEF_SYSTEM_Unix
#elif defined LCRZODEF_SYSTEM_Windows
  lcrzo_er(lcrzo_windows_getsystemversion(&ptr->windows_systemversion, NULL, NULL, NULL));
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

  lcrzo_er(lcrzo_priv_staticvars_init(&(ptr->staticvars)));

  lcrzo_er(lcrzo_priv_randomvars_init(&(ptr->randomvars)));
 
  lcrzo_er(lcrzo_priv_confvars_init(&(ptr->confvars)));

  return(LCRZO_ERR_OK);
}

