#include #include #include #include #include #include #include #include #include #include #include #include #include "server.h" #include #define BUFFER_SIZE 1024 // buffergroesse /* defintion der zustande */ #define Z_VERBUNDEN 1 #define Z_HELO 2 #define Z_MAIL 3 #define Z_RECEIPT 4 #define Z_DATA 5 #define Z_QUIT 6 #define Z_RSET 7 /* anzahl der zustande */ #define BEF_ANZ 7 #define SERVER "localhost" #define MAX_THREADS 2 /*anzahl maximaler Nutzer */ pthread_t threads[MAX_THREADS]; int jthreads[MAX_THREADS]; int sock; struct zustaende { int zustand; char *kommando; }; struct zustaende befehle[]={ {Z_VERBUNDEN, " "}, {Z_HELO, "HELO"}, {Z_MAIL, "MAIL"}, {Z_RECEIPT, "RCPT"}, {Z_DATA, "DATA"}, {Z_QUIT, "QUIT"}, {Z_RSET, "RSET"} }; struct speicher { char* mail_abs; char* mail_empf; char* mail_daten; }; void beenden() { } void signalhandler(int sig) { if(sig == SIGINT) { close(sock); exit(1); quit(); } } int main(int argc, char *argv[]) { sock = (int) argv[2]; if (argc != 3) /* test ob anzahl der argumente korrekt ist */ { fprintf(stderr, "Usage: %s \n", argv[0]); return -1; } struct sockaddr_in server; struct in_addr a; struct hostent * ziel = gethostbyname(argv[1]); unsigned int addr; char eing[BUFFER_SIZE]; signal(SIGINT,signalhandler); if(ziel == 0) return -1; if(ziel) { sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) perror("client: socket"); memset(&server,0,sizeof(server)); bcopy(*ziel->h_addr_list,(char*)&a,sizeof(a)); addr=inet_addr(inet_ntoa(a)); memcpy((char *)&server.sin_addr, &addr, sizeof(addr)); server.sin_family = AF_INET; server.sin_port = htons(atoi(argv[2])); if(connect(sock,(struct sockaddr*)&server,sizeof(server))<0) perror("client: connect"); switch(status){ case 0: if(daten_lesen(sock,eing,BUFFER_SIZE)<0) perror("ERROR: reading"); printf("%s",eing); gethostname(eing,sizeof(eing)); strcpy(cmd,"helo "); break; case 1: printf("Absenderadresse: "); strcpy(cmd,"mail from:"); break; case 2: printf("Empfägeradresse: "); strcpy(cmd,"rcpt to:"); break; case 3: printf("Betreff: "); strcpy(cmd,"data\015\012"); break; case 4: printf("Text: \n"); strcpy(cmd,""); break; case 5: strcpy(cmd,""); break; } // if(status!=0){ // fgets(eing,128,stdin); // } // if(status==3){ // send(sock, cmd, strlen(cmd), 0); // strcpy(subject,"Subject:"); // strncat(subject,buf,strlen(buf)-1); // strcat(subject,"\015\012"); // if(read(sock,buf2,127)<0) perror("ERROR: reading"); // send(sock, subject, strlen(subject), 0); // } // else{ // strcpy(text,cmd); // if(status==1||status==2) strcat(text,"<"); // if(status==0) strcat(text,buf); // else strncat(text,buf,strlen(buf)-1); // if(status==1||status==2) strcat(text,">"); // strcat(text,"\015\012"); // send(sock, text, strlen(text), 0); // if(status<4||strncmp(text,".\015\012",3)==0){ // bzero(buf2,128); // if(read(sock,buf2,127)<0) perror("ERROR: reading"); // printf("%s",buf2); // } // } // if(status==2&&buf2[0]=='2'){ // do{ // printf("Weitere Empfänger? (j/n) "); // fgets(buf3,128,stdin); // for(i=0;i