亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? smtpr.c

?? A simple smtp relay server. Which follows smtp protocol correctly. It receive an email. and relay it
?? C
?? 第 1 頁 / 共 2 頁
字號:
/****************************************************/ 
/* AUTHOR         :  LAW CHIU YUEN                    */
                   */
/* FILENAME     :  smtpr.c                         */
/****************************************************/ 

#ifdef WIN32
#include <windows.h>
#include <winsock.h>
#else
#define closesocket	close
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <arpa/inet.h>
#include <ctype.h>


//#define MYPORT 40711    // the port users will be connecting to
#define PORT 25
#define MAXBUFLEN 1024      // max buffer size
#define RELAY_NAME 255 // max length of file name
#define BACKLOG 10     // how many pending connections queue will hold
#define MAXDATASIZE 512 // max number of bytes we can get at once 
#define SQMAXDATASIZE 1048576 //1024 * 1024
#define RECVTIME 100    // max number of time to wait for client's message
#define MAXEMAILADDRESS 320 // 64 + 1 + 255 
#define MAXRCPT 50     //max number of mail receipients
/* State1 */
#define ACCEPT 0
#define HELO 1
#define MAILFROM 2
#define RCPTTO 3
#define DATA 4
#define MESSAGE 5
#define QUIT 6
#define RELAY 7
/* State2 */
#define FIRSTHELO 0
#define SECONDHELO 1
#define MAXHELO 1024

/*  tokenize mailto string, each time return the first email address */
/* eg.  a@a.com,b@b.com,c@c.com -->  a@a.com  */
char* tokenize(char *mailto){
     const char delimiters[] = ",";
     char *token, *cp;
     printf("b4 strtok: mailto:%s\n",mailto);     
                /* Make writable copy.  */
     token = strtok (mailto, delimiters);      /* token => "words" */
     printf("tokenize() speaking : mailto: %s\n",mailto);
     printf("tokenize() speaking : token: %s\n",token);
     return token;

}

/*  tokenize mailto string, each time return the email address other then the first one*/
/* first call:  a@a.com,b@b.com,c@c.com -->  b@b.com  */
/* second call:  a@a.com,b@b.com,c@c.com -->  c@c.com  */
char* tokenize_null(){
     const char delimiters[] = ",";
     char *token, *cp;

     token = strtok (NULL, delimiters);      /* token => "words" */
     printf("tokenize_null() speaking : token: %s\n",token);
     return token;
}

/* take in an email_address, and header; */
/*  convert to :  header: email_address  */
char* compose_mailheader(char *header,char *mail){
		char *a = malloc(strlen(mail)+30);
		char *b = NULL;
		char *c = NULL;
		strcpy(a, header);
	
		b = strcat(a, mail);
		c = strcat(b, "\r\n");
		printf("compose_mailheader:   b=%s\n", b);
		return b;
}
	
/*  1. receive message from smtp server  */
void receive(int fd, char* command, char *buf){
	int numbytes;
	
	  if ((numbytes=recv(fd, buf, MAXDATASIZE, 0)) == -1) {
        fprintf(stderr,"error in receiving\n");
        exit(1);
    }
    buf[numbytes] = '\0';
    printf("    receive() Received buf : %s",buf);
    if ( strstr(buf, command) != NULL ){
    printf("    receive() Received command : %s\n",command);
    }else{
    }
}
/*  helo  */
/*  1. called by relaymail()  */
/*  2. interact with a smtp server */
void helo(int sockfd){
		int numbytes;
		char buf2[MAXDATASIZE];
		char buf[MAXDATASIZE];
		printf("\n");
		printf("helo is called\n");
		/*receive 220*/
		receive(sockfd, "220 ", buf);

		/* send helo */
		if (send(sockfd, "HELO server\r\n", 13, 0) == -1)
				perror("HELO SERVER");
//		printf("sent HELO SERVER\n");

/* receive 250*/
		receive(sockfd, "250 ", buf);

/*      testing    */		
//		if (send(sockfd, "HELO server\r\n", 13, 0) == -1)
//				perror("HELO SERVER");
 
//		receive(sockfd, "250 ", buf);
}
	
