AIX calling WINSOCK during e-mail - normal?


 
Thread Tools Search this Thread
Top Forums Programming AIX calling WINSOCK during e-mail - normal?
# 29  
Old 01-24-2011
constructor:
Code:
connection::connection (void)
{
   the_socket = 0;
   in_index = 0;
   out_index = 0;
   in_buffer_total = 0;
   out_buffer_total = 0;
   in_buffer = 0;

   in_buffer = new char[SOCKET_BUFFER_SIZE];
   out_buffer = new char[SOCKET_BUFFER_SIZE];

   last_winsock_error = 0;
}


When compiling, I get this on a batch job that uses that lib:

ld: 0711-224 WARNING: Duplicate symbol: std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::_Copy(unsigned long)


Not sure if that's related at all.
# 30  
Old 01-24-2011
ok, good. I don't think that warning's related.

But, you definitely need to set the_socket=sockfd before you return. The class won't happen to just know what socket you opened -- you have to tell it Smilie

What does the second parameter of get_connected do, or should do? Currently it's being ignored.
This User Gave Thanks to Corona688 For This Post:
# 31  
Old 01-24-2011
It was being used here:
Code:
// --------------------------------------------------
   // resolve the service name
   //

   // If they've specified a number, just use it.
   if (gensock_is_a_number (service))
   {
      char * tail;
      our_port = (int) strtol (service, &tail, 10);
      if (tail == service)
      {
         return (ERR_CANT_RESOLVE_SERVICE);
      }
      else
      {
         our_port = htons (our_port);
      }
   }
   else
   {
      // we have a name, we must resolve it.
      serventry = getservbyname (service, "tcp");

      if (serventry)
         our_port = serventry->s_port;
      else
         return (ERR_CANT_RESOLVE_SERVICE);
   }

But I took it out and just replaced it with portno=25; because &tail wasn't declared anywhere (if I remember correctly). Since this will always be used for e-mail, I figured it was safe to assume a hard coded port of 25.


btw, thank you for helping with this. I'd be lost completely.

---------- Post updated at 11:45 AM ---------- Previous update was at 11:32 AM ----------

Oh, also - I've renamed all occurrences of the_socket to sockfd (including the class definition). Should I take out the declaration of sockfd at the beginning of get_connected() ?
# 32  
Old 01-24-2011
Okay, so the second parameter is the port number, or service name, in the form of a character string.

Not all mail servers have the same port, I'm not sure it's safe to ignore it. Never understand why people still mess with strtol for short ints when they've got scanf. This code should do the job:

Code:
    if(service == NULL)
        return(ERR_CANT_RESOLVE_SERVICE);

    // We read it in as local order!
    if(sscanf(service, "%d", &portno) == 1);
    else if(s = getservbyname(service, "tcp"))
      portno=htons(s->s_port); // Convert from network to LOCAL order!
    else
      return(ERR_CANT_RESOLVE_SERVICE);

You need a 'struct servent *s;' up in the group of variables at the top. You'll need <stdio.h>, which I give good odds that you've included already. And you'll need to stop manually setting it to 25 of course. The htons() is needed since s->s_port is already swapped for you, and you do swapping below too, we just want it as a normal int here...

I tested it on service strings like "telnet", and arbitrary ports like "8888".

---------- Post updated at 11:41 AM ---------- Previous update was at 11:00 AM ----------

Quote:
Originally Posted by ctote
Oh, also - I've renamed all occurrences of the_socket to sockfd (including the class definition). Should I take out the declaration of sockfd at the beginning of get_connected() ?
Gack... I wouldn't have reccomended doing that. Before, the_socket would never have been changed. With the one change I suggested, it would never have been changed unless you knew for a fact that sockfd was valid. Now, it will never change because the local variable's the same name. Get rid of the local definition and it'll change all the time, potentially getting left at invalid values somewhere inbetween.

Just the one line the_socket=sockfd; right at the bottom of the connection function would have done without altering all your connection code.
This User Gave Thanks to Corona688 For This Post:
# 33  
Old 01-24-2011
Ok no problem - I can fix that back. Thanks

---------- Post updated at 03:46 PM ---------- Previous update was at 12:42 PM ----------

Ok great. I'm getting a socket connection now!

