/*
		                  LCRZO
                             Network library
             Copyright(c) 1999,2000,2001,2002 Laurent Constantin
                                  -----

  Main server    : http://www.laurentconstantin.com/
  Backup servers : http://go.to/laurentconstantin/
                   http://laurentconstantin.est-la.com/
                   http://laurentconstantin.free.fr/
                   http://lauconstantin.multimania.com/
  [my current email address is on the web servers]

                                  -----
  This file is part of Lcrzo.

  Lcrzo is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  Lcrzo is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details (http://www.gnu.org).

------------------------------------------------------------------------
*/

/* -- Note about comments and variable names --
   In versions 1.00 up to 2.08, lcrzo was only written in French (my
   mother tongue). Since version 3.00, lcrzo is written in English, but
   most of comments and variable names are still in French.
   In future versions, I'll try to translate everything into English,
   but as you may guess, that's a quite big work...
   So, for the moment, here are some word translation, if you want to
   be able to understand what's going on in the functions :
     afficher - print     ;  ajouter - add         ;  copie - copy
     dernier - last       ;  donnee - data         ;  ecrire - write
     entete - header      ;  envoye - sent         ;  ferme - close
     fichier - file       ;  lire - read           ;  masque - mask 
     nboct - byte number  ;  ouvre, ouvrir - open  ;  paq, paquet - packet
     plage - range        ;  premier - first       ;  recu - received
     reseau - network     ;  retour - return       ;  taille - size
     tunnel - pipe

*/

#include "lcrzo_incl.h"


/*-------------------------------------------------------------*/
#include "sysdep/lcrzo_priv_globalvars_init.c"

/*-------------------------------------------------------------*/
#include "sysdep/lcrzo_priv_globalvars_close.c"

/*-------------------------------------------------------------*/
#include "sysdep/lcrzo_priv_globalvars_ptr_get.c"

/*-------------------------------------------------------------*/
int lcrzo_priv_globalvars_copy(lcrzo_priv_globalvars *srcptr)
{ lcrzo_priv_globalvars *dstptr;

  lcrzo_er(lcrzo_priv_globalvars_init()); 
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&dstptr));

  /* copy useful values */
  dstptr->errmsglcrzo=NULL;
  dstptr->errmsgsys=NULL;
  dstptr->language=srcptr->language;
  
  dstptr->sock_tcpser_backlog=srcptr->sock_tcpser_backlog;

  dstptr->time_sleep_threshold1=srcptr->time_sleep_threshold1;
  dstptr->time_sleep_threshold2=srcptr->time_sleep_threshold2;
  dstptr->time_sleep_threshold3=srcptr->time_sleep_threshold3;
  
  dstptr->record_open_mustbeanexistentfile=srcptr->record_open_mustbeanexistentfile;
  dstptr->record_open_mustbeanewfile=srcptr->record_open_mustbeanewfile;

  dstptr->hdr_compfields=srcptr->hdr_compfields;
  dstptr->hdr_compfield_ethtype=srcptr->hdr_compfield_ethtype;
  dstptr->hdr_compfield_iptotlen=srcptr->hdr_compfield_iptotlen;
  dstptr->hdr_compfield_ipihl=srcptr->hdr_compfield_ipihl;
  dstptr->hdr_compfield_ipcheck=srcptr->hdr_compfield_ipcheck;
  dstptr->hdr_compfield_ipprotocol=srcptr->hdr_compfield_ipprotocol;
  dstptr->hdr_compfield_udplen=srcptr->hdr_compfield_udplen;
  dstptr->hdr_compfield_udpcheck=srcptr->hdr_compfield_udpcheck;
  dstptr->hdr_compfield_tcpdoff=srcptr->hdr_compfield_tcpdoff;
  dstptr->hdr_compfield_tcpcheck=srcptr->hdr_compfield_tcpcheck;
  dstptr->hdr_compfield_icmpcheck=srcptr->hdr_compfield_icmpcheck;

  dstptr->intspoof_eth_type=srcptr->intspoof_eth_type;
  memcpy(dstptr->intspoof_eth_address, srcptr->intspoof_eth_address,
	 LCRZO_ETHA_MAXBYTES);
  dstptr->intspoof_ip_type=srcptr->intspoof_ip_type;
  memcpy(dstptr->intspoof_ip_address, srcptr->intspoof_ip_address,
	 LCRZO_IPA_MAXBYTES);

  dstptr->resolver_timeout=srcptr->resolver_timeout;

  dstptr->sniff_ipreastimeout1=srcptr->sniff_ipreastimeout1;
  dstptr->sniff_ipreastimeout2=srcptr->sniff_ipreastimeout2;
  dstptr->sniff_tcpreortimeout1=srcptr->sniff_tcpreortimeout1;
  dstptr->sniff_tcpreortimeout2=srcptr->sniff_tcpreortimeout2;

  dstptr->spoof_fragoctosize=srcptr->spoof_fragoctosize;
  dstptr->spoof_printbeforesending=srcptr->spoof_printbeforesending;
  dstptr->spoof_printprofile=srcptr->spoof_printprofile;
  dstptr->spoof_useethforip=srcptr->spoof_useethforip;

  dstptr->sock_virt_answeralive=srcptr->sock_virt_answeralive;

  dstptr->data_regexp_casesensitive=srcptr->data_regexp_casesensitive;

  dstptr->pprocess_int2uint8=srcptr->pprocess_int2uint8;
  dstptr->perr_displayfunction=srcptr->perr_displayfunction;

  dstptr->windows_systemversion=srcptr->windows_systemversion;

  /* call external copy */
  lcrzo_er(lcrzo_priv_staticvars_copy(&(srcptr->staticvars), &(dstptr->staticvars)));

  lcrzo_er(lcrzo_priv_randomvars_copy(&(srcptr->randomvars), &(dstptr->randomvars)));
  
  lcrzo_er(lcrzo_priv_confvars_copy(&(srcptr->confvars), &(dstptr->confvars)));

  return(LCRZO_ERR_OK);
}


