
#include<stdio.h>
#include<netinet/in.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>

#include"sitar.h"
#include"sitar_com.h"
#include"sitar_scan.h"
#include<almemsys/almemsys.h>


extern global_data_t gd;



int malloc_set(void)
{
//int count;
int fds;
/* initialization bufer */

#ifdef MALLOC_BUG
printf("MALLOC: malloc_set():\n");
#endif

/* file_path */
if((gd.fi.cronlist_filename = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.cronlist_filename_2 = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.cronfile_filename = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.bat_filename = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.bat_filename_2 = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.bat2_filename = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.bat2_filename_2 = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.midump_filename = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.midump_filename_2 = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.bat2_filestat = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.command_path = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.cron_path = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.fi.update_com = (char *)calloc(BUF_SLEN, sizeof(char)))==NULL){ m_exit(1);}


/* buff_set */
if((gd.bf.c_info = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.bf.c_name = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}

/* my_sock */
if((gd.ip.ip_addr = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.ip.ip2_addr = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.ip.port_s = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.ip.port2_s = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}

/* dns_ip */
if((gd.di.dns_name = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((gd.di.dns_name2 = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}

/* mail_data */
if((gd.smtp.ch_MailCc = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}

/* scan */
if((gd.sd.swap = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}


if((fds = getdtablesize()) <= 0){
   fprintf(stderr,"p_open(): not get fd size.\n");
   fds = 1024;
   }

//for(count = 0; count < COM_LEN; count++){
//   pids[count] = (int *)malloc((u_int)(fds * sizeof(int)));
//   }


//#ifdef POPEN_DEBUG
//printf("p_open(): &pids=%d count=%d pids[count]=%d exec program=%s\n", &pids, count, pids[count], program);
//#endif




return 0;
}



int malloc_set_free(void)
{
// int count;
#ifdef FREE_BUG
printf("FREE: malloc_set_free():\n");
#endif

/* file_path */
free(gd.fi.cronlist_filename);
free(gd.fi.cronlist_filename_2);
free(gd.fi.cronfile_filename);
free(gd.fi.bat_filename);
free(gd.fi.bat_filename_2);
free(gd.fi.bat2_filename);
free(gd.fi.bat2_filename_2);
free(gd.fi.midump_filename);
free(gd.fi.midump_filename_2);
free(gd.fi.bat2_filestat);
free(gd.fi.command_path);
free(gd.fi.cron_path);
free(gd.fi.update_com);

/* buff_set */
free(gd.bf.c_info);
free(gd.bf.c_name);
// free(gd.bf.myfile);

/* my_sock */
free(gd.ip.ip_addr);
free(gd.ip.ip2_addr);

/* dns_ip */
free(gd.di.dns_name);

/* mail_data */
free(gd.smtp.ch_MailCc);

/* scan */
free(gd.sd.swap);

/* scan */
//free(gd.cd.swap);
//free(gd.cd.scan_all);

//for(count = 0; count < COM_LEN; count++){
//   free(pids[count]);
//   }

return 0;
}










