// malloc_set.c
// $Id: malloc_set.c,v 1.1.1.1 2007/09/19 05:49:54 sendan Exp $
// masashi shimakura

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

#include"proxy.h"

struct my_sock ip;
struct buf_data bf;
struct exec_id exid;

int malloc_set(int argc, char * argv[])
{
int count;

if((ip.in.ip_addr=(char*)calloc((strlen(argv[1])+3), sizeof(char)))==NULL){exit(1);}
if((ip.in.ch_port=(char*)calloc((strlen(argv[2])+3), sizeof(char)))==NULL){exit(1);}
if((ip.out.ip_addr=(char*)calloc((strlen(argv[3])+3), sizeof(char)))==NULL){exit(1);}
if((ip.out.ch_port=(char*)calloc((strlen(argv[4])+3), sizeof(char)))==NULL){exit(1);}
memcpy(ip.in.ip_addr, argv[1], strlen(argv[1]));
memcpy(ip.in.ch_port, argv[2], strlen(argv[2]));
memcpy(ip.out.ip_addr, argv[3], strlen(argv[3]));
memcpy(ip.out.ch_port, argv[4], strlen(argv[4]));

ip.in.port = strtol( ip.in.ch_port, (char **)NULL, 10);
ip.out.port = strtol( ip.out.ch_port, (char **)NULL, 10);
ip.max_count = strtol( argv[5], (char **)NULL, 10);
exid.uid = strtol( argv[6], (char **)NULL, 10);

if((ip.fdstat=(int*)malloc(sizeof(int)*(ip.max_count)))==NULL){exit(1);}
if((ip.in.sk=(int*)malloc(sizeof(int)*(ip.max_count)))==NULL){exit(1);}
if((ip.out.sk=(int*)malloc(sizeof(int)*(ip.max_count)))==NULL){exit(1);}
if((ip.pt=(pthread_t *)malloc(sizeof(pthread_t)*(ip.max_count)))==NULL){exit(1);}

if((bf.getdata=(char**)malloc(sizeof(char *)*(ip.max_count+1)))==NULL){exit(1);}

for(count = 0; count < ip.max_count; count++){
   ip.pt[count] = 0;
   if((bf.getdata[count] = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){exit(1);}
   }

return 0;
}