/*  mailfrom  */
/*  1. called by relaymail()  */
/*  2. interact with a smtp server */
void mailfrom(int sockfd,char *mail_from){
		char buf[MAXDATASIZE] = "MAIL FROM:";

		char *out;
		int numbytes;
		int i;
		printf("\n");
		printf("mailfrom is called\n");

		/*  compose the "MAIL FROM:email@address.com" message  */	
		strcat(buf, mail_from);
		strcat(buf, "\r\n");
		printf("mailfrom() speaking: buf=%s\n", buf);
		printf("mailfrom() speaking: strlen(buf)=%i\n", strlen(buf));

		/* send out */
		if( send(sockfd, buf, strlen(buf), 0) == -1 )
			  perror("mailfrom()");

		/* receive 250*/
		receive(sockfd, "250 ", buf);

}  //mailfrom

/*  1. called by rcptto()  */
/*  2. interact with a smtp server */
void rcptto2(int sockfd,char *mailtos){
		char buf[MAXDATASIZE]="";
		char *a;
		char *out;
		int numbytes;
		int i,len;
		printf("\n");
		printf("rcptto2 is called\n");
		/*  compose the "RCPT TO:email@address.com" message  */	
				strcat(buf, "RCPT TO:");
				strcat(buf, tokenize_null());
				strcat(buf, "\r\n");
				printf("rcptto2() speaking: buf=%s\n", buf);
				printf("rcptto2() speaking: strlen(buf)=%i\n", strlen(buf));

				/*  send out */
				if( send(sockfd, buf, strlen(buf), 0) == -1 )
					  perror("rcptto()");

				/*  receive 250*/
				receive(sockfd, "250 ", buf);
				/*  clear the buffer  */
				for(i=0; i<strlen(buf);i++){
					buf[i]='\0';
				}//for()
				
}

/*  rcptto  */
/*  1. called by relaymail()  */
/*  2. interact with a smtp server */
void rcptto(int sockfd,char *mailtos, int mailto_num){
		char buf[MAXDATASIZE] = "RCPT TO:";
		char *a;
		char *out;
		int numbytes;
		int i,len;
		printf("\n");
		printf("rcptto is called\n");

/* sending the first address... */
				/*  compose the "RCPT TO:email@address.com" message  */	
				strcat(buf, tokenize(mailtos));
				strcat(buf, "\r\n");
				printf("rcptto() speaking: buf=%s\n", buf);
				printf("rcptto() speaking: strlen(buf)=%i\n", strlen(buf));

				/*  send out */
				if( send(sockfd, buf, strlen(buf), 0) == -1 )
					  perror("rcptto()");

				/*  receive 250*/
				receive(sockfd, "250 ", buf);
				/*  clear the buffer  */
				
				/*  handle multiple recipients case*/
				for(i=0;i<mailto_num-1;i++)
						rcptto2(sockfd, mailtos);
							
							
/* sending remaining addresses... */
}  //rcptto

/*  1. called by relaymail()  */
/*  2. interact with a smtp server */
void data(int sockfd){
		char buf[MAXDATASIZE] = "";
		printf("\n");
		printf("data() is called\n");

		/*  send "DATA"  */
		if( send(sockfd, "DATA\r\n", 6, 0) == -1 )
			  perror("data()");

		/*  receive 354  */
		receive(sockfd, "354 ", buf);
}


/*  1. called by relaymail()  */
/*  2. interact with a smtp server */
void message(int sockfd, char *msg){
		int times,i,j;
		int remainder;
		printf("\n");
		char out[1025];
		printf("message() is called\n");
		
		times = strlen(msg) / MAXDATASIZE;
		remainder = strlen(msg) - (times * MAXDATASIZE);
		
		printf("remainder: %i\n", remainder);
		printf("times: %i\n", times);
			
		for (i=0;i< times;i++){
					for (j=0;j< 1024;j++)
								out[j]= msg[1024*i + j];
					out[1024 +1] = '\0';
			
					printf("sending msg: %i\n", i);
						if( send(sockfd, out, 1025, 0) == -1 );
		}
		printf("end while: %i\n", i);
		printf("out: %s\n", out);
					for (j=0;j< remainder;j++)
								out[j]= msg[1024*times + j];
								out[remainder +1] = '\0';
		if( send(sockfd, out, remainder+1, 0) == -1 )
							perror("message");
							printf("out: %s\n", out);
}