/*-------------------------------------------------------------*/
int lcrzo_priv_staticvars_init(lcrzo_priv_staticvars *ptr)
{ 
  ptr->time_sleep_usec_numberforloop=0;
  
  ptr->sniff_reas_threshold_ipvu=0;
  ptr->sniff_reas_threshold_ipat=0;
  ptr->sniff_reas_threshold_tcp=0;
  
  ptr->intspoof_eth_randconstdone=LCRZO_FALSE;
  ptr->intspoof_eth_compconstdone=LCRZO_FALSE;
  lcrzo_er(lcrzo_etha_initdefault(ptr->intspoof_eth_savedetha));
  ptr->intspoof_ip_randconstdone=LCRZO_FALSE;
  ptr->intspoof_ip_compconstdone=LCRZO_FALSE;
  lcrzo_er(lcrzo_ipa_initdefault(ptr->intspoof_ip_savedipa));

  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_staticvars_close(lcrzo_priv_staticvars *ptr)
{ 
  ptr->time_sleep_usec_numberforloop=0;

  ptr->sniff_reas_threshold_ipvu=0;
  ptr->sniff_reas_threshold_ipat=0;
  ptr->sniff_reas_threshold_tcp=0;

  ptr->intspoof_eth_randconstdone=LCRZO_FALSE;
  ptr->intspoof_eth_compconstdone=LCRZO_FALSE;
  lcrzo_er(lcrzo_etha_initdefault(ptr->intspoof_eth_savedetha));
  ptr->intspoof_ip_randconstdone=LCRZO_FALSE;
  ptr->intspoof_ip_compconstdone=LCRZO_FALSE;
  lcrzo_er(lcrzo_ipa_initdefault(ptr->intspoof_ip_savedipa));

  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_staticvars_ptr_get(lcrzo_priv_staticvars **pptr)
{ lcrzo_priv_globalvars *ptrglo;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptrglo));
    
  if (pptr!=NULL)
  { *pptr=&(ptrglo->staticvars);
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_staticvars_copy(lcrzo_priv_staticvars *srcptr,
                               lcrzo_priv_staticvars *dstptr)
{ 
  dstptr->time_sleep_usec_numberforloop=srcptr->time_sleep_usec_numberforloop;

  dstptr->sniff_reas_threshold_ipvu=srcptr->sniff_reas_threshold_ipvu;
  dstptr->sniff_reas_threshold_ipat=srcptr->sniff_reas_threshold_ipat;
  dstptr->sniff_reas_threshold_tcp=srcptr->sniff_reas_threshold_tcp;

  dstptr->intspoof_eth_randconstdone=srcptr->intspoof_eth_randconstdone;
  dstptr->intspoof_eth_compconstdone=srcptr->intspoof_eth_compconstdone;
  memcpy(dstptr->intspoof_eth_savedetha, srcptr->intspoof_eth_savedetha, LCRZO_ETHA_MAXBYTES);
  dstptr->intspoof_ip_randconstdone=srcptr->intspoof_ip_randconstdone;
  dstptr->intspoof_ip_compconstdone=srcptr->intspoof_ip_compconstdone;
  memcpy(dstptr->intspoof_ip_savedipa, srcptr->intspoof_ip_savedipa, LCRZO_IPA_MAXBYTES);
  
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
#include "sysdep/lcrzo_priv_init_tlsalloc.c"
#include "sysdep/lcrzo_priv_close_tlsalloc.c"

/*-------------------------------------------------------------*/
int lcrzo_priv_global_set_errmsglcrzo(lcrzo_conststring string)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  if (ptr->errmsglcrzo!=NULL)
  { /* not the first time */
    lcrzo_er(lcrzo_string_free(ptr->errmsglcrzo));
  }
  lcrzo_er(lcrzo_string_initm_text(string, &(ptr->errmsglcrzo)));
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_global_get_errmsglcrzo(lcrzo_string *pstring)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  if (pstring!=NULL)
  { if (ptr->errmsglcrzo==NULL)
    { /* nothing stored */
      lcrzo_er(lcrzo_string_initm_text("", pstring));
    }
    else
    { /* nothing stored */
      lcrzo_er(lcrzo_string_initm_text(ptr->errmsglcrzo, pstring));
    }
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_global_set_errmsgsys(lcrzo_conststring string)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  if (ptr->errmsgsys!=NULL)
  { /* not the first time */
    lcrzo_er(lcrzo_string_free(ptr->errmsgsys));
  }
  lcrzo_er(lcrzo_string_initm_text(string, &(ptr->errmsgsys)));
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_global_get_errmsgsys(lcrzo_string *pstring)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  if (pstring!=NULL)
  { if (ptr->errmsgsys==NULL)
    { /* nothing stored */
      lcrzo_er(lcrzo_string_initm_text("", pstring));
    }
    else
    { /* nothing stored */
      lcrzo_er(lcrzo_string_initm_text(ptr->errmsgsys, pstring));
    }
  }
  return(LCRZO_ERR_OK);
}


/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
int lcrzo_global_set_language(lcrzo_int16 language)
{ lcrzo_priv_globalvars *ptr;

  if ( language!=LCRZO_GLOBAL_LANG_EN && language!=LCRZO_GLOBAL_LANG_FR )
    return(LCRZO_ERR_PAUNKNOWNTYPE);

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->language=language;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_sock_tcpser_backlog(lcrzo_uint8 backlog)
{ lcrzo_priv_globalvars *ptr;

  if (backlog==0) return(LCRZO_ERR_PATOOLOW);

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->sock_tcpser_backlog=backlog;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_time_sleep_1threshold(lcrzo_uint32 threshold)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->time_sleep_threshold1=threshold;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_time_sleep_2threshold(lcrzo_uint32 threshold)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->time_sleep_threshold2=threshold;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_time_sleep_3threshold(lcrzo_uint32 threshold)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->time_sleep_threshold3=threshold;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_record_open_existentfile(lcrzo_bool yesitmustbe)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yesitmustbe);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->record_open_mustbeanexistentfile=yesitmustbe;
  if (yesitmustbe)
    ptr->record_open_mustbeanewfile=0;
  else
    ptr->record_open_mustbeanewfile=1;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_record_open_newfile(lcrzo_bool yesitmustbe)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yesitmustbe);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->record_open_mustbeanewfile=yesitmustbe;
  if (yesitmustbe)
    ptr->record_open_mustbeanexistentfile=0;
  else
    ptr->record_open_mustbeanexistentfile=1;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_compfields(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfields=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_ethtype(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_ethtype=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_iptotlen(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_iptotlen=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_ipihl(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_ipihl=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_ipcheck(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_ipcheck=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_ipprotocol(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_ipprotocol=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_udplen(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_udplen=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_udpcheck(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_udpcheck=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_tcpdoff(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_tcpdoff=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_tcpcheck(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_tcpcheck=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_hdr_cf_icmpcheck(lcrzo_bool yes)
{ lcrzo_priv_globalvars *ptr;
  lcrzo_bool_verifbof(yes);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->hdr_compfield_icmpcheck=yes;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_intspoof_eth_type(lcrzo_uint8 intspoof_eth_type)
{ lcrzo_priv_globalvars *ptr;

  switch(intspoof_eth_type)
  { case LCRZO_INTSPOOF_TYPE_RAND:
    case LCRZO_INTSPOOF_TYPE_RANDCONST:
    case LCRZO_INTSPOOF_TYPE_USER:
    case LCRZO_INTSPOOF_TYPE_COMP:
    case LCRZO_INTSPOOF_TYPE_COMPCONST:
    case LCRZO_INTSPOOF_TYPE_CONF:
      break;
    default:
      return(LCRZO_ERR_PAUNKNOWNTYPE);
      break;
  }

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->intspoof_eth_type=intspoof_eth_type;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_intspoof_eth_type(lcrzo_uint8 *pintspoof_eth_type)
{ lcrzo_priv_globalvars *ptr;

  if (pintspoof_eth_type!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pintspoof_eth_type=ptr->intspoof_eth_type;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_intspoof_eth_address(const lcrzo_etha intspoof_eth_address)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  memcpy(ptr->intspoof_eth_address, intspoof_eth_address, 
	 LCRZO_ETHA_MAXBYTES);
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_intspoof_eth_address(lcrzo_etha intspoof_eth_address)
{ lcrzo_priv_globalvars *ptr;

  if (intspoof_eth_address!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    memcpy(intspoof_eth_address, ptr->intspoof_eth_address, 
	   LCRZO_ETHA_MAXBYTES);
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_intspoof_ip_type(lcrzo_uint8 intspoof_ip_type)
{ lcrzo_priv_globalvars *ptr;

  switch(intspoof_ip_type)
  { case LCRZO_INTSPOOF_TYPE_RAND:
    case LCRZO_INTSPOOF_TYPE_RANDCONST:
    case LCRZO_INTSPOOF_TYPE_USER:
    case LCRZO_INTSPOOF_TYPE_COMP:
    case LCRZO_INTSPOOF_TYPE_COMPCONST:
    case LCRZO_INTSPOOF_TYPE_CONF:
      break;
    default:
      return(LCRZO_ERR_PAUNKNOWNTYPE);
      break;
  }

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->intspoof_ip_type=intspoof_ip_type;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_intspoof_ip_type(lcrzo_uint8 *pintspoof_ip_type)
{ lcrzo_priv_globalvars *ptr;

  if (pintspoof_ip_type!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pintspoof_ip_type=ptr->intspoof_ip_type;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_intspoof_ip_address(const lcrzo_ipa intspoof_ip_address)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  memcpy(ptr->intspoof_ip_address, intspoof_ip_address, 
	 LCRZO_IPA_MAXBYTES);
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_intspoof_ip_address(lcrzo_ipa intspoof_ip_address)
{ lcrzo_priv_globalvars *ptr;

  if (intspoof_ip_address!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    memcpy(intspoof_ip_address, ptr->intspoof_ip_address, 
	   LCRZO_IPA_MAXBYTES);
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_language(lcrzo_int16 *planguage)
{ lcrzo_priv_globalvars *ptr;

  if (planguage!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *planguage=ptr->language;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_sock_tcpser_backlog(lcrzo_uint8 *pbacklog)
{ lcrzo_priv_globalvars *ptr;

  if (pbacklog!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pbacklog=ptr->sock_tcpser_backlog;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_time_sleep_1threshold(lcrzo_uint32 *pthreshold)
{ lcrzo_priv_globalvars *ptr;

  if (pthreshold!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pthreshold=ptr->time_sleep_threshold1;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_time_sleep_2threshold(lcrzo_uint32 *pthreshold)
{ lcrzo_priv_globalvars *ptr;

  if (pthreshold!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pthreshold=ptr->time_sleep_threshold2;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_time_sleep_3threshold(lcrzo_uint32 *pthreshold)
{ lcrzo_priv_globalvars *ptr;

  if (pthreshold!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pthreshold=ptr->time_sleep_threshold3;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_record_open_existentfile(lcrzo_bool *pyesitmustbe)
{ lcrzo_priv_globalvars *ptr;

  if (pyesitmustbe!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyesitmustbe=ptr->record_open_mustbeanexistentfile;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_record_open_newfile(lcrzo_bool *pyesitmustbe)
{ lcrzo_priv_globalvars *ptr;

  if (pyesitmustbe!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyesitmustbe=ptr->record_open_mustbeanewfile;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_compfields(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfields;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_ethtype(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_ethtype;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_iptotlen(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_iptotlen;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_ipihl(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_ipihl;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_ipcheck(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_ipcheck;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_ipprotocol(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_ipprotocol;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_udplen(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_udplen;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_udpcheck(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_udpcheck;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_tcpdoff(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_tcpdoff;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_tcpcheck(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_tcpcheck;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_hdr_cf_icmpcheck(lcrzo_bool *pyes)
{ lcrzo_priv_globalvars *ptr;

  if (pyes!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pyes=ptr->hdr_compfield_icmpcheck;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_resolver_timeout(lcrzo_uint8 timeout)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->resolver_timeout=timeout;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_resolver_timeout(lcrzo_uint8 *ptimeout)
{ lcrzo_priv_globalvars *ptr;

  if (ptimeout!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *ptimeout=ptr->resolver_timeout;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_sock_virt_answeralive(lcrzo_bool answeralive)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_bool_verifbof(answeralive);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->sock_virt_answeralive=answeralive;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_sock_virt_answeralive(lcrzo_bool *pansweralive)
{ lcrzo_priv_globalvars *ptr;

  if (pansweralive!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pansweralive=ptr->sock_virt_answeralive;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_data_regexp_casesensitive(lcrzo_bool casesensitive)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_bool_verifbof(casesensitive);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->data_regexp_casesensitive=casesensitive;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_data_regexp_casesensitive(lcrzo_bool *pcasesensitive)
{ lcrzo_priv_globalvars *ptr;

  if (pcasesensitive!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pcasesensitive=ptr->data_regexp_casesensitive;
  }
  return(LCRZO_ERR_OK);
}


/*************/

/*-------------------------------------------------------------*/
int lcrzo_global_set_sniff_ipreas1timeout(lcrzo_uint16 timeout)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->sniff_ipreastimeout1=timeout;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_sniff_ipreas2timeout(lcrzo_uint16 timeout)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->sniff_ipreastimeout2=timeout;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_sniff_tcpreor1timeout(lcrzo_uint16 timeout)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->sniff_tcpreortimeout1=timeout;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_sniff_tcpreor2timeout(lcrzo_uint16 timeout)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->sniff_tcpreortimeout2=timeout;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_spoof_fragoctosize(lcrzo_uint16 fragoctosize)
{ lcrzo_priv_globalvars *ptr;

  if (fragoctosize==0) return(LCRZO_ERR_PATOOLOW);
  if (fragoctosize>8192) return(LCRZO_ERR_PATOOBIG);

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->spoof_fragoctosize=fragoctosize;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_spoof_printbeforesending(lcrzo_bool printbeforesending)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_bool_verifbof(printbeforesending);
  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->spoof_printbeforesending=printbeforesending;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_set_spoof_printprofile(lcrzo_printprofile printprofile)
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->spoof_printprofile=printprofile;
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
#include "sysdep/lcrzo_global_set_spoof_useethforip.c"

/*-------------------------------------------------------------*/
int lcrzo_global_set_err_displayfunction(int (*pfunc)(int ret))
{ lcrzo_priv_globalvars *ptr;

  lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
  ptr->perr_displayfunction=pfunc;
  return(LCRZO_ERR_OK);
}


/*-------------------------------------------------------------*/
int lcrzo_global_get_sniff_ipreas1timeout(lcrzo_uint16 *ptimeout)
{ lcrzo_priv_globalvars *ptr;

  if (ptimeout!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *ptimeout=ptr->sniff_ipreastimeout1;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_sniff_ipreas2timeout(lcrzo_uint16 *ptimeout)
{ lcrzo_priv_globalvars *ptr;

  if (ptimeout!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *ptimeout=ptr->sniff_ipreastimeout2;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_sniff_tcpreor1timeout(lcrzo_uint16 *ptimeout)
{ lcrzo_priv_globalvars *ptr;

  if (ptimeout!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *ptimeout=ptr->sniff_tcpreortimeout1;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_sniff_tcpreor2timeout(lcrzo_uint16 *ptimeout)
{ lcrzo_priv_globalvars *ptr;

  if (ptimeout!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *ptimeout=ptr->sniff_tcpreortimeout2;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_spoof_fragoctosize(lcrzo_uint16 *pfragoctosize)
{ lcrzo_priv_globalvars *ptr;

  if (pfragoctosize!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pfragoctosize=ptr->spoof_fragoctosize;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_spoof_printbeforesending(lcrzo_bool *pprintbeforesending)
{ lcrzo_priv_globalvars *ptr;

  if (pprintbeforesending!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pprintbeforesending=ptr->spoof_printbeforesending;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_spoof_printprofile(lcrzo_printprofile *pprintprofile)
{ lcrzo_priv_globalvars *ptr;

  if (pprintprofile!=NULL)
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *pprintprofile=ptr->spoof_printprofile;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_spoof_useethforip(lcrzo_bool *puseethforip)
{ lcrzo_priv_globalvars *ptr;

  if (puseethforip!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *puseethforip=ptr->spoof_useethforip;
  }
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_global_get_err_displayfunction(int (**ppfunc)(int ret))
{ lcrzo_priv_globalvars *ptr;

  if (ppfunc!=NULL) 
  { lcrzo_er(lcrzo_priv_globalvars_ptr_get(&ptr));
    *ppfunc=ptr->perr_displayfunction;
  }
  return(LCRZO_ERR_OK);
}


