#define FNAME "feeder"
-static char titre[100]; //test title
-static char testname[100]; //dest description
+static char titre[100]; //test title
+static char testname[100]; //dest description
+
+typedef struct {
+ char *destip; //IP to connect to
+ char *destport; //Port to connect to
+ char *srcip; //Ip to be used as source
+ SOCPTR *socptr; //connection socket
+ }FEEDTYP;
/*
\f
/* Scanning one line from test file */
/* */
/********************************************************/
-static _Bool scanline(SOCPTR *socptr,int numline,char *line)
+static _Bool scanline(FEEDTYP *fd,int numline,char *line)
{
#define OPEP "feeder.c:scanline"
case 2 : //discarding comment
switch (action) {
case 'C' : //command to execute
- status=docommand(socptr,numline,line);
+ status=docommand(fd->socptr,numline,line);
+ break;
+ case 'L' : //Restart Session
+ fd->socptr=soc_closefeedsock(fd->socptr);
+ (void) usleep(100000); //wait 10 millisec
+ fd->socptr=soc_openfeedsock(pro_smtp,fd->srcip,fd->destip,fd->destport);
+ if (fd->socptr==(SOCPTR *)0) {
+ (void) report(numline,line,"Unable to restart feed socket!");
+ status=false;
+ phase=999; //Aborting feed job
+ }
break;
case 'R' : //Receiving data
- status=doincoming(socptr,numline,line);
+ status=doincoming(fd->socptr,numline,line);
break;
case 'S' : //sending data
- (void) dooutgoing(socptr,line);
+ (void) dooutgoing(fd->socptr,line);
break;
case 'T' : //Get the test titre
status=strncpy(testname,line,sizeof(testname));
/* Scanning data file. */
/* */
/********************************************************/
-static _Bool scanonefile(SOCPTR *socptr,const char *filename)
+static _Bool scanonefile(FEEDTYP *fd,const char *filename)
{
_Bool status;
proceed=false;
}
break;
- case 1 : //reading line;
+ case 1 : //Opening the socket
+ fd->socptr=soc_openfeedsock(pro_smtp,fd->srcip,fd->destip,fd->destport);
+ if (fd->socptr==(SOCPTR *)0) {
+ (void) rou_alert(0,"Unable to open link to [%s:%s]",
+ fd->destip,fd->destport);
+ (void) fclose(fichier);
+ proceed=false; //Can not scan file
+ }
+ break;
+ case 2 : //reading line;
while (fgets(line,sizeof(line),fichier)!=(char *)0) {
char *ptr;
numline++;
while ((ptr=strrchr(line,'\n'))!=(char *)0)
*ptr='\000';
- if (scanline(socptr,numline,line)==false) {
+ if (scanline(fd,numline,line)==false) {
phase=999; //Trouble trouble exiting
break;
}
}
break;
- case 2 : //scanning went well
+ case 3 : //scanning went well
status=true;
break;
default : //SAFE Guard
+ fd->socptr=soc_closefeedsock(fd->socptr);
(void) fclose(fichier);
proceed=false;
break;
{
int numfile;
-SOCPTR *socptr;
+FEEDTYP *feed;
+
int next;
int phase;
numfile=0;
-socptr=(SOCPTR *)0;
+feed=(FEEDTYP *)calloc(1,sizeof(FEEDTYP));
+feed->srcip=strdup(srcip);
+feed->destip=strdup(argv[0]);
+feed->destport=strdup(argv[1]);
next=2;
phase=0;
while (next<argc) {
switch (phase) {
case 0 : //display scanned file
break;
- case 1 : //opening a socket
- //socptr=soc_openonesock(pro_smtp,"127.63.31.15",argv[0],argv[1]);
- socptr=soc_openonesock(pro_smtp,srcip,argv[0],argv[1]);
- if (socptr==(SOCPTR *)0) {
- (void) rou_alert(0,"Unable to contact remote!");
- phase=999;
- }
- break;
- case 2 : //scanning file
- if (scanonefile(socptr,argv[next])==false)
+ case 1 : //scanning file
+ if (scanonefile(feed,argv[next])==false)
next=argc; //do not check next file
- socptr=soc_closeonesock(socptr);
break;
case 3 : //incrementing numfile scanned
numfile++;
}
phase++;
}
+feed->destport=rou_freestr(feed->destport);
+feed->destip=rou_freestr(feed->destip);
+feed->srcip=rou_freestr(feed->srcip);
+(void) free(feed);
return numfile;
}
/*