Linux网络编程POP3协议

小青蛙-呱呱呱 2014-05-02 04:35:35
RT~~运行到UIDL后就是QUIT~~~~~~刚入手Linux网络编程,大家能帮我完善完善代码么~~谢谢,,QQ 402122633
/***********************************

***********************************/
#include"com_pop3.h"

int com_pop3(int fd)
{
printf("****************in to pop3 communicate***************\n");
const char *READY="+OK pop3 server ready\r\n";
const char *WELCOME="+OK core mail\r\n";
const char *MAIL="+OK 1 message(s) [100 byte(s)]\r\n";
const char *OK_UIDL="+OK\r\n";
const char *OK="+OK 1 100\r\n";
const char *NUM="1 100\r\n";
const char *NUM_UIDL="1 1biasdh\r\n";
const char *BEGIN="+OK 100\r\n";
const char *END=".\r\n";
const char *end="\r\n.\r\n";
const char *DEL="+OK deleted\r\n";
const char *QUIT="+OK pop3 server quit\r\n";
const char *LIN="\n";
const char *ERR="-ERR not support\r\n";
char pop_buf[80]={0};
char *from="From: xxu@163.com\r\n";
char *to="To: xulinfight@163.com\r\n";
char *subject="Subject: replay\r\n";
char *receive="Received: COMMAND aa\r\n";
char *message="nihaoa\r\n";
send(fd,READY,strlen(READY),0);
memset(pop_buf,0,80);
printf("S:%s\n",READY);
int count=4;
while(count>0)
{ recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(!strncmp(pop_buf,"USER",4))
{
send(fd,WELCOME,strlen(WELCOME),0);
printf("S:%s\n",WELCOME);
break;
}
else if(count==1)
return (-1);
else
count-=1;
send(fd,ERR,strlen(ERR),0);
continue;
}
//grabuser();
memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(!strncmp(pop_buf,"PASS",4))
{
send(fd,MAIL,strlen(MAIL),0);
printf("S:%s\n",MAIL);
}
else
perror("pass:\n");
//grabpass();
//compare the user and password,

memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(!strncmp(pop_buf,"STAT",4))
{
send(fd,OK,strlen(OK),0);
printf("S:%s\n",OK);
/*
send(fd,NUM_UIDL,strlen(NUM_UIDL),0);
printf("S:%s\n",NUM_UIDL);
send(fd,END,strlen(END),0);
printf("S:%s\n",END);
*/
}
else
perror("stat:\n");
memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(!strncmp(pop_buf,"LIST",4))
{
send(fd,OK_UIDL,strlen(OK_UIDL),0);
printf("S:%s\n",OK);
send(fd,NUM,strlen(NUM),0);
printf("S:%s\n",NUM);
send(fd,END,strlen(END),0);
printf("S:%s\n",END);
}
else
perror("LIST:\n");
memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(!strncmp(pop_buf,"UIDL",4))
{
send(fd,OK,strlen(OK),0);
printf("S:%s\n",OK);

send(fd,NUM_UIDL,strlen(NUM_UIDL),0);
printf("S:%s\n",NUM_UIDL);
send(fd,END,strlen(END),0);
printf("S:%s\n",END);

}
else
perror("uidl:\n");

memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
send(fd,OK,strlen(OK),0);
printf("S:%s\n",OK);

memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(!strncmp(pop_buf,"RETR",4))
{
send(fd,BEGIN,strlen(BEGIN),0);
printf("S:%s\n",BEGIN);
// send(fd,receive,strlen(receive),0);
send(fd,from,strlen(from),0);
printf("From:%s\n",from);
send(fd,to,strlen(to),0);
printf("To:%s\n",to);
send(fd,subject,strlen(subject),0);
send(fd,LIN,strlen(LIN),0);
send(fd,message,strlen(message),0);
printf("S:%s\n",message);
send(fd,end,strlen(end),0);
}
else
perror("retr error:");
memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(strncmp(pop_buf,"DELE",4)!=0)
perror("dele error:");
send(fd,DEL,strlen(DEL),0);
printf("S:%s\n",DEL);
memset(pop_buf,0,80);
recv(fd,pop_buf,80,0);
printf("C:%s\n",pop_buf);
if(strncmp(pop_buf,"QUIT",4)!=0)
perror("quit error:");
send(fd,QUIT,strlen(QUIT),0);
printf("S:%s\n",QUIT);

memset(pop_buf,0,80);
return 0;

}
...全文
73 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,127

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