/*  1. called by relaymail()  */
/*  2. interact with a smtp server */
void quit(int sockfd){
		char buf[MAXDATASIZE] = "";
		printf("\n");
		printf("quit() is called\n");

		/*  send "QUIT"  */
		if( send(sockfd, "QUIT\r\n", 6, 0) == -1 )
			  perror("quit()");

		/*  receive 354  */
		receive(sockfd, "250 ", buf);
}


/*relay mail to a email server*/
void relaymail(char *relay,char *mail_from, char *mailto, int mailto_num, char *msg){

    int sockfd, numbytes;  
    char buf[MAXDATASIZE];
    struct hostent *he;
    struct sockaddr_in their_addr; // connector's address information 
    int state = 1;
    int logswitch = 0; 
		int logwhile = 0;
		
		
    if ((he=gethostbyname(relay)) == NULL) {  // get the host info 
        fprintf(stderr,"gethostbyname fail\n");
        exit(1);
    }

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
        fprintf(stderr,"fail to create socket\n");
        exit(1);
    }

    their_addr.sin_family = AF_INET;    // host byte order 
    their_addr.sin_port = htons(PORT);  // short, network byte order 
    their_addr.sin_addr = *((struct in_addr *)he->h_addr);
    memset(&(their_addr.sin_zero), '\0', 8);  // zero the rest of the struct 

    if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) {
        fprintf(stderr,"connect fail\n");
        exit(1);
    }

 		while (state <7 && logwhile <10){  /*  make sure the program won't run indefinitely  */

			logwhile++;
			/*   log   */	
//      printf("\n");
//			printf("logwhile = %i\n", logwhile);
//			printf("state = %i\n", state);
//      printf("\n");
			
			switch (state){
				case HELO :
					helo(sockfd);
					state++;
					printf ("end of case HELO\n");
					break;
				case MAILFROM :
					mailfrom(sockfd, mail_from);
					state++;
					printf ("relaymail():  end of case MAILFROM\n");				
					break;
				case RCPTTO :
					rcptto(sockfd, mailto, mailto_num);
					state++;
					printf ("relaymail():  end of case RCPTTO\n");									
					break;				
				case DATA :
					data(sockfd);
					state++;
					printf ("relaymail():  end of case DATA\n");
					break;
				case MESSAGE :
					message(sockfd, msg);
					printf ("relaymail():  end of case MESSAGE\n");
					state++;
					printf ("relaymail():  end of case MESSAGE\n");
				case QUIT :
					quit(sockfd);
					state++;
					printf ("end of case QUIT\n");
					closesocket(sockfd);
					break;

				default :
					break;				
				}
		}  // while()
    closesocket(sockfd);
}


/*  remove  < >   */
char* remove_brackets(char* input)
{
  int length;
  int i, j;
  char* output;

  length = strlen(input);
  output = (char*) malloc(length + 1); 
  j = 0;

  /* copy character of input which in not equal to < or > to output */
  for (i=0; i<length; i++)
    if ((input[i]!='<') && (input[i]!='>'))
    {
      output[j] = input[i];
      j++; 
    }     
  output[j] = '\0';

  return output;
}


/* trim the space(s) before and after the string */
char* trim_space(char* input)
{
  int i, j, length, is_ch, is_end, end_pos;
  char *output;
   
  /* trim the space(s) before the string */
  length = strlen(input);
  output = (char*) malloc (length+1);
  is_ch = 0;
  is_end = 0;
  j = 0;

  for(i=0; i<length; i++)
  {
    /* copy input characters to output */
    if (is_ch==1 || !isspace(input[i]))
    {
      output[j] = input[i];
      j++;
      is_ch = 1;
    }
 }
  output[j] = '\0';

  /* trim the space(s) after the string */
  length = strlen(output);
  end_pos = length-1;
  is_end = 0;
  
  for (i=0; i<length; i++)
    if (is_end==0 && isspace(output[i]))
    {
      is_end = 1;
      end_pos = i;   
    }   
    else if (!isspace(output[i]))
      is_end = 0; 
   
  output[end_pos] = '\0';
 
  return output;
}