Now the problem is still this segfault. I return out of my methods to this point:
Code:
int prepare_smtp_message(char * MailAddress, char * destination)
{
   char out_data[MAXOUTLINE];
   char str[1024];
   char *ptr;
   int len, startLen;

   if ( open_smtp_socket() )   // <- this is where it goes into get_connected()
      return -1;

   if ( get_smtp_line() != 220 )  // <- segfault
   {
      smtp_error ("SMTP server error");
      return ( -1);
   }

And at get_smtp_line() != 220, I get a segfault. I'm just posting on the off chance you've seen this code before.
# 34  
Old 01-24-2011
It'd be nice to see the code of get_smtp_line, then.

I'm not sure you need an IBM engineer as much as a C/C++ coder...
# 35  
Old 01-24-2011
Oh yea, duh. I wasn't sure if it was even making into the function or not. When I try to step in, it blows up.

Code:
int get_smtp_line( void )
{
   char ch = '.';
   char in_data [MAXOUTLINE];
   char * index;
   int retval = 0;

   index = in_data;

   while (ch != '\n')
   {
      if ( (retval = gensock_getchar (SMTPSock, 0, &ch) ) )
      {
         gensock_error ("gensock_getchar", retval);
         return -1;
      }
      else
      {
         *index = ch;
         index++;
      }
   }


   return atoi(in_data);
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Unable to set ACLs on sulog - need to grant read permission to a normal user on AIX 6.1

Hi, I need to grant read permission to a normal user on sulog file on AIX 6.1. As root I did acledit sulog and aclget shows "extended permissions" as "enabled" and normal user "splunk" has read permissions. When I try to access sulog as splunk user it won't allow and aclget for splunk user... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

Send mail from AIX 7.1

Hi, My OS version is AIX 7.1. I am trying to send an email with a file to my mail address. sendmail or uuencode does not work. Can someone give me the correct format ? I use: uuencode <file name> | mail -s "subject" emailaddress Thanks Use code tags, thanks. (3 Replies)
Discussion started by: Nagesh_1985
3 Replies

4. Shell Programming and Scripting

AIX mail notification

plzzz help me, I want to send emails for exchange group members when the used file-system % gets more than 90%, this notification must include df -g, netstat -i,and errpt with the hostname thx in advance (0 Replies)
Discussion started by: majd_ece
0 Replies

5. Shell Programming and Scripting

Calling SQL script from ksh job and send mail on some error.

Hi, I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are: 1) How to call a sql script from ksh job with parameters? 2) How to use the parameter in sql file to... (1 Reply)
Discussion started by: anil029
1 Replies

6. UNIX for Advanced & Expert Users

Oracle (11gr2) calling unix commands (aix)

I have an Oracle database running on AIX, and I have a procedure that is calling OS commands from an oracle (and it's not working anymore)... so, there was an Java stored proc in Oracle CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED COMMON."Host" as import java.io.*; public class Host {... (1 Reply)
Discussion started by: bongo
1 Replies

7. UNIX for Dummies Questions & Answers

Forwarding Mail in AIX 5.3

Hello everyone, I am trying to create a forwarding scenario, and I do not seem to get it right! I created a .forward file in the directory where my personal mailbox resides. In the file is the full address to deliver email to ... yet the emails do not seem to get forwarded. Is there something... (3 Replies)
Discussion started by: gio001
3 Replies

8. AIX

Normal User Unable to Login Through AIX CDE

When we as normal user try to login, the session startup terminates and we are presented with the login screen.The root user is able to login without any problem.I can log in to the Aix server as normal user through telnet & using xmanager but not directly through server terminal .The Aix version... (1 Reply)
Discussion started by: ranadeep
1 Replies

9. AIX

To find RAM Size in AIX as normal user?

Hi, Am jus trying to find the Total RAM Size of a AIX m/c (in MB)..svmon works perfectly for a superuser...But i want to achive this as a normal user...Please help me out with correct command.. Best Regards, Muthukumaran.M (3 Replies)
Discussion started by: muthukumaran13
3 Replies

10. AIX

Calling All Aix Experts

I am new to the world of AIX. I want to get certified in AIX and learn it but fast. with in 3 months Could you give me some advise of a good site that with teach you or a bootcamp that is reasonable. I am really in need I am in atlanta (0 Replies)
Discussion started by: Courtney3216
0 Replies
Login or Register to Ask a Question