[CODE] [Maybe NEWBIE] Another Tiny Socket Problem

From: Jourge Fuzz Bush (modem-burn@GEOCITIES.COM)
Date: 11/04/98


Well, all the help I got before helped significantly. I got the point
where I send the data to the mail server. But I have one problem....
Say I connected propery and got the right socket calls. Then I do the
following:

send(sockfd, string6, strlen(string6), 0);

string6 can be anything of any length, (just try and keep it under 1 k)
So, this will work fine. But if we try and repeat this command again. It
will send the first and not the second. No matter what string, length or
flags u have it won't send any commands after the first one. Am I
missing something. If it is helpful the actuall code from the source I
am using is at the bottom of the message.

Thanks,
- Matt

CODE:

ACMD(do_imail)
{
int sockfd, temp1;
struct sockaddr_in dest_addr;
char *hostname = "localhost";
int port = 25;
struct hostent *he;
char *string1, *string2, *string3, *string4, *string5, *string6;

string1 = "helo triplethreat.dyn.ml.org\r\n";
string2 = "mail from:circle@triplethreat.dyn.ml.org\r\n";
string3 = "rcpt to:modem-burn@geocities.com\r\n";
string4 = "data\r\n";
string5 = "hi hi testing hi\r\n";
string6 = ".\r\n";

        one_argument(argument, arg);
        if (!*arg)
        {
                send_to_char("Who would you like to E-Mail?\r\n", ch);
                return;
        }

        if ((he=gethostbyname(hostname)) == NULL) {
                send_to_char("Host Name error. Does not exist.\r\n", ch);
                return;
        }

        if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
        {
                send_to_char("Sorry, the socket was not avalible, perhaps another
person is just in the process of mailing.\r\n", ch);
                return;
        }

        dest_addr.sin_family = PF_INET;
        dest_addr.sin_port = htons(port);
        dest_addr.sin_addr = *((struct in_addr *)he->h_addr);
        memset((unsigned char *)&dest_addr.sin_zero, 0, sizeof(unsigned char
*));

        /*connect socket to remote host*/
        if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct
sockaddr_in)) == -1)
        {
                sprintf(buf, "Connection error. Report exact error to admin and the
followind number: %d/r/r", WSAGetLastError());
                send_to_char(buf, ch);
                return;
        }

/*I have added error checking in all of these and none of them return
-1. And all say they sent all their data*/

        temp1 = send(sockfd, string1, strlen(string1), 0);
        sprintf(buf, "The size of string was %d of %d.\r\n", strlen(string1),
temp1);
        send_to_char(buf, ch);
        temp1 = send(sockfd, string2, strlen(string2), 0);
        sprintf(buf, "The size of string was %d of %d.\r\n", strlen(string2),
temp1);
        send_to_char(buf, ch);
        temp1 = send(sockfd, string3, strlen(string3), 0);
        sprintf(buf, "The size of string was %d of %d.\r\n", strlen(string3),
temp1);
        send_to_char(buf, ch);
        temp1 = send(sockfd, string4, strlen(string4), 0);
        sprintf(buf, "The size of string was %d of %d.\r\n", strlen(string4),
temp1);
        send_to_char(buf, ch);
        temp1 = send(sockfd, string5, strlen(string5), 0);
        sprintf(buf, "The size of string was %d of %d.\r\n", strlen(string5),
temp1);
        send_to_char(buf, ch);
        temp1 = send(sockfd, string6, strlen(string6), 0);
        sprintf(buf, "The size of string was %d of %d.\r\n", strlen(string6),
temp1);
        send_to_char(buf, ch);
        close(sockfd);
        send_to_char("As you wish!\r\n", ch);
        return;
}


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST