AIX calling WINSOCK during e-mail - normal?


 
Thread Tools Search this Thread
Top Forums Programming AIX calling WINSOCK during e-mail - normal?
# 15  
Old 01-20-2011
If you're using memcpy but not including string.h, that is easily capable of causing a segmentation fault on some platforms.

Turns out there is a strings.h though, it defines bcopy.
This User Gave Thanks to Corona688 For This Post:
# 16  
Old 01-21-2011
I didn't recompile everything I should have - going to have to try again tomorrow. It will take another hour or so to shutdown the servers, recompile, and reboot them. I'll keep you updated though. Thanks again for the help!

---------- Post updated 01-21-11 at 11:51 AM ---------- Previous update was 01-20-11 at 06:54 PM ----------

So unfortunately, I'm still getting a -1 returned from connect(). Here's my full code:

Code:
int
connection::get_connected (char * hostname, char * service)
{
   struct hostent *    hostentry; /* from gethostbyname */
   struct servent *    serventry; /* from getservbyname */
   unsigned long ip_address;
   struct sockaddr_in    sa_in;
   int    our_port;
   struct linger NoLinger;
   int    retval, err_code;
   unsigned long    ioctl_blocking = 1;
   char    message[512];

   // if the ctor couldn't get a buffer
   if (!in_buffer || !out_buffer)
      return (ERR_CANT_MALLOC);

   // --------------------------------------------------
   // 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);
   }

   // --------------------------------------------------
   // resolve the hostname/ipaddress
   //
   // Assume only hostname
   //  if ((ip_address = inet_addr (hostname)) != INADDR_NONE) {
   //    sa_in.sin_addr.s_addr = ip_address;
   // }
   //  else {
   if ((hostentry = gethostbyname(hostname)) == NULL)
   {
      return (ERR_CANT_RESOLVE_HOSTNAME);
   }
   sa_in.sin_addr.s_addr = *(long *)hostentry->h_addr;
   // }


   // --------------------------------------------------
   // get a socket
   //

   if ((the_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
   {
      return (ERR_CANT_GET_SOCKET);
   }

   sa_in.sin_family = AF_INET;
   sa_in.sin_port = our_port;

   // set socket options.  DONTLINGER will give us a more graceful disconnect

   NoLinger.l_onoff = 0;
   setsockopt(the_socket,
              SOL_SOCKET,
              SO_LINGER,
              (char *) &NoLinger, sizeof(NoLinger));

   // get a connection

   memset(&sa_in, 0, sizeof(sa_in));
   memcpy(&sa_in.sin_addr.s_addr, hostentry->h_addr, hostentry->h_length);
   sa_in.sin_port=htons(our_port);
   retval = connect (the_socket, (struct sockaddr *) & sa_in,
                     sizeof(sa_in));

   if (retval == SOCKET_ERROR)
   {
      return (ERR_CANT_CONNECT);
   }


#ifdef HA
   // Make this a non-blocking socket
   fcntl (the_socket, F_SETFL, O_NDELAY);
   // make the FD_SET and timeout structures for later operations...
#endif

   FD_ZERO (&fds);
   FD_SET (the_socket, &fds);

   // normal timeout, can be changed by the wait option.
   timeout.tv_sec = 0;
   timeout.tv_usec = 0;

   return (0);
}

I'm lost at this point.

---------- Post updated at 12:03 PM ---------- Previous update was at 12:02 PM ----------

I should mention also that when I try to do 'print hostentry->h_addr' it says that's not a valid member... but it compiles fine with gmake. So I'm not sure.
# 17  
Old 01-21-2011
I am also mystified. We've given you several methods of getting the actual error but you haven't used them. Until you do, your guess is as good as mine.
# 18  
Old 01-21-2011
Oh shucks, it must have gotten lost somewhere along the way. When it print errno, I get 78. Or are you referring to something else?

---------- Post updated at 03:57 PM ---------- Previous update was at 03:19 PM ----------

Now I'm getting this errno for some reason:
ENOTEMPTY

Last edited by ctote; 01-21-2011 at 05:06 PM..
# 19  
Old 01-21-2011
that means 'directory not empty'. It's likely totally unrelated to the bit of code you're playing with. If you put a perror() too late, errno could have been trashed by any other system call that happened along the way.

The code 78 you get makes a lot more sense: 'connection timed out' on AIX 4.3 and 5.1. It's also what perror() would be printing for you.

So the next obvious thing would be trying to connect to the server and port you're giving it by hand, with telnet or something. Maybe it really is not letting you connect on that port.

Can you post your code again? I have no idea what it looks like now.
This User Gave Thanks to Corona688 For This Post:
# 20  
Old 01-24-2011
Here is my updated code - it looks to be working:

Code:
int
connection::get_connected (char * hostname, char * service)
{

    int sockfd, portno, n;
    struct sockaddr_in serv_addr;
    struct hostent *server;

    char buffer[256];

    sockfd = socket(AF_INET, SOCK_STREAM, 0);

    if (sockfd < 0) 
        error("ERROR opening socket");

    server = gethostbyname(hostname);
    portno = 25;

    if (server == NULL) 
    {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }

    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;

    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(portno);

    if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
        error("ERROR connecting");

#ifdef HA
    // Make this a non-blocking socket
    fcntl (sockfd, F_SETFL, O_NDELAY);
    // make the FD_SET and timeout structures for later operations...
#endif

    FD_ZERO (&fds);
    FD_SET (sockfd, &fds);

    // normal timeout, can be changed by the wait option.
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;

    return 0;

I'm not sure what this section is doing though. Could you explain it to me if you get time?

Code:
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;

    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(portno);

Now I'm getting segfaults, but I haven't narrowed down why - I'm not sure it's completely related to this code change. Thanks for all of your help
# 21  
Old 01-24-2011
Quote:
Originally Posted by ctote
Here is my updated code - it looks to be working:
Quote:
Now I'm getting segfaults
And now you learn the crucial difference between "compiles" and "does what I thought it did"..

Did you do #include <string.h>, for starters?

Taking a closer look at the code now...
This User Gave Thanks to Corona688 For This Post:
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