Socket Connection Problem

Socket Connection Problem

Post by R. Michael Gillmor » Wed, 16 Oct 1996 04:00:00



Hello all ...

I have recently upgraded my RS/6000 from AIX 3.2 to AIX 4.1.  The
installation was relatively
painless considering the hardware upgrade that we rolled in at the same
time.  We now have
a bigger problem, though.  We have written code that communicates to a
Tandem machine and
to a SunOS machine using Berkeley sockets.  If we run the code which was
compiled and linked
on the 3.2 machine (we kept one around just in case), it runs just
fine.  Communications
are flawless.  The problem comes when we try to run the code which was
compiled on the 4.1
OS version.  We either get "ECONNREFUSED" or "EACCESS" errors on the
communications ports.

The code itself is relatively simple.   Take a look:

===============  Code Begins Here ===============

typedef struct
{
        IP_Address_t    d_IP_Address;
        int                             d_socketID;
        int                             d_portNumber;
        direction_t             d_whichDirection;
        boolean_t               d_isConnected;

} realSocket_t;

int
establishConnection( socket_t definedSocket )
{
        /*
         *      This function establishes a TCP/IP connection with depending upon
the
         *      direction.  If it is incoming, we wait for the connection.  If it is
         *      outgoing, we request a connection from the other end
         */

        realSocket_t *                          socketPtr = ( realSocket_t * )definedSocket;
        static struct sockaddr_in       serverAddress;
        static struct sockaddr          remoteAddress;
        int                                                     err_ret;
        static int                                      remoteLength;

        /*
         *      Initialize the server address structure.
         */

        memset( &serverAddress, 0, sizeof( serverAddress ) );

        /*
         *      Open a socket.  This call is to the OS library
         */

        socketPtr->d_socketID = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
        if ( socketPtr->d_socketID < 0 )
        {
                /*
                 *      This is an error condition.  We need to determine
                 *      what we should do here
                 */

                l2k_log( 9, "error from socket(), error code == '%d'", errno );
                disconnect( definedSocket );
        }
        else
        {
                if ( socketPtr->d_whichDirection == INCOMING )
                {
                        /*
                         *      Since we are incoming, we want to accept any connection on the
                         *      designated port
                         */

                        serverAddress.sin_family = AF_INET;
                        serverAddress.sin_addr.s_addr = htonl( INADDR_ANY );
                        serverAddress.sin_port = htons( socketPtr->d_portNumber );

                        /*
                         *      Associate our port number and IP address
                         */

                        err_ret = bind( socketPtr->d_socketID,
                                ( struct sockaddr * )&serverAddress, sizeof( serverAddress ) );
                        if ( err_ret < 0 )
                        {
                                /*
                                 *      We can't even associate our port number and address.
                                 *      There are some serious problems here!  Disconnect
                                 *      and we have done all that can be done
                                 */

                                l2k_log( 0, "Unable to bind to address, error reported is %d",
                                        errno );
                                disconnect( definedSocket );
                        }
                        else
                        {
                                /*
                                 *      We will wait forever for a connection.  Incoming sockets
                                 *      simply means that we are waiting for the phone to ring
                                 */

                                err_ret = listen( socketPtr->d_socketID, NUMBER_CONNECTIONS );
                                if ( err_ret < 0 )
                                {
                                        /*
                                         *      There was some sort of error ... Close the socket
                                         */

                                        disconnect( definedSocket );
                                        l2k_log( 0, "listen returned an error of %d", errno );
                                }
                                else
                                {
                                        /*
                                         *      The phone has rung, and it is a "collect call".  We
                                         *      need to see who is calling
                                         */

                                        err_ret = accept( socketPtr->d_socketID,
                                                &remoteAddress, &remoteLength );
                                        if ( err_ret < 0 )
                                        {
                                                /*
                                                 *      The calling party did not identify himself, so
                                                 *      an error was reported.  Close the socket
                                                 */

                                                disconnect( definedSocket );
                                                l2k_log( 0, "accept returned an error of %d", errno );
                                        }
                                        else
                                        {
                                                /*
                                                 *      Everything was OK!  Indicate that the connection
                                                 *      has been established
                                                 */

                                                socketPtr->d_socketID = err_ret;
                                                socketPtr->d_isConnected = TRUE;
                                        }
                                }       /*      listen was successful */
                        }       /*      bind successful */
                }       /*      INCOMING socket */
                else
                {
                        /*
                         *      To prevent us from waiting forever while attempting to establish
                         *      a connection with a remote server, we will set an alarm.
                         */

                        setupAlarm();

                        /*
                         *      Indicate with which server we are to communicate, and
                         *      on which port
                         */

                        serverAddress.sin_family = AF_INET;
                        serverAddress.sin_addr.s_addr = inet_addr( socketPtr->d_IP_Address );        
                        serverAddress.sin_port = htons( socketPtr->d_portNumber );

                        /*
                         *      Connect the socket to the server.
                         */

                        err_ret = connect( socketPtr->d_socketID,
                                ( struct sockaddr * )&serverAddress, sizeof( serverAddress ) );
                        if ( err_ret < 0 )
                        {
                                l2k_log( 0, "Connection attempt failed (%d, %d)", err_ret, errno );
                                alarm( 0 );

                                /*
                                 *      We could not establish a connection with the
                                 *      remote system.  There is a problem, so close the
                                 *      socket, and return to the caller with a socketID
                                 *      which is not valid
                                 */

                                disconnect( definedSocket );
                        }       /*      Socket connection failed */
                }       /*      OUTGOING socket */
        }       /*      socket ID received */

        return ( socketPtr->d_socketID );

}       /*      establishConnection() */

===============  Commentary Continues Here ===============

This shouldn't be this hard (at least I wouldn't think so.  Can anyone
help?

Thanks for your support!

--

R. Michael "Okie" Gillmore
Highway Transportation Electronics
OBC Office Software
Mail Stop 105-170
Phone: (319)295-5932
Banyan -- R M Gillmore@L...@CCA.CR
Internet -- rmgil...@cca.rockwell.com

 
 
 

Socket Connection Problem

Post by R. Michael Gillmor » Wed, 16 Oct 1996 04:00:00


R. Michael Gillmore wrote:

> Hello all ...

> I have recently upgraded my RS/6000 from AIX 3.2 to AIX 4.1.  The
> installation was relatively
> painless considering the hardware upgrade that we rolled in at the same
> time.  We now have
> a bigger problem, though.  We have written code that communicates to a
> Tandem machine and
> to a SunOS machine using Berkeley sockets.  If we run the code which was
> compiled and linked
> on the 3.2 machine (we kept one around just in case), it runs just
> fine.  Communications
> are flawless.  The problem comes when we try to run the code which was
> compiled on the 4.1
> OS version.  We either get "ECONNREFUSED" or "EACCESS" errors on the
> communications ports.

> The code itself is relatively simple.   Take a look:

> ===============  Code Begins Here ===============

> typedef struct
> {
>         IP_Address_t    d_IP_Address;
>         int                             d_socketID;
>         int                             d_portNumber;
>         direction_t             d_whichDirection;
>         boolean_t               d_isConnected;
> } realSocket_t;

> int
> establishConnection( socket_t definedSocket )
> {
>         /*
>          *      This function establishes a TCP/IP connection with depending upon
> the
>          *      direction.  If it is incoming, we wait for the connection.  If it is
>          *      outgoing, we request a connection from the other end
>          */

>         realSocket_t *                          socketPtr = ( realSocket_t * )definedSocket;
>         static struct sockaddr_in       serverAddress;
>         static struct sockaddr          remoteAddress;
>         int                                                     err_ret;
>         static int                                      remoteLength;

>         /*
>          *      Initialize the server address structure.
>          */

>         memset( &serverAddress, 0, sizeof( serverAddress ) );

>         /*
>          *      Open a socket.  This call is to the OS library
>          */

>         socketPtr->d_socketID = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
>         if ( socketPtr->d_socketID < 0 )
>         {
>                 /*
>                  *      This is an error condition.  We need to determine
>                  *      what we should do here
>                  */

>                 l2k_log( 9, "error from socket(), error code == '%d'", errno );
>                 disconnect( definedSocket );
>         }
>         else
>         {
>                 if ( socketPtr->d_whichDirection == INCOMING )
>                 {
>                         /*
>                          *      Since we are incoming, we want to accept any connection on the
>                          *      designated port
>                          */

>                         serverAddress.sin_family = AF_INET;
>                         serverAddress.sin_addr.s_addr = htonl( INADDR_ANY );
>                         serverAddress.sin_port = htons( socketPtr->d_portNumber );

>                         /*
>                          *      Associate our port number and IP address
>                          */

>                         err_ret = bind( socketPtr->d_socketID,
>                                 ( struct sockaddr * )&serverAddress, sizeof( serverAddress ) );
>                         if ( err_ret < 0 )
>                         {
>                                 /*
>                                  *      We can't even associate our port number and address.
>                                  *      There are some serious problems here!  Disconnect
>                                  *      and we have done all that can be done
>                                  */

>                                 l2k_log( 0, "Unable to bind to address, error reported is %d",
>                                         errno );
>                                 disconnect( definedSocket );
>                         }
>                         else
>                         {
>                                 /*
>                                  *      We will wait forever for a connection.  Incoming sockets
>                                  *      simply means that we are waiting for the phone to ring
>                                  */

>                                 err_ret = listen( socketPtr->d_socketID, NUMBER_CONNECTIONS );
>                                 if ( err_ret < 0 )
>                                 {
>                                         /*
>                                          *      There was some sort of error ... Close the socket
>                                          */

>                                         disconnect( definedSocket );
>                                         l2k_log( 0, "listen returned an error of %d", errno );
>                                 }
>                                 else
>                                 {
>                                         /*
>                                          *      The phone has rung, and it is a "collect call".  We
>                                          *      need to see who is calling
>                                          */

>                                         err_ret = accept( socketPtr->d_socketID,
>                                                 &remoteAddress, &remoteLength );
>                                         if ( err_ret < 0 )
>                                         {
>                                                 /*
>                                                  *      The calling party did not identify himself, so
>                                                  *      an error was reported.  Close the socket
>                                                  */

>                                                 disconnect( definedSocket );
>                                                 l2k_log( 0, "accept returned an error of %d", errno );
>                                         }
>                                         else
>                                         {
>                                                 /*
>                                                  *      Everything was OK!  Indicate that the connection
>                                                  *      has been established
>                                                  */

>                                                 socketPtr->d_socketID = err_ret;
>                                                 socketPtr->d_isConnected = TRUE;
>                                         }
>                                 }       /*      listen was successful */
>                         }       /*      bind successful */
>                 }       /*      INCOMING socket */
>                 else
>                 {
>                         /*
>                          *      To prevent us from waiting forever while attempting to establish
>                          *      a connection with a remote server, we will set an alarm.
>                          */

>                         setupAlarm();

>                         /*
>                          *      Indicate with which server we are to communicate, and
>                          *      on which port
>                          */

>                         serverAddress.sin_family = AF_INET;
>                         serverAddress.sin_addr.s_addr = inet_addr( socketPtr->d_IP_Address );
>                         serverAddress.sin_port = htons( socketPtr->d_portNumber );

>                         /*
>                          *      Connect the socket to the server.
>                          */

>                         err_ret = connect( socketPtr->d_socketID,
>                                 ( struct sockaddr * )&serverAddress, sizeof( serverAddress ) );
>                         if ( err_ret < 0 )
>                         {
>                                 l2k_log( 0, "Connection attempt failed (%d, %d)", err_ret, errno );
>                                 alarm( 0 );

>                                 /*
>                                  *      We could not establish a connection with the
>                                  *      remote system.  There is a problem, so close the
>                                  *      socket, and return to the caller with a socketID
>                                  *      which is not valid
>                                  */

>                                 disconnect( definedSocket );
>                         }       /*      Socket connection failed */
>                 }       /*      OUTGOING socket */
>         }       /*      socket ID received */

>         return ( socketPtr->d_socketID );
> }       /*      establishConnection() */

