#--------------------------------------------------------------------
EXE= \
emlrcvr \
+ feeder \
maild \
chkspf \
SRC= \
emlrcvr.c \
+ freeder.c \
maild.c \
chkspf.c \
emlrcvr : toremake emlrcvr.o
@ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
+feeder : toremake feeder.o
+ @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
+
maild : toremake maild.o
@ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
../lib/unipar.h \
../lib/subrou.h
+feeder.o: feeder.c \
+ ../lib/unipar.h \
+ ../lib/subrou.h
+
+
maild.o : maild.c \
../lib/uniprc.h \
../lib/unisig.h \
case 2 : //doing main task
(void) rec_handlesmtp(params->argc,params->argv);
break;
- case 3 : //doing main tash
+ case 3 : //doing main task
(void) prc_cleantitle();
params=par_freeparams(params);
(void) sig_trapsignal(false,sig_alrm);
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* SMTP protocol feeder. */
+/* Used to transmit data to remote SMTP server. */
+/* */
+/* Format is: */
+/* feeder ip port [file1 file2...] */
+/* */
+/********************************************************/
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "subrou.h"
+#include "unipar.h"
+#include "devsoc.h"
+
+#define FNAME "feeder"
+
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to display feeder usage */
+/* */
+/********************************************************/
+static void usage(const char *name)
+
+{
+(void) fprintf(stderr,"usage:\n ");
+(void) fprintf(stderr,"%s\t"
+ "[-d debug] "
+ "[-h] "
+ "remote_name port [filename1 filename2...]\n",name);
+(void) fprintf(stderr,"\twhere:\n");
+(void) fprintf(stderr,"\t\t-d level\t: debug level [1-10]\n");
+(void) fprintf(stderr,"\t\t-h\t\t: print this help message\n");
+(void) fprintf(stderr,"\t\t:remote_name, fully qualified domain name\n");
+(void) fprintf(stderr,"\t\t:port, remote acces port to access\n");
+(void) fprintf(stderr,"\t\t:filenames, a set a filename to be feed to remote\n");
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Main routine */
+/* Start a channel to a remote ip.port */
+/* read file and transmit contecnts to */
+/* remote SMTP server. */
+/* */
+/********************************************************/
+int main(int argc,char *argv[])
+
+{
+int status;
+ARGTYP *params;
+SOCPTR *socptr;
+int numfile;
+int phase;
+_Bool proceed;
+
+status=0;
+params=(ARGTYP *)0;
+socptr=(SOCPTR *)0;
+numfile=0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //checking parameters
+ if ((params=par_getparams(argc,argv,"d:fh:r:v"))==(ARGTYP *)0) {
+ proceed=false; //no need to go further
+ }
+ break;
+ case 1 : //initialising process
+ if (params->argc<2) {
+ (void) fprintf(stdout,"Error, missing! remote_name? port?\n");
+ (void) usage("feeder");
+ phase=999; //can not go further
+ }
+ break;
+ case 2 : //opening remote channel
+ socptr=soc_openonesock(pro_smtp,params->argv[0],params->argv[1]);
+ if (socptr==(SOCPTR *)0) {
+ (void) fprintf(stdout,"Unable to contact remote!\n");
+ phase=999; //can not go further
+ }
+ break;
+ case 3 : //doing main task
+ for (int i=2;i<params->argc;i++) {
+ numfile++;
+
+ (void) fprintf(stdout,"sending <%s>\n",params->argv[i]);
+ (void) sleep(3);
+ }
+ (void) fprintf(stdout,"%d file transmetted to <%s.%s>\n",
+ numfile,params->argv[0],params->argv[1]);
+ break;
+ case 4 : //closing remote channel
+ socptr=soc_closeonesock(socptr);
+ break;
+ default : //end of task
+ params=par_freeparams(params);
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+(void) exit(status);
+}
typedef struct {
PROTYP proto; //Connexion protocol type
int handle; //connexion handle
+ _Bool connected;//soc is connected to remote
_Bool modtls; //soc is in TLS mode
TLSTYP *tls; //full TPS/SSL channel
int maxcarin; //absolute number within carin
newsoc=(SOCTYP *)newsocket();
newsoc->proto=soc->proto;
+newsoc->handle=soc->handle;
+newsoc->connected=soc->connected;
newsoc->ip=strdup(soc->ip);
newsoc->port=strdup(soc->port);
newsoc->iteration=soc->iteration;
-newsoc->handle=soc->handle;
return newsoc;
}
/*
break;
case 3 : //Socket ready
soc->handle=newhandle;
+ soc->connected=true;
good=true;
break;
default : //SAFE guard
proceed=true;
while (proceed==true) {
switch (phase) {
- case 0 : //shutting down the link
+ case 0 : //is the connect still active
+ if (soc->connected==false) //no!, no need to shutdown
+ phase++;
+ break;
+ case 1 : //shutting down the link
if (shutdown(soc->handle,SHUT_RDWR)<0) {
switch (errno) {
case ENOTCONN : //already disconnect by other side!
}
}
break;
- case 1 : //closing connexion
+ case 2 : //closing connexion
if (close(soc->handle)<0) {
(void) rou_alert(0,"%s unable to close channel [%s:%s] properly "
"(errno=<%s>)",
int handle;
fd_set rset;
fd_set wset;
-int mxtime;
-struct timeval timeout;
struct addrinfo hints;
struct addrinfo *ai;
int phase;
handle=0;
FD_ZERO(&rset);
FD_ZERO(&wset);
-mxtime=10;
-timeout.tv_usec=0;;
-timeout.tv_sec=mxtime;
(void) memset(&hints,'\000',sizeof(hints));
hints.ai_family=PF_UNSPEC;
hints.ai_flags=HINTFLG;
while (proceed==true) {
switch (phase) {
case 0 : //Do we have parameters
- if ((ip!=(const char *)0)&&(port!=(const char *)0)) {
+ if ((ip==(const char *)0)||(port==(const char *)0)) {
(void) rou_alert(0,"%s, ip (%s) or port (%s) missing (config?)",
OPEP,ip,port);
phase=999; //no need to go further
}
break;
- case 2 : //is address a good one
+ case 1 : //is address a good one
if ((status=getaddrinfo(ip,port,&hints,&ai))!=0) {
(void) rou_alert(0,"%s, Unable to find a address about "
"IP:port '%s:%s' (error='%s')",
phase=999; //no need to go further
}
break;
- case 3 : //lets create socket
+ case 2 : //lets create socket
if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
(void) rou_alert(0,"%s Unable to open socket for <%s> (error='%s')",
OPEP,ai->ai_canonname,strerror(errno));
phase=999; //no need to go further
}
break;
- case 4 : //connecting to remote
+ case 3 : //connecting to remote
if (connect(handle,ai->ai_addr,ai->ai_addrlen)<0) {
switch (errno) {
case EINPROGRESS : //its acceptable
}
}
break;
- case 5 : //wait for connect completion
- switch (select(handle+1,&rset,&wset,(fd_set *)0,&timeout)) {
- case -1 :
- (void) rou_alert(1,"%s trouble to establish connection with '%s.%s' "
- "(error=<%s>)",
- OPEP,ip,port,strerror(errno));
- (void) close(handle);
- phase=999; //no ned to go further
- break;
- case 0 :
- (void) rou_alert(1,"%s Unable establish connection with '%s.%s' "
- "within %d sec, (error=<%s>)",
- OPEP,ip,port,mxtime,strerror(ETIMEDOUT));
- (void) close(handle);
- phase=999; //no ned to go further
- break;
- default : //everything fine
- break;
- }
- break;
- case 6 : //socket is now ready
+ case 4 : //socket is now ready
soc=newsocket();
soc->proto=proto;
+ soc->connected=true;
soc->handle=handle;
soc->ip=strdup(ip);
soc->port=strdup(port);
switch (errno) {
case EAGAIN : //no char available
break;
+ case ECONNRESET : //Connection reset by peer
+ soc->connected=false;
+ break;
default :
- (void) rou_alert(0,"%s Unexpected error <%s> (Bug)",strerror(errno));
+ (void) rou_alert(0,"%s Unexpected error=%d <%s> (Bug)",
+ OPEP,errno,strerror(errno));
break;
}
break;
contact->peername=soc_getaddrinfo(contact->socptr,false,true);
contact->peerip=soc_getaddrinfo(contact->socptr,false,false);
contact->logptr=log_openlog(contact->mainsesid,true);
+ (void) rou_alert(0,"Contact from peer <%s> to port <%s> started",
+ contact->peerip,contact->locserv);
break;
case 3 : //check contact validity
if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
}
break;
case 1 : //properly closing remote contact
- (void) rou_alert(0,"Contact from peer <%s> on port <%s> Terminated",
+ (void) rou_alert(0,"Contact from peer <%s> to port <%s> terminated",
contact->peerip,contact->locserv);
contact->socptr=soc_release(contact->socptr);
break;
//version definition
#define VERSION "0.6"
-#define RELEASE "7"
+#define RELEASE "8"
//Public variables
PUBLIC int debug=0; //debug level