/* convert :    MAIL FROM: a@a.com  --->  a@a.com */
char *extractemail(const char *buf, const int i){
char * email = NULL;
char * tmp_email = NULL;
char * tmp_email2 = NULL;
char * tmp_email3 = NULL;

	/*           extract email address              */
/*  1. remove MAIL FROM:  */
				email = malloc(strlen(buf));
        strcpy(email,buf);
        email += i;
        printf("\n");
        printf("email =%s\n", email);
        printf("email length =%i\n", strlen(email));
        printf("\n");
/*  2. trim head and trailing whitespace  */
        tmp_email = trim_space(email);
        printf("trimmed email= %s\n", tmp_email);
/*  3. remove <>  */
				tmp_email2 = remove_brackets(tmp_email);
				printf("remove<> email= %s\n", tmp_email2);
/*  4. trim again */
//				tmp_email3 = trim_space("ellen@cs.com.hk");
//				printf("\n");
//				printf("extracted email= ~~~~~~%s~~~~~~\n", tmp_email3);
//				printf("\n");

//				printf("extracted email= ~~~~~~%s~~~~~~\n", tmp_email3);
				return tmp_email2;
}


/* check if email address is a valid one  */
int check_email_validity(const char *address) {
  // check if email address is valid
	// return 1 if valid
	// return 0 if invalid
	
  int number = 0;
  const char *a, *host;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩va亚洲va欧美va久久| 国产一区二区日韩精品| 欧美视频一区二区三区四区 | 久久久综合精品| 一区二区三区精品在线| 国产一区二区三区蝌蚪| 欧美日韩一二三区| 亚洲国产精品成人综合色在线婷婷| 天天色天天操综合| 一本色道久久综合精品竹菊| 亚洲精品在线免费播放| 五月婷婷综合激情| 欧美亚洲综合色| 亚洲欧美二区三区| 成人在线视频首页| 久久久天堂av| 久久精品国产一区二区| 欧美久久一二区| 一区二区三区在线观看网站| av一区二区久久| 中文字幕在线不卡| 成人毛片老司机大片| 337p日本欧洲亚洲大胆精品| 全部av―极品视觉盛宴亚洲| 欧美午夜电影网| 亚洲综合一区在线| 在线观看中文字幕不卡| 亚洲精品自拍动漫在线| 色综合久久综合网97色综合| 1区2区3区国产精品| 暴力调教一区二区三区| 国产精品国产三级国产普通话99 | 精品噜噜噜噜久久久久久久久试看| 午夜成人免费视频| 欧美精品成人一区二区三区四区| 亚洲激情六月丁香| 欧美性极品少妇| 性感美女久久精品| 国产精品美日韩| proumb性欧美在线观看| 最新不卡av在线| 在线免费观看日本一区| 亚洲成av人片一区二区三区| 欧美喷潮久久久xxxxx| 日韩国产在线一| 日韩天堂在线观看| 国产美女在线精品| 国产精品理伦片| 91极品美女在线| 日本亚洲免费观看| 久久精品视频免费观看| 国产成人精品综合在线观看| 一区免费观看视频| 欧美日韩在线播放| 激情综合网av| 亚洲视频网在线直播| 欧美亚洲尤物久久| 精品一区二区久久| 亚洲人xxxx| 日韩色视频在线观看| 国产乱码精品一区二区三区五月婷| 中国色在线观看另类| 日本韩国一区二区三区视频| 日本不卡免费在线视频| 中文一区二区在线观看| 欧美综合一区二区三区| 久久99国产精品尤物| 中文字幕亚洲不卡| 欧美一区二区三区四区在线观看| 国产麻豆精品久久一二三| 亚洲欧美日韩一区二区三区在线观看| 欧美日韩视频在线一区二区 | aaa欧美日韩| 日韩av一二三| 亚洲女人的天堂| 欧美电影免费观看高清完整版在线| 不卡电影一区二区三区| 欧美a级一区二区| 成人免费在线视频| 精品国产免费人成在线观看| 99国内精品久久| 精品一区二区三区在线观看| 亚洲免费观看高清完整版在线| 日韩欧美一区二区久久婷婷| 色综合中文字幕国产 | 日本vs亚洲vs韩国一区三区二区| 亚洲国产精品高清| 精品少妇一区二区三区在线视频 | 亚洲精品亚洲人成人网在线播放| 欧美xxxxx裸体时装秀| 久久一夜天堂av一区二区三区| 一本色道**综合亚洲精品蜜桃冫| 国产在线不卡一卡二卡三卡四卡| 亚洲国产色一区| 成人欧美一区二区三区小说| 精品免费国产一区二区三区四区| 欧美在线观看18| caoporen国产精品视频| 国产高清无密码一区二区三区| 日韩电影在线观看网站| 亚洲国产欧美在线人成| 综合激情成人伊人| 国产精品久久久久久久久久免费看| 欧美一区二区成人| 在线成人免费视频| 欧美日韩一区高清| 欧美色男人天堂| 欧美午夜影院一区| 在线欧美一区二区| 欧美综合一区二区| 欧美中文一区二区三区| 色菇凉天天综合网| 一本色道久久综合亚洲精品按摩| 福利一区福利二区| 粉嫩一区二区三区在线看| 国产毛片精品视频| 国产99精品视频| 不卡的av中国片| 不卡高清视频专区| 精品国产网站在线观看| 日韩午夜激情免费电影| 欧美电影免费观看高清完整版在线| 在线成人免费视频| 26uuu国产电影一区二区| 久久综合999| 久久天天做天天爱综合色| 久久久不卡网国产精品一区| 久久久99精品免费观看| 国产精品乱码一区二三区小蝌蚪| 中文字幕一区二区三区蜜月| 亚洲黄一区二区三区| 亚洲高清免费观看| 免费在线观看视频一区| 国产一区视频网站| 色综合欧美在线视频区| 欧美日韩高清一区二区三区| 欧美一区午夜精品| 久久久国产午夜精品| 最新日韩av在线| 日韩精品电影在线| 国产在线日韩欧美| 91在线小视频| 欧美精品一卡二卡| 久久久久久免费| 亚洲精品高清视频在线观看| 日韩av二区在线播放| 国产精品1区2区3区在线观看| 91丝袜呻吟高潮美腿白嫩在线观看| 在线观看精品一区| 欧美精品一区二区三区高清aⅴ| 中文字幕第一区二区| 婷婷国产v国产偷v亚洲高清| 国产大陆a不卡| 欧美日韩国产一级二级| 久久久国产一区二区三区四区小说| 亚洲人成影院在线观看| 青娱乐精品视频在线| 99久久99久久精品免费观看| 日韩一区二区麻豆国产| 亚洲欧美日韩在线不卡| 国产美女在线精品| 欧美裸体一区二区三区| 国产精品久久精品日日| 日韩**一区毛片| 欧美综合亚洲图片综合区| 欧美激情中文不卡| 久久国产精品99久久久久久老狼| 色综合久久天天| 国产精品少妇自拍| 久久精品99国产精品| 欧美色精品在线视频| 1024成人网| 国产成人丝袜美腿| 欧美一区二区三区小说| 亚洲激情六月丁香| 91在线播放网址| 久久精品一区二区| 精品在线观看视频| 欧美精品久久久久久久久老牛影院| 国产精品久久久久影院老司| 久久99国产精品久久99果冻传媒| 欧美日韩精品一区视频| 亚洲免费观看高清完整版在线| 国产成人午夜精品5599| 精品sm在线观看| 久久er99热精品一区二区| 欧美精品色一区二区三区| 亚洲国产裸拍裸体视频在线观看乱了 | 久久国产精品99久久久久久老狼| 在线观看一区二区视频| 亚洲人成电影网站色mp4| www.日韩精品| 国产精品美日韩| 成人性生交大片免费看视频在线 | 自拍av一区二区三区| www.欧美精品一二区| 国产精品久久99| 成人综合日日夜夜| 中文字幕成人在线观看| 不卡区在线中文字幕|