> ===============  Commentary Continues Here ===============

> This shouldn't be this hard (at least I wouldn't think so.  Can anyone
> help?

> Thanks for your support!

> --

> R. Michael "Okie" Gillmore
> Highway Transportation Electronics
> OBC Office Software
> Mail Stop 105-170
> Phone: (319)295-5932
> Banyan -- R M Gillmore@L...@CCA.CR
> Internet -- rmgil...@cca.rockwell.com

Oh, yes!!  I forgot to tell everyone that we are using the
COMPAT_43 and BSD=43 compilation switches already!

--

R. Michael "Okie" Gillmore
Highway Transportation Electronics
OBC Office Software
Mail Stop 105-170
Phone: (319)295-5932
Banyan -- R M Gillmore@L...@CCA.CR
Internet -- rmgil...@cca.rockwell.com

 
 
 

Socket Connection Problem

Post by Ed Rav » Sat, 19 Oct 1996 04:00:00



[way too much posting re-included]

Quote:

>Oh, yes!!  I forgot to tell everyone that we are using the
>COMPAT_43 and BSD=43 compilation switches already!

There's some weird stuff going on with AIX 4 (and some patches in
3.2.5) with sockets.  The best example is Lynx -- if you compile
Lynx versions 2.5 or later on AIX 3.2.5, with the command "make aix32",
the binary won't run on AIX 4 or a 3.2.5 system with a particular APAR
applied.

But if you recompile Lynx with "make aix4", it compiles fine (even though
you're compiling on an AIX 3.2.5 system), and the binary runs on both
AIX 3.2.5 and 4.1.

You might want to try dumping the BSD 4.3 compilation switches, since
that changes the socket structure used by the C libraries, and could
easily be a source of confusion between different operating system
revisions.  Or contact the Lynx development folks and ask them if they
figured out what was going on with the problem described above -- I'll
bet a dollar that it's related to your problem.

--
Ed Ravin        |If I were not a little mad and generally silly

                |I should show you in a moment how to grapple with the question
+1 212 678 5545 |And you'd really be astonished at the force of my suggestion.

 
 
 

1. Troubled with a socket connection problem... please help

Can I post here an issue we have with Redhat, posting a message here
is our last option to find a solution.

The problem:

We are creating a socket (dgram) as a server.

Then we want to connect on it with an other application as client.

When we connect we always get : connection refused (errno 111)

We do not face this problem when we do not use symbolic links to socket;

we do have it, when we use symbolic links (IQ_bus -> /tmp/1010101)

We are using RedHat 7.2 on an Intel PC.

We're very troubled with this issue and hope that one of you can help us

or point us to a solution or explanation.

Best Regards,

2. Loading linux from d:

3. Unix/win socket connection problem.

4. A Linux vs Solaris Question

5. socket connection problem

6. missing single- and double-quotes in text?

7. Socket Connection Problems

8. Solaris 7 x86 installs smoothly on Micro Center PowerSpec 4430

9. Socket connection problem.

10. Socket connection problem

11. Opening a socket connection while in a socket connection.

12. Weird: get a socket connection without a running socket server !

13. Why Multiple Socket Connections on one Connection....