我想用c写一个邮件客户端。我使用openssl,但是我有一个问题,当我使用像"USER示例"这样的命令与telnet一起工作时,我总是得到一个"未知命令"。
所需代码为:
int login(BIO *bio) {
unsigned char buf_print[4096]; //Used for WebPrintLine to
unsigned char user_log[] = {"USER men"};
if( WebSendLine(bio, user_log, strlen(user_log)) != 0) {
printf("Couldn't login.n");
return -1;
}
WebPrintReturnLine(bio, buf_print, sizeof(buf_print));//Print the line to the display
}
:
//Send one line of data
int WebSendLine(BIO *bio, unsigned char buf_write[], int strlenbuf) {
/*
BIO_write will attempt to write bytes to the socket. It returns the number of bytes actually written, or 0 or -1. As with BIO_read, 0 or -1 does not necessarily indicate an error. BIO_should_retry is the way to find out. If the write operation is to be retried, it must be with the exact same parameters as before.
*/
if( BIO_write(bio, buf_write, strlenbuf) <= 0 ) {
if( ! BIO_should_retry(bio) )
return -1;
}
return 0;
}
我或多或少是个新手,所以我可能还不明白它到底是如何工作的。我的问题列表我要做什么,这样我就不会得到"未知的命令"从服务器回来?
我期待着你的来信。
王认为,Greenality
服务器需要回车和换行。你应该发送"USER examplern"