⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnstream.cpp

📁 linux 上http email 协议分析程序 主要能够处理大数据量的主干网的应用
💻 CPP
字号:
#include <stdio.h>#include <string.h>#include <ctype.h>#include <assert.h>#include <unistd.h>#include <netinet/in.h>#include <arpa/inet.h>#include <iostream>#include <fstream>using namespace std;#include "Ini.h"#include "BaseConst.h"#include "Cnstream.h"//Cmimestream::Cmimestream(){	m_curpos=NULL;	m_endpos=NULL;}Cmimestream::~Cmimestream(){	}void Cmimestream::init(int ilen,char *szdata){	m_curpos=szdata;	m_endpos=szdata+ilen;	//char *m_endpos;}/*return : len of line==	-1:结束,错误==	0:空行	0:内容长度*/int Cmimestream::getLine(char *buf){	int ilen=0;	while(m_curpos<m_endpos)	{		if(*m_curpos==C_CR )		{			if(*(m_curpos+1)==C_LF)			{				m_curpos+=2;				if(*(m_curpos)==C_SPACE ||*(m_curpos)==C_HTAB)				{//					*buf++=*m_curpos++;					ilen++;										continue;				}				else				{//					*buf=0;					return ilen;				}			}		}		*buf++=*m_curpos++;		ilen++;		if(ilen>=1000)				return -1;	}	return -1;}/*return : len of line==	-1:结束,错误==	0:空行	0:内容长度*/int Cmimestream::getLine(char *buf,int lenbuf){	int ilen=0;	if(m_curpos>=m_endpos)		return -1;	while(m_curpos<m_endpos)	{		if(*m_curpos==C_CR )		{			if(*(m_curpos+1)==C_LF)			{				m_curpos+=2;				if(*(m_curpos)==C_SPACE ||*(m_curpos)==C_HTAB)				{//					if(ilen<lenbuf)					{						*buf++=*m_curpos++;						ilen++;					}					else					{						m_curpos++;					}				}				else				{//					*buf=0;					return ilen;				}			}		}		if(ilen<lenbuf)		{			*buf++=*m_curpos++;			ilen++;		}		else		{			m_curpos++;		}	}	return ilen;	//fix-2005-05-20 return -1;}/*return : len of line==	-1:结束,错误==	0:空行	0:内容长度*/int Cmimestream::tmdgetLine(char *buf){	int ilen=0;	while(m_curpos<m_endpos)	{		if(*m_curpos==C_CR )		{			if(*(m_curpos+1)==C_LF)			{				m_curpos+=2;								*buf=0;				return ilen;							}		}		*buf++=*m_curpos++;		ilen++;		if(ilen>=1000)				return -1;	}	return -1;}/*return : len of line==	-1:结束,错误==	0:空行	0:内容长度*/int Cmimestream::tmdgetLine(char *buf,int lenbuf){	int ilen=0;	while(m_curpos<m_endpos)	{		if(*m_curpos==C_CR )		{			if(*(m_curpos+1)==C_LF)			{				m_curpos+=2;								*buf=0;				return ilen;							}		}		if(ilen<lenbuf)		{			*buf++=*m_curpos++;			ilen++;		}		else		{			m_curpos++;		}	}	return -1;}char *Cmimestream::gotoMarker(char *marker){	#ifdef DEBUG		//printf("marker [%s],[%s]\n",marker,m_curpos);	#endif	char *p=m_curpos;	int len=strlen(marker);	while(p+len<=m_endpos)	{				if(memcmp(p,marker,len)==0)		{			m_curpos=p;			return p;		}		p++;	}	return		NULL;}void Cmimestream::gotoNextLine(){	while(m_curpos<m_endpos)	{		if(*m_curpos==C_CR )		{			m_curpos++;			if(*(m_curpos)==C_LF)			{				m_curpos++;				return;			}		}		else			m_curpos++;	}	return;}void Cmimestream::gotoEndPos(){	m_curpos=m_endpos;}bool Cmimestream::endofStream(){	if(m_curpos>=m_endpos)		return true;	return false;}void  Cmimestream::goaHead(int len){	m_curpos+=len;}char *Cmimestream::getCurPos(){	return m_curpos;}char *Cmimestream::getEndPos(){	return m_endpos;}char *Cmimestream::getEndEmailBodyPos(){	char *p=m_curpos;	while(p<=m_endpos-2)	{		if(*p=='.')		{			if(*(p+1)==C_CR )			{						if(*(p+2)==C_LF)				{					if(*(p-1)==C_LF && *(p-2)==C_CR)					{						m_curpos=p;						return p;					}				}			}		}		p++;	}	return NULL;}/*void Cmimestream::saveFile(struct ST_TCP_STREAM *phead){	struct in_addr inaddr;	char filename[128];	inaddr.s_addr = phead->src_ip;	sprintf(filename,"log/%s::%d--",inet_ntoa(inaddr),ntohs(phead->src_port));		//printf("filename=%s\n",filename);	inaddr.s_addr = phead->dst_ip;	sprintf(filename+strlen(filename),"%s::%d--",inet_ntoa(inaddr),ntohs(phead->dst_port));	//printf("filename=%s\n",filename);	strcat(filename,".");	strcat(filename,TUTime::YYYYMMDDHHMMSS());	//printf("filename=%s\n",filename);	//printf("save stream [%s]\n",filename);	strcpy(filename,"log/tmp.s");	ofstream *pofslog= new ofstream(filename,ios::trunc);	char *p=m_curpos;		while(p<m_endpos)	{		*pofslog<<*p;		p++;	}	//printf("flush\n");	pofslog->flush();	//printf("close\n");	pofslog->close();	}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -