C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-19-2005, 09:21 PM   #1
Registered User
 
Join Date: Oct 2005
Posts: 2
Question 100+ errors

I am kind of new to C++ but know some. I am using Dev C++ and am getting all sorts of errors from this code.

Can someone please tell me what I am doing wrong.

Code:
#include <cstdlib>
#include < winsock.h >

WORD version = MAKEWORD(1,1);
WSADATA wsaData;
SOCKET theSocket;
char Buf[256],myBuf[256]; // Buf -for server answer and myBuf -for your commands
int nRet; // For eventual errors

int conect(char *server) { //Connects to a server using "Winsock"

// Start up Winsock
nRet=WSAStartup(version, &wsaData);
if (nRet!=0) {return(0);}

// Store information about the server
LPHOSTENT lpHostEntry;

lpHostEntry = gethostbyname(server);
if (lpHostEntry == NULL) {
WSACleanup();
return(0);
}

// Create the socket
theSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
WSACleanup();
return(0);
}

SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(25); // Port 25

// Connect to the server
nRet = connect(theSocket,(LPSOCKADDR)&saServer,sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR) {
WSACleanup();
return(0);
}

nRet = recv(theSocket,Buf,sizeof(Buf),0);
if (nRet == SOCKET_ERROR) {
WSACleanup();
return(0);
}

if (Buf[0]=='4' || Buf[0]=='5') return(0); // Not a '220' Hello
if (Buf[0]=='2' && Buf[1]=='2' && Buf[2]=='0') {
sendmail(); // Ok to send mails
}

//Close the connection
closesocket(theSocket);


// Shutdown Winsock
WSACleanup();
}

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    char from [100], mailto [100], msg [500];
    cout << "What is your e-mail address?";
    cin >> from;
    cout << endl << "Who do you want to send to?";
    cin >> mailto;
    cout << "Sending From: " << from << endl << "Sending To: " << mailto << endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}
void sendmail() { //Sends an e-mail with MIME encoding
int err=0;
char ch[1];


// "HELO" the server
strcpy(myBuf, "HELO <");> strcat(myBuf,helo);
strcat(myBuf,">\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
recv(theSocket,Buf,sizeof(Buf),0);


// MAIL FROM...
if (Buf[0]=='2' && Buf[1]=='5' && Buf[2]=='0') {
strcpy(myBuf, "MAIL FROM:<");> strcat(myBuf,from);
strcat(myBuf,">\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
recv(theSocket,Buf,sizeof(Buf),0);
}

if (Buf[0]=='4' || Buf[0]=='5') err=1;
if (Buf[0]=='2' && Buf[1]=='5' && Buf[2]=='0' && err==0) {


// MAIL TO...
strcpy(myBuf, "RCPT TO:<");> strcat(myBuf, mailto);
strcat(myBuf, ">\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
recv(theSocket,Buf,sizeof(Buf),0);
}

if (Buf[0]=='4' || Buf[0]=='5') err=1;
if (Buf[0]=='2' && Buf[1]=='5' && err==0) {
strcpy(myBuf, "DATA\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
 recv(theSocket,Buf,sizeof(Buf),0);
}

if (Buf[0]=='4' || Buf[0]=='5') err=1;


// MIME encoded message
if (Buf[0]=='3' && Buf[1]=='5' && Buf[2]=='4' && err==0) {
strcpy(myBuf, "From: <");> strcat(myBuf, email); // Can change "email" to anything
strcat(myBuf, ">\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "Subject: Hello\x0d\x0a"); // Your subject goes here
send(theSocket,myBuf,strlen(myBuf),0);


// MIME stuff
strcpy(myBuf, "MIME-Version: 1.0\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "Content-Type: multipart/mixed;\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, " boundary = \"bla\"\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "X-Priority: 3\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "X -MSMail - Priority: Normal\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "X-Mailer: mailer@localhost\x0d\x0a\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "This is a multi-part message in MIME format.\x0d\x0a\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "--bla\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "Content-Type: text/plain; charset:us-ascii\x0d\x0a\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);


// This is the message (change it as you whish)
strcpy(myBuf, msg << "\x0d\x0a\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "--bla\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "Content-Type: application/x-msdownload;\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);


}
f.close();
strcpy(myBuf, "\x0d\x0a--bla--\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
strcpy(myBuf, "\x0d\x0a.\x0d\x0a"); // End transmission ;)
send(theSocket,myBuf,strlen(myBuf),0);
recv(theSocket,Buf,sizeof(Buf),0);
}
if (Buf[0]=='4' || Buf[0]=='5') err=1;



// QUIT (bye bye)
strcpy(myBuf, "QUIT\x0d\x0a");
send(theSocket,myBuf,strlen(myBuf),0);
}
Ryu++ is offline   Reply With Quote
Old 10-19-2005, 09:39 PM   #2
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
Well you said you are getting over 100 errors. Try posting the first few. Generally when you have that many errors you either are making the same mistake over and over or you have an error that cascades into other compile time errors. But thats all a guess since you haven't given us anything to start from
Thantos is offline   Reply With Quote
Old 10-19-2005, 09:50 PM   #3
Just Lurking
 
Dave_Sinkula's Avatar
 
Join Date: Oct 2002
Posts: 5,006
Quote:
Code:
#include <cstdlib>
#include < winsock.h >

WORD version = MAKEWORD(1,1);
Put code in functions.
__________________
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Dave_Sinkula is offline   Reply With Quote
Old 10-20-2005, 12:56 AM   #4
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,699
You know, you can press "compile" long before the program is complete. That way you can more easily spot when you start to do something wrong, rather than relying on people on message boards to fix a whole big mess.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 10-20-2005, 05:45 AM   #5
Linux Forever
 
Join Date: Oct 2002
Posts: 373
Also check your spelling. I noticed a "conect" command, later used as "connect". I can't really do socket prorgamming myself, but I can still spot a typo in it. I'm assuming that most of your errors would come from small typos like that. C++ is kinda picky....
__________________
This war, like the next war, is a war to end war.
Blizzarddog is offline   Reply With Quote
Old 10-20-2005, 08:53 AM   #6
Registered User
 
Join Date: Dec 2004
Location: UK
Posts: 109
As far as I can tell you never connect from main.
Also sendmail needs to be declared before connect otherwise the compiler will give you an error.
sigfriedmcwild is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ten Errors AverageSoftware Contests Board 0 07-20-2007 10:50 AM
Header File Errors... Junior89 C++ Programming 5 07-08-2007 12:28 AM
getting massive compile errors, need help jlmac2001 C++ Programming 3 03-20-2003 04:05 PM
executing errors s0ul2squeeze C++ Programming 3 03-26-2002 01:43 PM


All times are GMT -6. The time now is 03:25 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22